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

com.aeontronix.enhancedmule.tools.anypoint.authentication.AuthenticationProviderBearerTokenImpl Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha4
Show newest version
/*
 * Copyright (c) Aeontronix 2020
 */

package com.aeontronix.enhancedmule.tools.anypoint.authentication;

import com.aeontronix.enhancedmule.tools.util.AnypointAccessToken;
import com.aeontronix.enhancedmule.tools.util.HttpException;
import com.aeontronix.enhancedmule.tools.util.HttpHelper;
import com.aeontronix.restclient.RESTClient;
import com.aeontronix.restclient.RESTException;
import com.aeontronix.restclient.RESTRequest;

public class AuthenticationProviderBearerTokenImpl extends AuthenticationProvider {
    private String anypointBearerToken;

    public AuthenticationProviderBearerTokenImpl(String anypointBearerToken) {
        this.anypointBearerToken = anypointBearerToken;
    }

    @Override
    public AnypointAccessToken getBearerToken(HttpHelper httpHelper) throws HttpException {
        return new AnypointAccessToken(anypointBearerToken);
    }

    @Override
    public String filterSecret(String resStr) {
        return resStr.replace(anypointBearerToken, "**********");
    }

    @Override
    public boolean isRefreshRequired() {
        return false;
    }

    @Override
    public boolean isRefreshable() {
        return false;
    }

    @Override
    public void applyCredentials(RESTRequest request) {
        if (anypointBearerToken != null) {
            request.setHeader("Authorization", "bearer " + anypointBearerToken);
        }
    }

    @Override
    public void refreshCredential(RESTClient restClient) throws RESTException {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy