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

org.jsoftware.restclient.plugins.AuthBearerPlugin Maven / Gradle / Ivy

There is a newer version: 1.5
Show newest version
package org.jsoftware.restclient.plugins;

import org.apache.commons.lang3.StringUtils;
import org.jsoftware.restclient.RestClientPlugin;

/**
 * Add Authorization header with value Bearertoken
 * @author szalik
 */
public class AuthBearerPlugin implements RestClientPlugin {
    private String token;

    public AuthBearerPlugin() {
        this(null);
    }

    public AuthBearerPlugin(String token) {
        this.token = token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public void clearToken() {
        this.token = null;
    }

    @Override
    public void plugin(PluginContext context, PluginChain chain) throws Exception {
        if (StringUtils.isNotBlank(token)) {
            context.getRequest().addHeader("Authorization", "Bearer " + token);
        }
        chain.continueChain();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy