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;
}
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;
}
Aggregations