Search in sources :

Example 1 with RolePrivilegeEntry

use of com.jd.blockchain.ledger.RolesConfigureOperation.RolePrivilegeEntry in project jdchain-core by blockchain-jd-com.

the class RolesConfigureOperationHandle method doProcess.

@Override
protected void doProcess(RolesConfigureOperation operation, LedgerTransactionContext transactionContext, TransactionRequestExtension request, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
    // 权限校验;
    SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
    securityPolicy.checkEndpointPermission(LedgerPermission.CONFIGURE_ROLES, MultiIDsPolicy.AT_LEAST_ONE);
    // 操作账本;
    RolePrivilegeEntry[] rpcfgs = operation.getRoles();
    RolePrivilegeSettings rpSettings = transactionContext.getDataset().getAdminDataset().getAdminSettings().getRolePrivileges();
    if (rpcfgs != null) {
        for (RolePrivilegeEntry rpcfg : rpcfgs) {
            RolePrivileges rp = rpSettings.getRolePrivilege(rpcfg.getRoleName());
            if (rp == null) {
                ((RolePrivilegeDataset) rpSettings).addRolePrivilege(rpcfg.getRoleName(), rpcfg.getEnableLedgerPermissions(), rpcfg.getEnableTransactionPermissions());
            } else {
                rp.enable(rpcfg.getEnableLedgerPermissions());
                rp.enable(rpcfg.getEnableTransactionPermissions());
                rp.disable(rpcfg.getDisableLedgerPermissions());
                rp.disable(rpcfg.getDisableTransactionPermissions());
                ((RolePrivilegeDataset) rpSettings).updateRolePrivilege(rp);
            }
        }
    }
}
Also used : RolePrivilegeDataset(com.jd.blockchain.ledger.core.RolePrivilegeDataset) RolePrivileges(com.jd.blockchain.ledger.RolePrivileges) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) RolePrivilegeEntry(com.jd.blockchain.ledger.RolesConfigureOperation.RolePrivilegeEntry) RolePrivilegeSettings(com.jd.blockchain.ledger.RolePrivilegeSettings)

Aggregations

RolePrivilegeSettings (com.jd.blockchain.ledger.RolePrivilegeSettings)1 RolePrivileges (com.jd.blockchain.ledger.RolePrivileges)1 RolePrivilegeEntry (com.jd.blockchain.ledger.RolesConfigureOperation.RolePrivilegeEntry)1 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)1 RolePrivilegeDataset (com.jd.blockchain.ledger.core.RolePrivilegeDataset)1