Search in sources :

Example 1 with IllegalAccountStateException

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

the class UserStateUpdateOperationHandle method doProcess.

@Override
protected void doProcess(UserStateUpdateOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
    // 权限校验;
    SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
    securityPolicy.checkEndpointPermission(LedgerPermission.UPDATE_USER_STATE, MultiIDsPolicy.AT_LEAST_ONE);
    UserAccount user = transactionContext.getDataset().getUserAccountSet().getAccount(op.getUserAddress());
    if (null == user) {
        throw new UserDoesNotExistException(String.format("User doesn't exist! --[Address=%s]", op.getUserAddress()));
    }
    // REVOKE 状态不可再恢复
    if (user.getState() == AccountState.REVOKE) {
        throw new IllegalAccountStateException(String.format("Can not change user in REVOKE state! --[Address=%s]", op.getUserAddress()));
    }
    // 操作账本;
    ((UserAccountSetEditor) (transactionContext.getDataset().getUserAccountSet())).setState(op.getUserAddress(), op.getState());
}
Also used : UserAccountSetEditor(com.jd.blockchain.ledger.core.UserAccountSetEditor) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) IllegalAccountStateException(com.jd.blockchain.ledger.IllegalAccountStateException) UserDoesNotExistException(com.jd.blockchain.ledger.UserDoesNotExistException) UserAccount(com.jd.blockchain.ledger.core.UserAccount)

Example 2 with IllegalAccountStateException

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

the class ContractStateUpdateOperationHandle method doProcess.

@Override
protected void doProcess(ContractStateUpdateOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
    // 权限校验;
    SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
    securityPolicy.checkEndpointPermission(LedgerPermission.UPDATE_CONTRACT_STATE, MultiIDsPolicy.AT_LEAST_ONE);
    ContractAccount contract = transactionContext.getDataset().getContractAccountSet().getAccount(op.getContractAddress());
    if (null == contract) {
        throw new ContractDoesNotExistException(String.format("Contract doesn't exist! --[Address=%s]", op.getContractAddress()));
    }
    // REVOKE 状态不可再恢复
    if (contract.getState() == AccountState.REVOKE) {
        throw new IllegalAccountStateException(String.format("Can not change contract in REVOKE state! --[Address=%s]", op.getContractAddress()));
    }
    // 操作账本;
    ((ContractAccountSetEditor) (transactionContext.getDataset().getContractAccountSet())).setState(op.getContractAddress(), op.getState());
}
Also used : ContractAccount(com.jd.blockchain.ledger.core.ContractAccount) ContractAccountSetEditor(com.jd.blockchain.ledger.core.ContractAccountSetEditor) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) IllegalAccountStateException(com.jd.blockchain.ledger.IllegalAccountStateException) ContractDoesNotExistException(com.jd.blockchain.ledger.ContractDoesNotExistException)

Example 3 with IllegalAccountStateException

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

the class UserCAUpdateOperationHandle method doProcess.

@Override
protected void doProcess(UserCAUpdateOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
    // 权限校验;
    SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
    securityPolicy.checkEndpointPermission(LedgerPermission.UPDATE_USER_CA, MultiIDsPolicy.AT_LEAST_ONE);
    UserAccount user = transactionContext.getDataset().getUserAccountSet().getAccount(op.getUserAddress());
    if (null == user) {
        throw new UserDoesNotExistException(String.format("User doesn't exist! --[Address=%s]", op.getUserAddress()));
    }
    if (user.getState() == AccountState.REVOKE) {
        throw new IllegalAccountStateException(String.format("Can not change user in REVOKE state! --[Address=%s]", op.getUserAddress()));
    }
    // 证书校验
    X509Certificate cert = CertificateUtils.parseCertificate(op.getCertificate());
    CertificateUtils.checkCertificateRolesAny(cert, CertificateRole.PEER, CertificateRole.GW, CertificateRole.USER);
    CertificateUtils.checkValidity(cert);
    X509Certificate[] ledgerCAs = CertificateUtils.parseCertificates(transactionContext.getDataset().getAdminDataset().getAdminSettings().getMetadata().getLedgerCertificates());
    X509Certificate[] issuers = CertificateUtils.findIssuers(cert, ledgerCAs);
    Arrays.stream(issuers).forEach(issuer -> CertificateUtils.checkCACertificate(issuer));
    CertificateUtils.checkValidityAny(issuers);
    // 操作账本;
    ((UserAccountSetEditor) (transactionContext.getDataset().getUserAccountSet())).setCertificate(op.getUserAddress(), op.getCertificate());
}
Also used : UserAccountSetEditor(com.jd.blockchain.ledger.core.UserAccountSetEditor) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) IllegalAccountStateException(com.jd.blockchain.ledger.IllegalAccountStateException) UserDoesNotExistException(com.jd.blockchain.ledger.UserDoesNotExistException) UserAccount(com.jd.blockchain.ledger.core.UserAccount) X509Certificate(java.security.cert.X509Certificate)

Aggregations

IllegalAccountStateException (com.jd.blockchain.ledger.IllegalAccountStateException)3 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)3 UserDoesNotExistException (com.jd.blockchain.ledger.UserDoesNotExistException)2 UserAccount (com.jd.blockchain.ledger.core.UserAccount)2 UserAccountSetEditor (com.jd.blockchain.ledger.core.UserAccountSetEditor)2 ContractDoesNotExistException (com.jd.blockchain.ledger.ContractDoesNotExistException)1 ContractAccount (com.jd.blockchain.ledger.core.ContractAccount)1 ContractAccountSetEditor (com.jd.blockchain.ledger.core.ContractAccountSetEditor)1 X509Certificate (java.security.cert.X509Certificate)1