public void checkAccess(BlockTokenIdentifier id, String userId, ExtendedBlock block, BlockTokenIdentifier.AccessMode mode) throws InvalidToken { if (LOG.isDebugEnabled()) { LOG.debug("Checking access for user=" + userId + ", block=" + block + ", access mode=" + mode + " using " + id); } if (userId != null && !userId.equals(id.getUserId())) { throw new InvalidToken("Block token with " + id + " doesn't belong to user " + userId); } if (!id.getBlockPoolId().equals(block.getBlockPoolId())) { throw new InvalidToken("Block token with " + id + " doesn't apply to block " + block); } if (id.getBlockId() != block.getBlockId()) { throw new InvalidToken("Block token with " + id + " doesn't apply to block " + block); } if (isExpired(id.getExpiryDate())) { throw new InvalidToken("Block token with " + id + " is expired."); } if (!id.getAccessModes().contains(mode)) { throw new InvalidToken("Block token with " + id + " doesn't have " + mode + " permission"); } }
@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()) + ")"; }
@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() + ")"; }
@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() + ")"; }
+ ", access mode=" + mode + " using " + id.toString()); if (userId != null && !userId.equals(id.getUserId())) { throw new InvalidToken("Block token with " + id.toString() + " doesn't belong to user " + userId);
+ ", access mode=" + mode + " using " + id.toString()); if (userId != null && !userId.equals(id.getUserId())) { throw new InvalidToken("Block token with " + id.toString() + " doesn't belong to user " + userId);
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(); }