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);
}
}
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());
}
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());
}
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);
}
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);
}
Aggregations