use of org.apache.accumulo.core.security.thrift.TDelegationTokenConfig in project accumulo by apache.
the class SecurityOperationsImpl method getDelegationToken.
@Override
public DelegationToken getDelegationToken(DelegationTokenConfig cfg) throws AccumuloException, AccumuloSecurityException {
final TDelegationTokenConfig tConfig;
if (null != cfg) {
tConfig = DelegationTokenConfigSerializer.serialize(cfg);
} else {
tConfig = new TDelegationTokenConfig();
}
TDelegationToken thriftToken;
try {
thriftToken = MasterClient.execute(context, new ClientExecReturn<TDelegationToken, Client>() {
@Override
public TDelegationToken execute(Client client) throws Exception {
return client.getDelegationToken(Tracer.traceInfo(), context.rpcCreds(), tConfig);
}
});
} catch (TableNotFoundException e) {
// should never happen
throw new AssertionError("Received TableNotFoundException on method which should not throw that exception", e);
}
AuthenticationTokenIdentifier identifier = new AuthenticationTokenIdentifier(thriftToken.getIdentifier());
// Get the password out of the thrift delegation token
return new DelegationTokenImpl(thriftToken.getPassword(), identifier);
}
use of org.apache.accumulo.core.security.thrift.TDelegationTokenConfig in project accumulo by apache.
the class DelegationTokenConfigSerializer method serialize.
/**
* Serialize the delegation token config into the thrift variant
*
* @param config
* The configuration
*/
public static TDelegationTokenConfig serialize(DelegationTokenConfig config) {
TDelegationTokenConfig tconfig = new TDelegationTokenConfig();
tconfig.setLifetime(config.getTokenLifetime(TimeUnit.MILLISECONDS));
return tconfig;
}
use of org.apache.accumulo.core.security.thrift.TDelegationTokenConfig in project accumulo by apache.
the class MasterClientServiceHandler method getDelegationToken.
@Override
public TDelegationToken getDelegationToken(TInfo tinfo, TCredentials credentials, TDelegationTokenConfig tConfig) throws ThriftSecurityException, TException {
if (!master.security.canObtainDelegationToken(credentials)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
// Round-about way to verify that SASL is also enabled.
if (!master.delegationTokensAvailable()) {
throw new TException("Delegation tokens are not available for use");
}
final DelegationTokenConfig config = DelegationTokenConfigSerializer.deserialize(tConfig);
final AuthenticationTokenSecretManager secretManager = master.getSecretManager();
try {
Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> pair = secretManager.generateToken(credentials.principal, config);
return new TDelegationToken(ByteBuffer.wrap(pair.getKey().getPassword()), pair.getValue().getThriftIdentifier());
} catch (Exception e) {
throw new TException(e.getMessage());
}
}
use of org.apache.accumulo.core.security.thrift.TDelegationTokenConfig in project accumulo by apache.
the class DelegationTokenConfigSerializerTest method test.
@Test
public void test() {
DelegationTokenConfig cfg = new DelegationTokenConfig();
cfg.setTokenLifetime(8323, TimeUnit.HOURS);
TDelegationTokenConfig tCfg = DelegationTokenConfigSerializer.serialize(cfg);
assertEquals(tCfg.getLifetime(), cfg.getTokenLifetime(TimeUnit.MILLISECONDS));
assertEquals(cfg, DelegationTokenConfigSerializer.deserialize(tCfg));
}
Aggregations