Search in sources :

Example 1 with CreatableRenewers

use of org.apache.kafka.common.message.CreateDelegationTokenRequestData.CreatableRenewers in project kafka by apache.

the class KafkaAdminClient method createDelegationToken.

@Override
public CreateDelegationTokenResult createDelegationToken(final CreateDelegationTokenOptions options) {
    final KafkaFutureImpl<DelegationToken> delegationTokenFuture = new KafkaFutureImpl<>();
    final long now = time.milliseconds();
    List<CreatableRenewers> renewers = new ArrayList<>();
    for (KafkaPrincipal principal : options.renewers()) {
        renewers.add(new CreatableRenewers().setPrincipalName(principal.getName()).setPrincipalType(principal.getPrincipalType()));
    }
    runnable.call(new Call("createDelegationToken", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {

        @Override
        CreateDelegationTokenRequest.Builder createRequest(int timeoutMs) {
            return new CreateDelegationTokenRequest.Builder(new CreateDelegationTokenRequestData().setRenewers(renewers).setMaxLifetimeMs(options.maxlifeTimeMs()));
        }

        @Override
        void handleResponse(AbstractResponse abstractResponse) {
            CreateDelegationTokenResponse response = (CreateDelegationTokenResponse) abstractResponse;
            if (response.hasError()) {
                delegationTokenFuture.completeExceptionally(response.error().exception());
            } else {
                CreateDelegationTokenResponseData data = response.data();
                TokenInformation tokenInfo = new TokenInformation(data.tokenId(), new KafkaPrincipal(data.principalType(), data.principalName()), options.renewers(), data.issueTimestampMs(), data.maxTimestampMs(), data.expiryTimestampMs());
                DelegationToken token = new DelegationToken(tokenInfo, data.hmac());
                delegationTokenFuture.complete(token);
            }
        }

        @Override
        void handleFailure(Throwable throwable) {
            delegationTokenFuture.completeExceptionally(throwable);
        }
    }, now);
    return new CreateDelegationTokenResult(delegationTokenFuture);
}
Also used : CreateDelegationTokenRequestData(org.apache.kafka.common.message.CreateDelegationTokenRequestData) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) DelegationToken(org.apache.kafka.common.security.token.delegation.DelegationToken) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) ArrayList(java.util.ArrayList) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) TokenInformation(org.apache.kafka.common.security.token.delegation.TokenInformation) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) CreatableRenewers(org.apache.kafka.common.message.CreateDelegationTokenRequestData.CreatableRenewers) CreateDelegationTokenResponseData(org.apache.kafka.common.message.CreateDelegationTokenResponseData) CreateDelegationTokenRequest(org.apache.kafka.common.requests.CreateDelegationTokenRequest) CreateDelegationTokenResponse(org.apache.kafka.common.requests.CreateDelegationTokenResponse)

Example 2 with CreatableRenewers

use of org.apache.kafka.common.message.CreateDelegationTokenRequestData.CreatableRenewers in project kafka by apache.

the class RequestResponseTest method createCreateTokenRequest.

private CreateDelegationTokenRequest createCreateTokenRequest(short version) {
    List<CreatableRenewers> renewers = new ArrayList<>();
    renewers.add(new CreatableRenewers().setPrincipalType("User").setPrincipalName("user1"));
    renewers.add(new CreatableRenewers().setPrincipalType("User").setPrincipalName("user2"));
    return new CreateDelegationTokenRequest.Builder(new CreateDelegationTokenRequestData().setRenewers(renewers).setMaxLifetimeMs(System.currentTimeMillis())).build(version);
}
Also used : CreatableRenewers(org.apache.kafka.common.message.CreateDelegationTokenRequestData.CreatableRenewers) CreateDelegationTokenRequestData(org.apache.kafka.common.message.CreateDelegationTokenRequestData) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 CreateDelegationTokenRequestData (org.apache.kafka.common.message.CreateDelegationTokenRequestData)2 CreatableRenewers (org.apache.kafka.common.message.CreateDelegationTokenRequestData.CreatableRenewers)2 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 CreateDelegationTokenResponseData (org.apache.kafka.common.message.CreateDelegationTokenResponseData)1 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 CreateDelegationTokenRequest (org.apache.kafka.common.requests.CreateDelegationTokenRequest)1 CreateDelegationTokenResponse (org.apache.kafka.common.requests.CreateDelegationTokenResponse)1 KafkaPrincipal (org.apache.kafka.common.security.auth.KafkaPrincipal)1 DelegationToken (org.apache.kafka.common.security.token.delegation.DelegationToken)1 TokenInformation (org.apache.kafka.common.security.token.delegation.TokenInformation)1