Search in sources :

Example 16 with LedgerException

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

the class RolePrivilegeDataset method setRolePrivilege.

/**
 * 设置角色权限; <br>
 * 如果版本校验不匹配,则返回 -1;
 *
 * @param roleAuth
 * @return
 */
private long setRolePrivilege(RolePrivileges roleAuth) {
    if (roleAuth.getRoleName().length() > MAX_ROLE_NAME_LENGTH) {
        throw new LedgerException("Too long role name!");
    }
    Bytes key = encodeKey(roleAuth.getRoleName());
    byte[] privilegeBytes = BinaryProtocol.encode(roleAuth, PrivilegeSet.class);
    return dataset.setValue(key, privilegeBytes, roleAuth.getVersion());
}
Also used : Bytes(utils.Bytes) LedgerException(com.jd.blockchain.ledger.LedgerException)

Example 17 with LedgerException

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

the class RolePrivilegeDataset method addRolePrivilege.

/**
 * 加入新的角色权限; <br>
 *
 * 如果指定的角色已经存在,则引发 {@link LedgerException} 异常;
 *
 * @param roleName        角色名称;不能超过 {@link #MAX_ROLE_NAME_LENGTH} 个 Unicode 字符;
 * @param ledgerPrivilege
 * @param txPrivilege
 */
public long addRolePrivilege(String roleName, LedgerPrivilegeBitset ledgerPrivilege, TransactionPrivilegeBitset txPrivilege) {
    RolePrivileges roleAuth = new RolePrivileges(roleName, -1, ledgerPrivilege, txPrivilege);
    long nv = setRolePrivilege(roleAuth);
    if (nv < 0) {
        throw new LedgerException("Role[" + roleName + "] already exist!");
    }
    if (ledgerDataStructure.equals(LedgerDataStructure.KV)) {
        Bytes index = ROLEPRI_SEQUENCE_KEY_PREFIX.concat(Bytes.fromString(String.valueOf(dataset.getDataCount() + rolepri_index_in_block)));
        nv = dataset.setValue(index, Bytes.fromString(roleName).toBytes(), -1);
        if (nv < 0) {
            throw new LedgerException("Role[" + roleName + "] seq already exist!");
        }
        rolepri_index_in_block++;
    }
    return nv;
}
Also used : Bytes(utils.Bytes) RolePrivileges(com.jd.blockchain.ledger.RolePrivileges) LedgerException(com.jd.blockchain.ledger.LedgerException)

Aggregations

LedgerException (com.jd.blockchain.ledger.LedgerException)17 Bytes (utils.Bytes)10 HashMap (java.util.HashMap)3 CryptoAlgorithm (com.jd.blockchain.crypto.CryptoAlgorithm)2 CryptoProvider (com.jd.blockchain.crypto.CryptoProvider)2 PubKey (com.jd.blockchain.crypto.PubKey)2 HashDigest (com.jd.blockchain.crypto.HashDigest)1 ContractExecuteException (com.jd.blockchain.ledger.ContractExecuteException)1 Event (com.jd.blockchain.ledger.Event)1 RolePrivileges (com.jd.blockchain.ledger.RolePrivileges)1 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)1 TypedValue (com.jd.blockchain.ledger.TypedValue)1 LedgerAdminDataSet (com.jd.blockchain.ledger.core.LedgerAdminDataSet)1 LedgerAdminDataSetEditor (com.jd.blockchain.ledger.core.LedgerAdminDataSetEditor)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 PublicKey (java.security.PublicKey)1 X509Certificate (java.security.cert.X509Certificate)1