Search in sources :

Example 1 with GetDelegationTokenRequestProto

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();
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OzoneTokenIdentifier(org.apache.hadoop.ozone.security.OzoneTokenIdentifier) Text(org.apache.hadoop.io.Text) GetDelegationTokenRequestProto(org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto)

Example 2 with GetDelegationTokenRequestProto

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;
}
Also used : GetDelegationTokenRequestProto(org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto)

Example 3 with GetDelegationTokenRequestProto

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();
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OMGetDelegationTokenRequest(org.apache.hadoop.ozone.om.request.security.OMGetDelegationTokenRequest) OzoneTokenIdentifier(org.apache.hadoop.ozone.security.OzoneTokenIdentifier) Text(org.apache.hadoop.io.Text) GetDelegationTokenRequestProto(org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto) Before(org.junit.Before)

Example 4 with GetDelegationTokenRequestProto

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);
    }
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) GetDelegationTokenResponseProto(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetDelegationTokenResponseProto) IOException(java.io.IOException) GetDelegationTokenRequestProto(org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Aggregations

GetDelegationTokenRequestProto (org.apache.hadoop.ozone.security.proto.SecurityProtos.GetDelegationTokenRequestProto)4 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)3 Text (org.apache.hadoop.io.Text)2 OzoneTokenIdentifier (org.apache.hadoop.ozone.security.OzoneTokenIdentifier)2 IOException (java.io.IOException)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 OMGetDelegationTokenRequest (org.apache.hadoop.ozone.om.request.security.OMGetDelegationTokenRequest)1 GetDelegationTokenResponseProto (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetDelegationTokenResponseProto)1 Before (org.junit.Before)1