Search in sources :

Example 1 with RolePrivileges

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

the class RolePrivilegeDataset method enablePermissions.

/**
 * 授权角色指定的权限; <br>
 * 如果角色不存在,则返回 -1;
 *
 * @param roleName
 * @param ledgerPermissions
 * @param txPermissions
 * @return
 */
public long enablePermissions(String roleName, LedgerPermission[] ledgerPermissions, TransactionPermission[] txPermissions) {
    RolePrivileges roleAuth = getRolePrivilege(roleName);
    if (roleAuth == null) {
        return -1;
    }
    roleAuth.getLedgerPrivilege().enable(ledgerPermissions);
    roleAuth.getTransactionPrivilege().enable(txPermissions);
    return setRolePrivilege(roleAuth);
}
Also used : RolePrivileges(com.jd.blockchain.ledger.RolePrivileges)

Example 2 with RolePrivileges

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

the class RolePrivilegeDataset method disablePermissions.

/**
 * 禁止角色指定的权限; <br>
 * 如果角色不存在,则返回 -1;
 *
 * @param roleName    角色;
 * @param permissions 权限列表;
 * @return
 */
public long disablePermissions(String roleName, LedgerPermission... permissions) {
    RolePrivileges roleAuth = getRolePrivilege(roleName);
    if (roleAuth == null) {
        return -1;
    }
    roleAuth.getLedgerPrivilege().disable(permissions);
    return setRolePrivilege(roleAuth);
}
Also used : RolePrivileges(com.jd.blockchain.ledger.RolePrivileges)

Example 3 with RolePrivileges

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

the class RolePrivilegeDataset method enablePermissions.

/**
 * 授权角色指定的权限; <br>
 * 如果角色不存在,则返回 -1;
 *
 * @param roleName    角色;
 * @param permissions 权限列表;
 * @return
 */
public long enablePermissions(String roleName, TransactionPermission... permissions) {
    RolePrivileges roleAuth = getRolePrivilege(roleName);
    if (roleAuth == null) {
        return -1;
    }
    roleAuth.getTransactionPrivilege().enable(permissions);
    return setRolePrivilege(roleAuth);
}
Also used : RolePrivileges(com.jd.blockchain.ledger.RolePrivileges)

Example 4 with RolePrivileges

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

the class RolePrivilegeDataset method disablePermissions.

/**
 * 禁用角色指定的权限; <br>
 * 如果角色不存在,则返回 -1;
 *
 * @param roleName
 * @param ledgerPermissions
 * @param txPermissions
 * @return
 */
public long disablePermissions(String roleName, LedgerPermission[] ledgerPermissions, TransactionPermission[] txPermissions) {
    RolePrivileges roleAuth = getRolePrivilege(roleName);
    if (roleAuth == null) {
        return -1;
    }
    roleAuth.getLedgerPrivilege().disable(ledgerPermissions);
    roleAuth.getTransactionPrivilege().disable(txPermissions);
    return setRolePrivilege(roleAuth);
}
Also used : RolePrivileges(com.jd.blockchain.ledger.RolePrivileges)

Example 5 with RolePrivileges

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

the class RolePrivilegeDataset method getRolePrivilege.

/**
 * 查询角色权限;
 *
 * <br>
 * 如果不存在,则返回 null;
 *
 * @param address
 * @return
 */
@Override
public RolePrivileges getRolePrivilege(String roleName) {
    // 只返回最新版本;
    Bytes key = encodeKey(roleName);
    DataEntry<Bytes, byte[]> kv = dataset.getDataEntry(key);
    if (kv == null) {
        return null;
    }
    PrivilegeSet privilege = BinaryProtocol.decode(kv.getValue());
    return new RolePrivileges(roleName, kv.getVersion(), privilege);
}
Also used : Bytes(utils.Bytes) RolePrivileges(com.jd.blockchain.ledger.RolePrivileges) PrivilegeSet(com.jd.blockchain.ledger.PrivilegeSet)

Aggregations

RolePrivileges (com.jd.blockchain.ledger.RolePrivileges)11 RolePrivilegeSettings (com.jd.blockchain.ledger.RolePrivilegeSettings)2 RolePrivilegeDataset (com.jd.blockchain.ledger.core.RolePrivilegeDataset)2 Bytes (utils.Bytes)2 HashDigest (com.jd.blockchain.crypto.HashDigest)1 LedgerException (com.jd.blockchain.ledger.LedgerException)1 PrivilegeSet (com.jd.blockchain.ledger.PrivilegeSet)1 RolePrivilegeEntry (com.jd.blockchain.ledger.RolesConfigureOperation.RolePrivilegeEntry)1 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)1 UserAuthorizationSettings (com.jd.blockchain.ledger.UserAuthorizationSettings)1 UserRoles (com.jd.blockchain.ledger.UserRoles)1 CryptoConfig (com.jd.blockchain.ledger.core.CryptoConfig)1 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)1 Test (org.junit.Test)1