Search in sources :

Example 1 with TAuthenticationTokenIdentifier

use of org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier in project accumulo by apache.

the class AuthenticationTokenIdentifier method readFields.

@Override
public void readFields(DataInput in) throws IOException {
    int length = in.readInt();
    if (length > 0) {
        ThriftMessageUtil msgUtil = new ThriftMessageUtil();
        byte[] serialized = new byte[length];
        in.readFully(serialized);
        var tAuthTokenId = msgUtil.deserialize(serialized, new TAuthenticationTokenIdentifier());
        populateFields(tAuthTokenId);
    }
}
Also used : TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) ThriftMessageUtil(org.apache.accumulo.core.util.ThriftMessageUtil)

Example 2 with TAuthenticationTokenIdentifier

use of org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier in project accumulo by apache.

the class AuthenticationTokenIdentifierTest method testTokenKind.

@Test
public void testTokenKind() {
    String principal = "my_special_principal";
    var token = new AuthenticationTokenIdentifier(new TAuthenticationTokenIdentifier(principal));
    assertEquals(AuthenticationTokenIdentifier.TOKEN_KIND, token.getKind());
}
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 3 with TAuthenticationTokenIdentifier

use of org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier in project accumulo by apache.

the class AuthenticationTokenIdentifierTest method testSerialization.

@Test
public void testSerialization() throws IOException {
    String principal = "my_special_principal";
    var token = new AuthenticationTokenIdentifier(new TAuthenticationTokenIdentifier(principal));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    token.write(out);
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
    AuthenticationTokenIdentifier deserializedToken = new AuthenticationTokenIdentifier();
    deserializedToken.readFields(in);
    assertEquals(token, deserializedToken);
    assertEquals(token.hashCode(), deserializedToken.hashCode());
    assertEquals(token.toString(), deserializedToken.toString());
}
Also used : TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.jupiter.api.Test)

Example 4 with TAuthenticationTokenIdentifier

use of org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier in project accumulo by apache.

the class ThriftMessageUtilTest method testSerializationAsByteArrayWithLimits.

@Test
public void testSerializationAsByteArrayWithLimits() throws IOException {
    ByteBuffer buff = util.serialize(msg);
    TAuthenticationTokenIdentifier copy = new TAuthenticationTokenIdentifier();
    byte[] array = new byte[buff.limit() + 14];
    // Throw some garbage in front and behind the actual message
    array[0] = 'G';
    array[1] = 'A';
    array[2] = 'R';
    array[3] = 'B';
    array[4] = 'A';
    array[5] = 'G';
    array[6] = 'E';
    System.arraycopy(buff.array(), 0, array, 7, buff.limit());
    array[7 + buff.limit()] = 'G';
    array[7 + buff.limit() + 1] = 'A';
    array[7 + buff.limit() + 2] = 'R';
    array[7 + buff.limit() + 3] = 'B';
    array[7 + buff.limit() + 4] = 'A';
    array[7 + buff.limit() + 5] = 'G';
    array[7 + buff.limit() + 6] = 'E';
    util.deserialize(array, 7, buff.limit(), copy);
    assertEquals(msg, copy);
}
Also used : TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 5 with TAuthenticationTokenIdentifier

use of org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier in project accumulo by apache.

the class AuthenticationTokenSecretManager method generateToken.

/**
 * Generates a delegation token for the user with the provided {@code username}.
 *
 * @param username
 *          The client to generate the delegation token for.
 * @param cfg
 *          A configuration object for obtaining the delegation token
 * @return A delegation token for {@code username} created using the {@link #currentKey}.
 */
public Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> generateToken(String username, DelegationTokenConfig cfg) throws AccumuloException {
    requireNonNull(username);
    requireNonNull(cfg);
    var id = new AuthenticationTokenIdentifier(new TAuthenticationTokenIdentifier(username));
    final StringBuilder svcName = new StringBuilder(DelegationTokenImpl.SERVICE_NAME);
    if (id.getInstanceId() != null) {
        svcName.append("-").append(id.getInstanceId());
    }
    // Create password will update the state on the identifier given currentKey. Need to call this
    // before serializing the identifier
    byte[] password;
    try {
        password = createPassword(id, cfg);
    } catch (RuntimeException e) {
        throw new AccumuloException(e.getMessage());
    }
    // The use of the ServiceLoader inside Token doesn't work to automatically get the Identifier
    // Explicitly returning the identifier also saves an extra deserialization
    Token<AuthenticationTokenIdentifier> token = new Token<>(id.getBytes(), password, id.getKind(), new Text(svcName.toString()));
    return Maps.immutableEntry(token, id);
}
Also used : TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TAuthenticationTokenIdentifier(org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text)

Aggregations

TAuthenticationTokenIdentifier (org.apache.accumulo.core.securityImpl.thrift.TAuthenticationTokenIdentifier)12 Test (org.junit.jupiter.api.Test)8 AuthenticationTokenIdentifier (org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier)7 ByteBuffer (java.nio.ByteBuffer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 ThriftMessageUtil (org.apache.accumulo.core.util.ThriftMessageUtil)1 Text (org.apache.hadoop.io.Text)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 Token (org.apache.hadoop.security.token.Token)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1