use of com.jd.blockchain.ledger.DataAccountDoesNotExistException in project jdchain-core by blockchain-jd-com.
the class DataAccountKVSetOperationHandle method doProcess.
@Override
protected void doProcess(DataAccountKVSetOperation kvWriteOp, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
// 权限校验;
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
securityPolicy.checkEndpointPermission(LedgerPermission.WRITE_DATA_ACCOUNT, MultiIDsPolicy.AT_LEAST_ONE);
// 操作账本;
DataAccount account = transactionContext.getDataset().getDataAccountSet().getAccount(kvWriteOp.getAccountAddress());
if (account == null) {
throw new DataAccountDoesNotExistException(String.format("Data account doesn't exist! --[Address=%s]", kvWriteOp.getAccountAddress()));
}
// 写权限校验
securityPolicy.checkDataPermission(account.getPermission(), DataPermissionType.WRITE);
KVWriteEntry[] writeSet = kvWriteOp.getWriteSet();
long v = -1L;
for (KVWriteEntry kvw : writeSet) {
v = account.getDataset().setValue(kvw.getKey(), TypedValue.wrap(kvw.getValue()), kvw.getExpectedVersion());
if (v < 0) {
throw new DataVersionConflictException();
}
}
}
use of com.jd.blockchain.ledger.DataAccountDoesNotExistException in project jdchain-core by blockchain-jd-com.
the class AccountPermissionOperationHandle method doProcess.
@Override
protected void doProcess(AccountPermissionSetOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
PermissionAccount account = null;
// 查找账户
switch(op.getAccountType()) {
case DATA:
account = transactionContext.getDataset().getDataAccountSet().getAccount(op.getAddress());
if (null == account) {
throw new DataAccountDoesNotExistException(String.format("Data account doesn't exist! --[Address=%s]", op.getAddress()));
}
break;
case EVENT:
account = transactionContext.getEventSet().getEventAccountSet().getAccount(op.getAddress());
if (null == account) {
throw new EventAccountDoesNotExistException(String.format("Event account doesn't exist! --[Address=%s]", op.getAddress()));
}
break;
case CONTRACT:
account = transactionContext.getDataset().getContractAccountSet().getAccount(op.getAddress());
if (null == account) {
throw new ContractDoesNotExistException(String.format("Contract doesn't exist! --[Address=%s]", op.getAddress()));
}
break;
}
if (!StringUtils.isEmpty(op.getRole()) && !transactionContext.getDataset().getAdminDataset().getAdminSettings().getRolePrivileges().contains(op.getRole())) {
throw new RoleDoesNotExistException(String.format("Role doesn't exist! --[Role=%s]", op.getRole()));
}
// 写权限校验
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
securityPolicy.checkDataOwners(account.getPermission(), MultiIDsPolicy.AT_LEAST_ONE);
// 更新权限信息
DataPermission originPermission = account.getPermission();
AccountModeBits modeBits = op.getMode() > -1 ? new AccountModeBits(op.getAccountType(), op.getMode()) : originPermission.getModeBits();
String rols = !StringUtils.isEmpty(op.getRole()) ? op.getRole().toUpperCase() : originPermission.getRole();
account.setPermission(new AccountDataPermission(modeBits, originPermission.getOwners(), rols));
}
Aggregations