diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java index 8400b4f04bf..4d3915e3fa3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java @@ -94,6 +94,18 @@ public class BlockPoolTokenSecretManager extends storageTypes, storageIds); } + /** + * See {@link BlockTokenSecretManager#checkAccess(BlockTokenIdentifier, + * String, ExtendedBlock, BlockTokenIdentifier.AccessMode, + * StorageType[])} + */ + public void checkAccess(BlockTokenIdentifier id, String userId, + ExtendedBlock block, AccessMode mode, StorageType[] storageTypes) + throws InvalidToken { + get(block.getBlockPoolId()).checkAccess(id, userId, block, mode, + storageTypes); + } + /** * See {@link BlockTokenSecretManager#checkAccess(Token, String, * ExtendedBlock, BlockTokenIdentifier.AccessMode, @@ -108,7 +120,7 @@ public class BlockPoolTokenSecretManager extends } /** - * See {@link BlockTokenSecretManager#addKeys(ExportedBlockKeys)} + * See {@link BlockTokenSecretManager#addKeys(ExportedBlockKeys)}. */ public void addKeys(String bpid, ExportedBlockKeys exportedKeys) throws IOException { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockTokenSecretManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockTokenSecretManager.java index da830a6d419..6b7dd37e13b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockTokenSecretManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockTokenSecretManager.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; @@ -291,6 +292,23 @@ public class BlockTokenSecretManager extends } } + /** + * 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) throws InvalidToken { + checkAccess(id, userId, block, mode); + if (ArrayUtils.isNotEmpty(storageTypes)) { + checkAccess(id.getStorageTypes(), storageTypes, "StorageTypes"); + } + } + public void checkAccess(BlockTokenIdentifier id, String userId, ExtendedBlock block, BlockTokenIdentifier.AccessMode mode) throws InvalidToken { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java index aaddb3654aa..c16b471e2d2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/security/token/block/TestBlockToken.java @@ -215,7 +215,11 @@ public class TestBlockToken { private static void checkAccess(BlockTokenSecretManager m, Token t, ExtendedBlock blk, BlockTokenIdentifier.AccessMode mode, StorageType[] storageTypes, - String[] storageIds) throws SecretManager.InvalidToken { + String[] storageIds) throws IOException { + if(storageIds == null) { + // Test overloaded checkAccess method. + m.checkAccess(t.decodeIdentifier(), null, blk, mode, storageTypes); + } m.checkAccess(t, null, blk, mode, storageTypes, storageIds); } @@ -801,6 +805,7 @@ public class TestBlockToken { emptyStorageIds); sm.checkAccess(id, null, block3, mode, storageTypes, null); + sm.checkAccess(id, null, block3, mode, storageTypes); } @Test