Example usage for org.apache.commons.httpclient.auth AuthScope ANY_REALM

List of usage examples for org.apache.commons.httpclient.auth AuthScope ANY_REALM

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.auth AuthScope ANY_REALM.

Prototype

String ANY_REALM

To view the source code for org.apache.commons.httpclient.auth AuthScope ANY_REALM.

Click Source Link

Usage

From source file:eu.learnpad.rest.utils.RestResource.java

public HttpClient getClient(String userName, String password) {
    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setAuthenticationPreemptive(true);
    Credentials credentials = new UsernamePasswordCredentials(userName, password);
    AuthScope authentication = new AuthScope(this.HOSTNAME, this.PORT, AuthScope.ANY_REALM);
    httpClient.getState().setCredentials(authentication, credentials);
    return httpClient;
}

From source file:fedora.client.Downloader.java

/**
 * Construct a downloader for a certain repository as a certain user.
 *//*from  w  w w  . ja  v a2s  .co m*/
public Downloader(String host, int port, String context, String user, String pass) throws IOException {
    m_fedoraUrlStart = Administrator.getProtocol() + "://" + host + ":" + port + "/" + context + "/" + "get/";
    m_authScope = new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
    m_creds = new UsernamePasswordCredentials(user, pass);
}

From source file:it.drwolf.ridire.utility.test.SSLConnectionTest.java

public SSLConnectionTest() {
    Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 8443));
    this.httpClient = new HttpClient();
    // this.httpClient.getParams().setAuthenticationPreemptive(true);
    Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
    this.httpClient.getState().setCredentials(
            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), defaultcreds);
    PostMethod method = new PostMethod("https://localhost:8443/engine");
    method.addParameter(new NameValuePair("action", "rescan"));
    try {/*w w w . j a  va 2  s .co m*/
        int status = this.httpClient.executeMethod(method);
        Header redirectLocation = method.getResponseHeader("location");
        String loc = redirectLocation.getValue();
        GetMethod getmethod = new GetMethod("https://localhost:8443/engine");
        status = this.httpClient.executeMethod(getmethod);
        System.out.println(status);
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
}

From source file:io.hawt.web.JBossPostApp.java

@Test
public void testPostWithCredentials() throws Exception {
    System.out.println("Using URL: " + url + " user: " + userName + " password: " + password);

    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod(url);

    //client.getParams().setAuthenticationPreemptive(true);
    method.setDoAuthentication(true);/* ww w.  j  av a2s.  c  o m*/

    Credentials defaultcreds = new UsernamePasswordCredentials(userName, password);
    client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds);
    //client.getState().setProxyCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds);

    method.setRequestEntity(new StringRequestEntity(data, "application/json", "UTF-8"));

    int result = client.executeMethod(method);

    System.out.println("Status: " + result);

    String response = method.getResponseBodyAsString();
    System.out.println(response);
}

From source file:com.twinsoft.convertigo.engine.enums.AuthenticationMode.java

public boolean setCredentials(HttpState httpState, String user, String password, String host, String domain) {
    if (httpState == null)
        return false;
    if (host == null)
        return false;

    AuthScope authScope = new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM);

    Credentials credentials = null;//from ww w .  ja  va 2 s .c om
    int type = getType();
    try {
        switch (type) {
        case 0: // Anonymous
            credentials = ac;
            break;
        case 1: // Basic
            credentials = new UsernamePasswordCredentials(user, password);
            break;
        case 2: // NTLM
            credentials = new NTCredentials(user, password, host, domain);
            break;
        default: // None
        case -1:
            break;
        }

        Credentials curCred = httpState.getCredentials(authScope);
        int needChange = compare(curCred, credentials);
        switch (needChange) {
        case -1:
            httpState.setCredentials(authScope, null);
            Engine.logEngine.debug("(AuthenticationMode) credentials cleared");
            break;
        case 1:
            httpState.setCredentials(authScope, credentials);
            Engine.logEngine.debug("(AuthenticationMode) " + name() + " credentials: " + user + ": ******");
            break;
        case 0:
            Engine.logEngine.debug("(AuthenticationMode) reusing credentials");
            break;
        }

        return needChange != 0;

    } catch (Exception e) {
        Engine.logEngine.error("Unable to set " + name() + " credentials for user", e);
        return false;
    }
}

From source file:com.mindquarry.common.index.SolrIndexClient.java

/**
 * Used to initialize the HTTP client.//from w  ww. j  a va  2 s. c  o m
 */
public void initialize() throws Exception {
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    httpClient = new HttpClient(connectionManager);

    // enable Preemptive authentication to save one round trip
    httpClient.getParams().setAuthenticationPreemptive(true);

    Credentials solrCreds = new UsernamePasswordCredentials(solrLogin, solrPassword);
    AuthScope anyAuthScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);

    httpClient.getState().setCredentials(anyAuthScope, solrCreds);

    // register events by calling base class initialization
    super.initialize();
}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

private static HttpClient getClient(String url, String username, String password) {
    // Disabling strict JAVA SSL security... 
    enableSSLUnsecureTrustStore();//from w  ww . j  a  v  a  2  s. c  om

    HttpClient client = new HttpClient();
    // We set the credentials
    client.getState().setCredentials(new AuthScope(stripURL(url), port, AuthScope.ANY_REALM),
            new UsernamePasswordCredentials(username, password));
    client.getParams().setAuthenticationPreemptive(true);

    return client;
}

From source file:com.collabnet.tracker.common.httpClient.TrackerHttpSender.java

public static void setupHttpClient(HttpClient client, String repositoryUrl, String user, String password) {

    setupHttpClientParams(client, null);

    if (user != null && password != null) {
        AuthScope authScope = new AuthScope(getDomain(repositoryUrl), getPort(repositoryUrl),
                AuthScope.ANY_REALM);
        try {/* w  ww  .jav a 2  s  .  c o m*/
            client.getState().setCredentials(authScope,
                    getCredentials(user, password, InetAddress.getLocalHost()));
        } catch (UnknownHostException e) {
            client.getState().setCredentials(authScope, getCredentials(user, password, null));
        }
    }

    if (isRepositoryHttps(repositoryUrl)) {
        Protocol acceptAllSsl = new Protocol("https",
                (ProtocolSocketFactory) SslProtocolSocketFactory.getInstance(), getPort(repositoryUrl));
        client.getHostConfiguration().setHost(getDomain(repositoryUrl), getPort(repositoryUrl), acceptAllSsl);
        Protocol.registerProtocol("https", acceptAllSsl);
    } else {
        client.getHostConfiguration().setHost(getDomain(repositoryUrl), getPort(repositoryUrl));
    }
}

From source file:be.fedict.trust.Credential.java

/**
 * Any scheme and any realm is allowed.//from  w w w.ja v a2  s . com
 * 
 * @param host
 * @param port
 * @param username
 * @param password
 */
public Credential(String host, int port, String username, String password) {
    this(host, port, AuthScope.ANY_REALM, username, password);
}

From source file:eu.learnpad.cw.rest.internal.DefaultXWikiPackage.java

private void putPage(File indexFile, String spaceName, String pageName)
        throws XWikiRestException, JAXBException {
    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setAuthenticationPreemptive(true);
    Credentials defaultcreds = new UsernamePasswordCredentials("Admin", "admin");
    httpClient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);

    PutMethod putMethod = new PutMethod(
            "http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/" + spaceName + "/pages/" + pageName);
    putMethod.addRequestHeader("Accept", "application/xml");
    putMethod.addRequestHeader("Accept-Ranges", "bytes");
    RequestEntity fileRequestEntity = new FileRequestEntity(indexFile, "application/xml");
    putMethod.setRequestEntity(fileRequestEntity);
    try {//from ww  w .j a  v  a  2s. co  m
        httpClient.executeMethod(putMethod);
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}