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

it.geosolutions.geoserver.rest.http.UsernamePasswordAuthenticator Maven / Gradle / Ivy

Go to download

GeoServer Manager is a library to interact with GeoServer The scope of this library is to have a simple API, and use as few external libs as possible.

The newest version!
package it.geosolutions.geoserver.rest.http;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;

public class UsernamePasswordAuthenticator implements GeoServerRestAuthenticator {
    
    private String username;
    
    private String pw;
    
    public UsernamePasswordAuthenticator(String username, String pw) {
        this.username = username;
        this.pw = pw;
    }

    @Override
    public void setAuth(HttpClient client, HttpMethod method) throws URIException {
        Credentials defaultcreds = new UsernamePasswordCredentials(username, pw);
        client.getState().setCredentials(
                new AuthScope(method.getURI().getHost(), method.getURI().getPort()), defaultcreds);
        client.getParams().setAuthenticationPreemptive(true); // GS2 by
                                                              // default
                                                              // always
                                                              // requires
                                                              // authentication
    }
    

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy