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

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

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

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.jsoftware.restclient.RestClientPlugin;
import org.jsoftware.restclient.RestClientResponse;

/**
 * Add Authorization header with value Basic Authorization
 * @author szalik
 */
public class AuthBasicPlugin implements RestClientPlugin {
    private final String auth;

    public AuthBasicPlugin(String username, String password) {
        byte[] encoding = Base64.encodeBase64((username + ":" + password).getBytes());
        this.auth = new String(encoding);
    }

    @Override
    public void plugin(PluginContext context, PluginChain chain) throws Exception {
        context.getRequest().addHeader("Authorization", "Basic " + auth);
        chain.continueChain();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy