use of org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto in project ozone by apache.
the class OMGetDelegationTokenRequest method preExecute.
@Override
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
GetDelegationTokenRequestProto getDelegationTokenRequest = getOmRequest().getGetDelegationTokenRequest();
// Call OM to create token
Token<OzoneTokenIdentifier> token = ozoneManager.getDelegationToken(new Text(getDelegationTokenRequest.getRenewer()));
// Client issues GetDelegationToken request, when received by OM leader
// it will generate a token. Original GetDelegationToken request is
// converted to UpdateGetDelegationToken request with the generated token
// information. This updated request will be submitted to Ratis. In this
// way delegation token created by leader, will be replicated across all
// OMs. With this approach, original GetDelegationToken request from
// client does not need any proto changes.
// Create UpdateGetDelegationTokenRequest with token response.
OMRequest.Builder omRequest;
if (token != null) {
omRequest = OMRequest.newBuilder().setUserInfo(getUserInfo()).setUpdateGetDelegationTokenRequest(UpdateGetDelegationTokenRequest.newBuilder().setGetDelegationTokenResponse(GetDelegationTokenResponseProto.newBuilder().setResponse(SecurityProtos.GetDelegationTokenResponseProto.newBuilder().setToken(OMPBHelper.convertToTokenProto(token)).build()).build()).setTokenRenewInterval(ozoneManager.getDelegationTokenMgr().getTokenRenewInterval())).setCmdType(getOmRequest().getCmdType()).setClientId(getOmRequest().getClientId());
} else {
// If token is null, do not set GetDelegationTokenResponse with response.
omRequest = OMRequest.newBuilder().setUserInfo(getUserInfo()).setUpdateGetDelegationTokenRequest(UpdateGetDelegationTokenRequest.newBuilder().setGetDelegationTokenResponse(GetDelegationTokenResponseProto.newBuilder())).setCmdType(getOmRequest().getCmdType()).setClientId(getOmRequest().getClientId());
}
if (getOmRequest().hasTraceID()) {
omRequest.setTraceID(getOmRequest().getTraceID());
}
return omRequest.build();
}
use of org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto in project ozone by apache.
the class TestOMGetDelegationTokenRequest method setupRequest.
private void setupRequest() {
GetDelegationTokenRequestProto getDelegationTokenRequestProto = GetDelegationTokenRequestProto.newBuilder().setRenewer(identifier.getRenewer().toString()).build();
originalRequest = OMRequest.newBuilder().setClientId(UUID.randomUUID().toString()).setCmdType(Type.GetDelegationToken).setGetDelegationTokenRequest(getDelegationTokenRequestProto).build();
omGetDelegationTokenRequest = new OMGetDelegationTokenRequest(originalRequest);
modifiedRequest = null;
}
use of org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto in project ozone by apache.
the class TestOMGetDelegationTokenResponse method setupGetDelegationToken.
@Before
public void setupGetDelegationToken() {
Text tester = new Text("tester");
identifier = new OzoneTokenIdentifier(tester, tester, tester);
identifier.setOmCertSerialId("certID");
GetDelegationTokenRequestProto getDelegationTokenRequestProto = GetDelegationTokenRequestProto.newBuilder().setRenewer(identifier.getRenewer().toString()).build();
OMRequest omRequest = OMRequest.newBuilder().setClientId(UUID.randomUUID().toString()).setCmdType(Type.GetDelegationToken).setGetDelegationTokenRequest(getDelegationTokenRequestProto).build();
updateGetDelegationTokenRequest = new OMGetDelegationTokenRequest(omRequest).getOmRequest().getUpdateGetDelegationTokenRequest();
}
use of org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto in project ozone by apache.
the class OzoneManagerProtocolClientSideTranslatorPB method getDelegationToken.
/**
* Get a valid Delegation Token.
*
* @param renewer the designated renewer for the token
* @return Token<OzoneDelegationTokenSelector>
* @throws OMException
*/
@Override
public Token<OzoneTokenIdentifier> getDelegationToken(Text renewer) throws OMException {
GetDelegationTokenRequestProto req = GetDelegationTokenRequestProto.newBuilder().setRenewer(renewer == null ? "" : renewer.toString()).build();
OMRequest omRequest = createOMRequest(Type.GetDelegationToken).setGetDelegationTokenRequest(req).build();
final GetDelegationTokenResponseProto resp;
try {
resp = handleError(submitRequest(omRequest)).getGetDelegationTokenResponse();
return resp.getResponse().hasToken() ? OMPBHelper.convertToDelegationToken(resp.getResponse().getToken()) : null;
} catch (IOException e) {
if (e instanceof OMException) {
throw (OMException) e;
}
throw new OMException("Get delegation token failed.", e, TOKEN_ERROR_OTHER);
}
}
Aggregations