use of com.jd.blockchain.ledger.UserRoles in project jdchain-core by blockchain-jd-com.
the class UserRoleDatasetEditor method getUserRoles.
/**
* 查询角色授权;
*
* <br>
* 如果不存在,则返回 null;
*
* @param address
* @return
*/
@Override
public UserRoles getUserRoles(Bytes userAddress) {
// 只返回最新版本;
DataEntry<Bytes, byte[]> kv = dataset.getDataEntry(userAddress);
if (kv == null) {
return null;
}
RoleSet roleSet = BinaryProtocol.decode(kv.getValue());
return new UserRoles(userAddress, kv.getVersion(), roleSet);
}
use of com.jd.blockchain.ledger.UserRoles in project jdchain-core by blockchain-jd-com.
the class UserRoleDatasetEditor method getUserRoles.
@Override
public UserRoles[] getUserRoles() {
DataEntry<Bytes, byte[]>[] kvEntries = dataset.getDataEntries(0, (int) dataset.getDataCount());
UserRoles[] pns = new UserRoles[kvEntries.length];
RoleSet roleset;
for (int i = 0; i < pns.length; i++) {
roleset = BinaryProtocol.decode(kvEntries[i].getValue());
pns[i] = new UserRoles(kvEntries[i].getKey(), kvEntries[i].getVersion(), roleset);
}
return pns;
}
use of com.jd.blockchain.ledger.UserRoles in project jdchain-core by blockchain-jd-com.
the class UserRoleDatasetTest method testAddUserRoles.
@Test
public void testAddUserRoles() {
CryptoConfig cryptoConfig = new CryptoConfig();
cryptoConfig.setAutoVerifyHash(true);
cryptoConfig.setSupportedProviders(SUPPORTED_PROVIDERS);
cryptoConfig.setHashAlgorithm(HASH_ALGORITHM);
MemoryKVStorage testStorage = new MemoryKVStorage();
String prefix = "user-roles/";
UserRoleDatasetEditor userRolesDataset = new UserRoleDatasetEditor(cryptoConfig, prefix, testStorage, testStorage, LedgerDataStructure.MERKLE_TREE);
BlockchainKeypair bckp = BlockchainKeyGenerator.getInstance().generate();
String[] authRoles = { "DEFAULT", "MANAGER" };
userRolesDataset.addUserRoles(bckp.getAddress(), RolesPolicy.UNION, authRoles);
userRolesDataset.commit();
assertEquals(1, userRolesDataset.getUserCount());
UserRoles userRoles = userRolesDataset.getUserRoles(bckp.getAddress());
assertNotNull(userRoles);
String[] roles = userRoles.getRoles();
assertEquals(2, roles.length);
assertArrayEquals(authRoles, roles);
assertEquals(RolesPolicy.UNION, userRoles.getPolicy());
}
Aggregations