Search in sources :

Example 1 with AuthenticationKey

use of org.apache.accumulo.server.security.delegation.AuthenticationKey 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);
}
Also used : Instance(org.apache.accumulo.core.client.Instance) AuthenticationKey(org.apache.accumulo.server.security.delegation.AuthenticationKey) AuthenticationTokenIdentifier(org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier) AuthenticationTokenSecretManager(org.apache.accumulo.server.security.delegation.AuthenticationTokenSecretManager) Token(org.apache.hadoop.security.token.Token) Test(org.junit.Test)

Example 2 with AuthenticationKey

use of org.apache.accumulo.server.security.delegation.AuthenticationKey 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);
}
Also used : Instance(org.apache.accumulo.core.client.Instance) ByteArrayInputStream(java.io.ByteArrayInputStream) AuthenticationKey(org.apache.accumulo.server.security.delegation.AuthenticationKey) AuthenticationTokenIdentifier(org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier) AuthenticationTokenSecretManager(org.apache.accumulo.server.security.delegation.AuthenticationTokenSecretManager) Token(org.apache.hadoop.security.token.Token) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

Instance (org.apache.accumulo.core.client.Instance)2 AuthenticationTokenIdentifier (org.apache.accumulo.core.client.impl.AuthenticationTokenIdentifier)2 AuthenticationKey (org.apache.accumulo.server.security.delegation.AuthenticationKey)2 AuthenticationTokenSecretManager (org.apache.accumulo.server.security.delegation.AuthenticationTokenSecretManager)2 Token (org.apache.hadoop.security.token.Token)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1