use of org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier in project accumulo by apache.
the class SaslDigestCallbackHandlerTest method testTokenSerialization.
@Test
public void testTokenSerialization() throws Exception {
Instance instance = createMock(Instance.class);
AuthenticationTokenSecretManager secretManager = new AuthenticationTokenSecretManager(instance, 1000l);
expect(instance.getInstanceID()).andReturn("instanceid");
replay(instance);
secretManager.addKey(new AuthenticationKey(1, 0l, 100l, keyGen.generateKey()));
Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> entry = secretManager.generateToken("user", cfg);
byte[] password = entry.getKey().getPassword();
char[] encodedPassword = handler.encodePassword(password);
char[] computedPassword = handler.getPassword(secretManager, entry.getValue());
verify(instance);
assertArrayEquals(computedPassword, encodedPassword);
}
use of org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier in project accumulo by apache.
the class SaslDigestCallbackHandlerTest method testTokenAndIdentifierSerialization.
@Test
public void testTokenAndIdentifierSerialization() throws Exception {
Instance instance = createMock(Instance.class);
AuthenticationTokenSecretManager secretManager = new AuthenticationTokenSecretManager(instance, 1000l);
expect(instance.getInstanceID()).andReturn("instanceid");
replay(instance);
secretManager.addKey(new AuthenticationKey(1, 0l, 1000 * 100l, keyGen.generateKey()));
Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> entry = secretManager.generateToken("user", cfg);
byte[] password = entry.getKey().getPassword();
char[] encodedPassword = handler.encodePassword(password);
String name = handler.encodeIdentifier(entry.getValue().getBytes());
byte[] decodedIdentifier = handler.decodeIdentifier(name);
AuthenticationTokenIdentifier identifier = new AuthenticationTokenIdentifier();
identifier.readFields(new DataInputStream(new ByteArrayInputStream(decodedIdentifier)));
char[] computedPassword = handler.getPassword(secretManager, identifier);
verify(instance);
assertArrayEquals(computedPassword, encodedPassword);
}
use of org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier in project accumulo by apache.
the class AuthenticationTokenSecretManagerTest method testTokenIssuedInFuture.
@Test(expected = InvalidToken.class)
public void testTokenIssuedInFuture() throws Exception {
// start of the test
long then = System.currentTimeMillis();
long tokenLifetime = 60 * 1000;
AuthenticationTokenSecretManager secretManager = new AuthenticationTokenSecretManager(instance, tokenLifetime);
// Add a current key
secretManager.addKey(new AuthenticationKey(1, then, then + tokenLifetime, keyGen.generateKey()));
String principal = "user@EXAMPLE.COM";
Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> pair = secretManager.generateToken(principal, cfg);
Token<AuthenticationTokenIdentifier> token = pair.getKey();
// Reconstitute the token identifier (will happen when clients are involved)
AuthenticationTokenIdentifier id = new AuthenticationTokenIdentifier();
id.readFields(new DataInputStream(new ByteArrayInputStream(token.getIdentifier())));
// Increase the value of issueDate
id.setIssueDate(Long.MAX_VALUE);
secretManager.retrievePassword(id);
}
use of org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier in project accumulo by apache.
the class AuthenticationTokenSecretManagerTest method testVerifyPassword.
@Test
public void testVerifyPassword() throws Exception {
// start of the test
long then = System.currentTimeMillis();
// 1 minute
long tokenLifetime = 60 * 1000;
AuthenticationTokenSecretManager secretManager = new AuthenticationTokenSecretManager(instance, tokenLifetime);
// Add a current key
secretManager.addKey(new AuthenticationKey(1, then, then + tokenLifetime, keyGen.generateKey()));
String principal = "user@EXAMPLE.COM";
Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> pair = secretManager.generateToken(principal, cfg);
Token<AuthenticationTokenIdentifier> token = pair.getKey();
AuthenticationTokenIdentifier id = new AuthenticationTokenIdentifier();
id.readFields(new DataInputStream(new ByteArrayInputStream(token.getIdentifier())));
byte[] password = secretManager.retrievePassword(id);
// The passwords line up against multiple calls with the same ID
assertArrayEquals(password, secretManager.retrievePassword(id));
// Make a second token for the same user
Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> pair2 = secretManager.generateToken(principal, cfg);
Token<AuthenticationTokenIdentifier> token2 = pair2.getKey();
// Reconstitute the token identifier (will happen when clients are involved)
AuthenticationTokenIdentifier id2 = new AuthenticationTokenIdentifier();
id2.readFields(new DataInputStream(new ByteArrayInputStream(token2.getIdentifier())));
// Get the password
byte[] password2 = secretManager.retrievePassword(id2);
// It should be different than the password for the first user.
assertFalse("Different tokens for the same user shouldn't have the same password", Arrays.equals(password, password2));
}
use of org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier in project accumulo by apache.
the class AuthenticationTokenSecretManagerTest method testRolledMasterKey.
@Test(expected = InvalidToken.class)
public void testRolledMasterKey() throws Exception {
// start of the test
long then = System.currentTimeMillis();
long tokenLifetime = 60 * 1000;
AuthenticationTokenSecretManager secretManager = new AuthenticationTokenSecretManager(instance, tokenLifetime);
// Add a current key
AuthenticationKey authKey1 = new AuthenticationKey(1, then, then + tokenLifetime, keyGen.generateKey());
secretManager.addKey(authKey1);
String principal = "user@EXAMPLE.COM";
Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> pair = secretManager.generateToken(principal, cfg);
Token<AuthenticationTokenIdentifier> token = pair.getKey();
AuthenticationTokenIdentifier id = new AuthenticationTokenIdentifier();
id.readFields(new DataInputStream(new ByteArrayInputStream(token.getIdentifier())));
long now = System.currentTimeMillis();
secretManager.addKey(new AuthenticationKey(2, now, now + tokenLifetime, keyGen.generateKey()));
// Should succeed -- the SecretManager still has authKey1
secretManager.retrievePassword(id);
// Remove authKey1
secretManager.removeKey(authKey1.getKeyId());
// Should fail -- authKey1 (presumably) expired, cannot authenticate
secretManager.retrievePassword(id);
}
Aggregations