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

mesosphere.dcos.client.DCOSAuthTokenHeaderInterceptor Maven / Gradle / Ivy

There is a newer version: 0.6.3
Show newest version
package mesosphere.dcos.client;

import static java.util.Objects.requireNonNull;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import mesosphere.dcos.client.model.DCOSAuthCredentials;
import mesosphere.dcos.client.model.DCOSAuthToken;

public class DCOSAuthTokenHeaderInterceptor implements RequestInterceptor {
    private final DCOS dcosClient;
    private final DCOSAuthCredentials authCredentials;
    private DCOSAuthToken dcosAuthToken;

    DCOSAuthTokenHeaderInterceptor(final DCOSAuthCredentials authCredentials, final DCOS dcosClient) {
        requireNonNull(authCredentials, "authCredentials:null");
        requireNonNull(dcosClient, "dcosClient:null");

        this.dcosClient = dcosClient;
        this.authCredentials = authCredentials;
    }

    @Override
    public void apply(RequestTemplate template) {
        if (dcosAuthToken == null || dcosAuthToken.requiresRefresh()) {
            dcosAuthToken = dcosClient.authenticate(authCredentials).toDCOSAuthToken();
        }

        template.header("Authorization", "token=" + dcosAuthToken.getToken());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy