Search in sources :

Example 1 with AuthorizationException

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

the class UserRoleDatasetEditor method addUserRoles.

/**
 * 加入新的用户角色授权; <br>
 *
 * 如果该用户的授权已经存在,则引发 {@link LedgerException} 异常;
 *
 * @param userAddress
 * @param rolesPolicy
 * @param roles
 */
public void addUserRoles(Bytes userAddress, RolesPolicy rolesPolicy, String... roles) {
    UserRoles roleAuth = new UserRoles(userAddress, -1, rolesPolicy);
    roleAuth.addRoles(roles);
    long nv = setUserRolesAuthorization(roleAuth);
    if (nv < 0) {
        throw new AuthorizationException("Roles authorization of User[" + userAddress + "] already exists!");
    }
    if (ledgerDataStructure.equals(LedgerDataStructure.KV)) {
        Bytes index = USEERROLR_SEQUENCE_KEY_PREFIX.concat(Bytes.fromString(String.valueOf(dataset.getDataCount() + userrole_index_in_block)));
        nv = dataset.setValue(index, userAddress.toBytes(), -1);
        if (nv < 0) {
            throw new AuthorizationException("Roles authorization seq of User[" + userAddress + "] already exists!");
        }
        userrole_index_in_block++;
    }
}
Also used : Bytes(utils.Bytes) AuthorizationException(com.jd.blockchain.ledger.AuthorizationException) UserRoles(com.jd.blockchain.ledger.UserRoles)

Example 2 with AuthorizationException

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

the class UserRoleDatasetEditor method addUserRoles.

/**
 * 加入新的用户角色授权; <br>
 *
 * 如果该用户的授权已经存在,则引发 {@link LedgerException} 异常;
 *
 * @param userAddress
 * @param rolesPolicy
 * @param roles
 */
public void addUserRoles(Bytes userAddress, RolesPolicy rolesPolicy, Collection<String> roles) {
    UserRoles roleAuth = new UserRoles(userAddress, -1, rolesPolicy);
    roleAuth.addRoles(roles);
    long nv = setUserRolesAuthorization(roleAuth);
    if (nv < 0) {
        throw new AuthorizationException("Roles authorization of User[" + userAddress + "] already exists!");
    }
    if (ledgerDataStructure.equals(LedgerDataStructure.KV)) {
        Bytes index = USEERROLR_SEQUENCE_KEY_PREFIX.concat(Bytes.fromString(String.valueOf(dataset.getDataCount() + userrole_index_in_block)));
        nv = dataset.setValue(index, userAddress.toBytes(), -1);
        if (nv < 0) {
            throw new AuthorizationException("Roles authorization seq of User[" + userAddress + "] already exists!");
        }
        userrole_index_in_block++;
    }
}
Also used : Bytes(utils.Bytes) AuthorizationException(com.jd.blockchain.ledger.AuthorizationException) UserRoles(com.jd.blockchain.ledger.UserRoles)

Aggregations

AuthorizationException (com.jd.blockchain.ledger.AuthorizationException)2 UserRoles (com.jd.blockchain.ledger.UserRoles)2 Bytes (utils.Bytes)2