/** * Check if access should be allowed. userID is not checked if null. This * method doesn't check if token password is correct. It should be used only * when token password has already been verified (e.g., in the RPC layer). * * Some places need to check the access using StorageTypes and for other * places the StorageTypes is not relevant. */ public void checkAccess(BlockTokenIdentifier id, String userId, ExtendedBlock block, BlockTokenIdentifier.AccessMode mode, StorageType[] storageTypes, String[] storageIds) throws InvalidToken { checkAccess(id, userId, block, mode); if (ArrayUtils.isNotEmpty(storageTypes)) { checkAccess(id.getStorageTypes(), storageTypes, "StorageTypes"); } if (ArrayUtils.isNotEmpty(storageIds)) { checkAccess(id.getStorageIds(), storageIds, "StorageIDs"); } }
@Override public String toString() { return "block_token_identifier (expiryDate=" + this.getExpiryDate() + ", keyId=" + this.getKeyId() + ", userId=" + this.getUserId() + ", blockPoolId=" + this.getBlockPoolId() + ", blockId=" + this.getBlockId() + ", access modes=" + this.getAccessModes() + ", storageTypes= " + Arrays.toString(this.getStorageTypes()) + ", storageIds= " + Arrays.toString(this.getStorageIds()) + ")"; }
public static BlockTokenSecretProto convert( BlockTokenIdentifier blockTokenSecret) { BlockTokenSecretProto.Builder builder = BlockTokenSecretProto.newBuilder(); builder.setExpiryDate(blockTokenSecret.getExpiryDate()); builder.setKeyId(blockTokenSecret.getKeyId()); String userId = blockTokenSecret.getUserId(); if (userId != null) { builder.setUserId(userId); } String blockPoolId = blockTokenSecret.getBlockPoolId(); if (blockPoolId != null) { builder.setBlockPoolId(blockPoolId); } builder.setBlockId(blockTokenSecret.getBlockId()); for (BlockTokenIdentifier.AccessMode aMode : blockTokenSecret.getAccessModes()) { builder.addModes(convert(aMode)); } for (StorageType storageType : blockTokenSecret.getStorageTypes()) { builder.addStorageTypes(convertStorageType(storageType)); } for (String storageId : blockTokenSecret.getStorageIds()) { builder.addStorageIds(storageId); } return builder.build(); }