Search in sources :

Example 11 with UserAccount

use of com.jd.blockchain.ledger.core.UserAccount 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

UserAccount (com.jd.blockchain.ledger.core.UserAccount)11 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)9 HashDigest (com.jd.blockchain.crypto.HashDigest)8 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)6 TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)6 Test (org.junit.Test)6 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)5 LedgerDataSetEditor (com.jd.blockchain.ledger.core.LedgerDataSetEditor)5 LedgerManager (com.jd.blockchain.ledger.core.LedgerManager)5 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)5 LedgerTransactionContext (com.jd.blockchain.ledger.core.LedgerTransactionContext)5 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)5 TransactionResponse (com.jd.blockchain.ledger.TransactionResponse)4 DefaultOperationHandleRegisteration (com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration)4 LedgerDataSet (com.jd.blockchain.ledger.core.LedgerDataSet)4 LedgerSecurityManager (com.jd.blockchain.ledger.core.LedgerSecurityManager)4 OperationHandleRegisteration (com.jd.blockchain.ledger.core.OperationHandleRegisteration)4 TransactionBatchProcessor (com.jd.blockchain.ledger.core.TransactionBatchProcessor)4 IllegalAccountStateException (com.jd.blockchain.ledger.IllegalAccountStateException)2 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)2