Search in sources :

Example 1 with SecurityInitData

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

the class LedgerInitConfiguration method createSecurityInitSettings.

private static SecurityInitData createSecurityInitSettings(LedgerInitProperties ledgerInitProps) {
    // 设置角色;
    SecurityInitData securityInitData = new SecurityInitData();
    securityInitData.setRoles(ledgerInitProps.getRoles());
    // 如果没有默认角色,则创建“默认”角色;
    if (securityInitData.getRolesCount() == 0) {
        securityInitData.addRole(LedgerSecurityManager.DEFAULT_ROLE, LedgerPermission.values(), TransactionPermission.values());
    } else if (!securityInitData.containsRole(LedgerSecurityManager.DEFAULT_ROLE)) {
        // 如果定义了角色,则必须显式地定义“默认”角色;
        throw new LedgerInitException("Miss definition of role[DEFAULT]!");
    }
    // 设置授权;
    for (GenesisUser u : ledgerInitProps.getGenesisUsers()) {
        String[] roles = u.getRoles();
        for (String role : roles) {
            if (!securityInitData.containsRole(role)) {
                throw new LedgerInitException(String.format("The role[%s] authenticated to user[%s] is not defined!", role, AddressEncoding.generateAddress(u.getPubKey())));
            }
        }
        // 去掉对默认角色的授权;
        securityInitData.addUserAuthencation(AddressEncoding.generateAddress(u.getPubKey()), roles, u.getRolesPolicy());
    }
    return securityInitData;
}
Also used : SecurityInitData(com.jd.blockchain.ledger.SecurityInitData) LedgerInitException(com.jd.blockchain.ledger.LedgerInitException) GenesisUser(com.jd.blockchain.ledger.GenesisUser)

Example 2 with SecurityInitData

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

the class LedgerInitConfiguration method create.

public static LedgerInitConfiguration create(LedgerInitProperties ledgerInitProps) {
    LedgerInitConfiguration ledgerConfig = new LedgerInitConfiguration();
    CryptoConfig cryptoConfig = createCryptoConfig(ledgerInitProps.getCryptoProperties());
    ledgerConfig.cryptoConfig = cryptoConfig;
    ConsensusConfig consensusConfig = createConsensusConfig(ledgerInitProps);
    ledgerConfig.consensusConfig = consensusConfig;
    ParticipantProperties[] participants = resolveParticipants(ledgerInitProps);
    ledgerConfig.participants = participants;
    LedgerInitData ledgerSettings = createLedgerInitSettings(ledgerInitProps, cryptoConfig, consensusConfig, participants);
    ledgerSettings.setCreatedTime(ledgerInitProps.getCreatedTime());
    ledgerConfig.ledgerSettings = ledgerSettings;
    SecurityInitData securitySettings = createSecurityInitSettings(ledgerInitProps);
    ledgerConfig.securitySettings = securitySettings;
    return ledgerConfig;
}
Also used : SecurityInitData(com.jd.blockchain.ledger.SecurityInitData) ParticipantProperties(com.jd.blockchain.ledger.LedgerInitProperties.ParticipantProperties) LedgerInitData(com.jd.blockchain.transaction.LedgerInitData) CryptoConfig(com.jd.blockchain.ledger.core.CryptoConfig)

Aggregations

SecurityInitData (com.jd.blockchain.ledger.SecurityInitData)2 GenesisUser (com.jd.blockchain.ledger.GenesisUser)1 LedgerInitException (com.jd.blockchain.ledger.LedgerInitException)1 ParticipantProperties (com.jd.blockchain.ledger.LedgerInitProperties.ParticipantProperties)1 CryptoConfig (com.jd.blockchain.ledger.core.CryptoConfig)1 LedgerInitData (com.jd.blockchain.transaction.LedgerInitData)1