use of co.cask.cdap.security.guice.FileBasedSecurityModule in project cdap by caskdata.
the class TestFileBasedTokenManager method testFileBasedKey.
/**
* Test that two token managers can share a key that is written to a file.
* @throws Exception
*/
@Test
public void testFileBasedKey() throws Exception {
// Create two token managers that points to the same path
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
TokenManager tokenManager = Guice.createInjector(new IOModule(), new ConfigModule(cConf), new FileBasedSecurityModule(), new DiscoveryRuntimeModule().getInMemoryModules()).getInstance(TokenManager.class);
tokenManager.startAndWait();
TokenManager tokenManager2 = Guice.createInjector(new IOModule(), new ConfigModule(cConf), new FileBasedSecurityModule(), new DiscoveryRuntimeModule().getInMemoryModules()).getInstance(TokenManager.class);
tokenManager2.startAndWait();
Assert.assertNotSame("ERROR: Both token managers refer to the same object.", tokenManager, tokenManager2);
String user = "testuser";
long now = System.currentTimeMillis();
List<String> groups = Lists.newArrayList("users", "admins");
AccessTokenIdentifier identifier = new AccessTokenIdentifier(user, groups, now, now + TOKEN_DURATION);
AccessToken token = tokenManager.signIdentifier(identifier);
// Since both tokenManagers have the same key, they must both be able to validate the secret.
tokenManager.validateSecret(token);
tokenManager2.validateSecret(token);
}
use of co.cask.cdap.security.guice.FileBasedSecurityModule in project cdap by caskdata.
the class TestKeyIdentifierCodec method setup.
@BeforeClass
public static void setup() throws Exception {
Injector injector = Guice.createInjector(new IOModule(), new ConfigModule(), new FileBasedSecurityModule(), new DiscoveryRuntimeModule().getInMemoryModules());
CConfiguration conf = injector.getInstance(CConfiguration.class);
keyIdentifierCodec = injector.getInstance(KeyIdentifierCodec.class);
keyLength = conf.getInt(Constants.Security.TOKEN_DIGEST_KEY_LENGTH);
keyAlgo = conf.get(Constants.Security.TOKEN_DIGEST_ALGO);
keyGenerator = KeyGenerator.getInstance(keyAlgo);
keyGenerator.init(keyLength);
}
use of co.cask.cdap.security.guice.FileBasedSecurityModule in project cdap by caskdata.
the class TestFileBasedTokenManager method getTokenManagerAndCodec.
@Override
protected ImmutablePair<TokenManager, Codec<AccessToken>> getTokenManagerAndCodec() throws IOException {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
Injector injector = Guice.createInjector(new IOModule(), new ConfigModule(cConf), new FileBasedSecurityModule(), new DiscoveryRuntimeModule().getInMemoryModules());
TokenManager tokenManager = injector.getInstance(TokenManager.class);
tokenManager.startAndWait();
Codec<AccessToken> tokenCodec = injector.getInstance(AccessTokenCodec.class);
return new ImmutablePair<>(tokenManager, tokenCodec);
}
Aggregations