Search in sources :

Example 11 with AuthenticationTokenIdentifier

use of org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier in project accumulo by apache.

the class SaslConnectionParamsTest method testDelegationTokenImpl.

@Test
public void testDelegationTokenImpl() throws Exception {
    final DelegationTokenImpl token = new DelegationTokenImpl(new byte[0], new AuthenticationTokenIdentifier(createTAuthIdentifier("user", 1, 10L, 20L, "instanceid")));
    testUser.doAs((PrivilegedExceptionAction<Void>) () -> {
        final SaslConnectionParams saslParams = createSaslParams(token);
        assertEquals(primary, saslParams.getKerberosServerPrimary());
        final QualityOfProtection defaultQop = QualityOfProtection.get(Property.RPC_SASL_QOP.getDefaultValue());
        assertEquals(defaultQop, saslParams.getQualityOfProtection());
        assertEquals(SaslMechanism.DIGEST_MD5, saslParams.getMechanism());
        assertNotNull(saslParams.getCallbackHandler());
        assertEquals(SaslClientDigestCallbackHandler.class, saslParams.getCallbackHandler().getClass());
        Map<String, String> properties = saslParams.getSaslProperties();
        assertEquals(1, properties.size());
        assertEquals(defaultQop.getQuality(), properties.get(Sasl.QOP));
        assertEquals(username, saslParams.getPrincipal());
        return null;
    });
}
Also used : QualityOfProtection(org.apache.accumulo.core.rpc.SaslConnectionParams.QualityOfProtection) DelegationTokenImpl(org.apache.accumulo.core.clientImpl.DelegationTokenImpl) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 12 with AuthenticationTokenIdentifier

use of org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier in project accumulo by apache.

the class SaslConnectionParamsTest method testEquality.

@Test
public void testEquality() throws Exception {
    final KerberosToken token = EasyMock.createMock(KerberosToken.class);
    SaslConnectionParams params1 = testUser.doAs((PrivilegedExceptionAction<SaslConnectionParams>) () -> createSaslParams(token));
    SaslConnectionParams params2 = testUser.doAs((PrivilegedExceptionAction<SaslConnectionParams>) () -> createSaslParams(token));
    assertEquals(params1, params2);
    assertEquals(params1.hashCode(), params2.hashCode());
    final DelegationTokenImpl delToken1 = new DelegationTokenImpl(new byte[0], new AuthenticationTokenIdentifier(createTAuthIdentifier("user", 1, 10L, 20L, "instanceid")));
    SaslConnectionParams params3 = testUser.doAs((PrivilegedExceptionAction<SaslConnectionParams>) () -> createSaslParams(delToken1));
    assertNotEquals(params1, params3);
    assertNotEquals(params1.hashCode(), params3.hashCode());
    assertNotEquals(params2, params3);
    assertNotEquals(params2.hashCode(), params3.hashCode());
    final DelegationTokenImpl delToken2 = new DelegationTokenImpl(new byte[0], new AuthenticationTokenIdentifier(createTAuthIdentifier("user", 1, 10L, 20L, "instanceid")));
    SaslConnectionParams params4 = testUser.doAs((PrivilegedExceptionAction<SaslConnectionParams>) () -> createSaslParams(delToken2));
    assertNotEquals(params1, params4);
    assertNotEquals(params1.hashCode(), params4.hashCode());
    assertNotEquals(params2, params4);
    assertNotEquals(params2.hashCode(), params4.hashCode());
    assertEquals(params3, params4);
    assertEquals(params3.hashCode(), params4.hashCode());
}
Also used : KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) DelegationTokenImpl(org.apache.accumulo.core.clientImpl.DelegationTokenImpl) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) Test(org.junit.jupiter.api.Test)

Example 13 with AuthenticationTokenIdentifier

use of org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier in project accumulo by apache.

the class AuthenticationTokenIdentifierTest method testExtendedEquality.

@Test
public void testExtendedEquality() {
    String principal = "user";
    var token = new AuthenticationTokenIdentifier(new TAuthenticationTokenIdentifier(principal));
    assertEquals(token, token);
    var newToken = new AuthenticationTokenIdentifier(createTAuthIdentifier(principal, 1, 5L, 10L, "uuid"));
    assertNotEquals(token, newToken);
    assertNotEquals(token.hashCode(), newToken.hashCode());
    var dblNewToken = new AuthenticationTokenIdentifier(new TAuthenticationTokenIdentifier(principal));
    dblNewToken.setKeyId(1);
    dblNewToken.setIssueDate(5L);
    dblNewToken.setExpirationDate(10L);
    dblNewToken.setInstanceId(InstanceId.of("uuid"));
}
Also used : TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) Test(org.junit.jupiter.api.Test)

Example 14 with AuthenticationTokenIdentifier

use of org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier in project accumulo by apache.

the class AuthenticationTokenIdentifierTest method testToString.

@Test
public void testToString() {
    String principal = "my_special_principal";
    var token = new AuthenticationTokenIdentifier(new TAuthenticationTokenIdentifier(principal));
    assertTrue(token.toString().contains(principal));
}
Also used : TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) Test(org.junit.jupiter.api.Test)

Example 15 with AuthenticationTokenIdentifier

use of org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier in project accumulo by apache.

the class AuthenticationTokenIdentifierTest method testUgi.

@Test
public void testUgi() {
    String principal = "user";
    var token = new AuthenticationTokenIdentifier(new TAuthenticationTokenIdentifier(principal));
    UserGroupInformation actual = token.getUser();
    UserGroupInformation expected = UserGroupInformation.createRemoteUser(principal);
    assertEquals(expected.getAuthenticationMethod(), actual.getAuthenticationMethod());
    assertEquals(expected.getUserName(), expected.getUserName());
}
Also used : TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.jupiter.api.Test)

Aggregations

AuthenticationTokenIdentifier (org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier)29 ByteArrayInputStream (java.io.ByteArrayInputStream)13 DataInputStream (java.io.DataInputStream)13 DelegationTokenImpl (org.apache.accumulo.core.clientImpl.DelegationTokenImpl)11 Token (org.apache.hadoop.security.token.Token)11 Test (org.junit.jupiter.api.Test)11 TAuthenticationTokenIdentifier (org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 DelegationTokenConfig (org.apache.accumulo.core.client.admin.DelegationTokenConfig)6 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)6 InvalidToken (org.apache.hadoop.security.token.SecretManager.InvalidToken)6 AccumuloException (org.apache.accumulo.core.client.AccumuloException)5 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)5 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)5 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 DelegationToken (org.apache.accumulo.core.client.security.tokens.DelegationToken)4 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)4 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3