All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.kusto.data.auth.TokenProviderBase Maven / Gradle / Ivy

There is a newer version: 5.2.0
Show newest version
package com.microsoft.azure.kusto.data.auth;

import com.azure.core.http.HttpClient;
import com.microsoft.azure.kusto.data.UriUtils;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

import com.microsoft.azure.kusto.data.instrumentation.MonitoredActivity;
import com.microsoft.azure.kusto.data.instrumentation.TraceableAttributes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

public abstract class TokenProviderBase implements TraceableAttributes {
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    protected final String clusterUrl;
    protected final HttpClient httpClient;
    private final String authMethod;

    public TokenProviderBase(@NotNull String clusterUrl, @Nullable HttpClient httpClient) throws URISyntaxException {
        this.clusterUrl = UriUtils.setPathForUri(clusterUrl, "");
        this.httpClient = httpClient;
        this.authMethod = getClass().getSimpleName();
    }

    public Mono acquireAccessToken() {
        return initialize().then(Mono.defer(() -> MonitoredActivity.wrap(this.acquireAccessTokenImpl(),
                getAuthMethod().concat(".acquireAccessToken"), getTracingAttributes())));
    }

    Mono initialize() {
        return Mono.empty();
    }

    protected abstract Mono acquireAccessTokenImpl();

    protected String getAuthMethod() {
        return authMethod;
    }

    @Override
    public Map getTracingAttributes() {
        return new HashMap<>();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy