org.apache.http.auth.AuthScope

Here are the examples of the java api class org.apache.http.auth.AuthScope taken from open source projects.

1. TestClientAuthentication#testBasicAuthenticationSuccessOnRepeatablePost()

Project: httpasyncclient
File: TestClientAuthentication.java
@Test
public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
    TestCredentialsProvider credsProvider = new TestCredentialsProvider(new UsernamePasswordCredentials("test", "test"));
    this.httpclient.setCredentialsProvider(credsProvider);
    HttpPost httppost = new HttpPost("/");
    httppost.setEntity(new NStringEntity("some important stuff", HTTP.ISO_8859_1));
    Future<HttpResponse> future = this.httpclient.execute(this.target, httppost, null);
    HttpResponse response = future.get();
    Assert.assertNotNull(response);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    AuthScope authscope = credsProvider.getAuthScope();
    Assert.assertNotNull(authscope);
    Assert.assertEquals("test realm", authscope.getRealm());
}

2. TestClientAuthentication#testBasicAuthenticationSuccess()

Project: httpasyncclient
File: TestClientAuthentication.java
@Test
public void testBasicAuthenticationSuccess() throws Exception {
    TestCredentialsProvider credsProvider = new TestCredentialsProvider(new UsernamePasswordCredentials("test", "test"));
    this.httpclient.setCredentialsProvider(credsProvider);
    HttpGet httpget = new HttpGet("/");
    Future<HttpResponse> future = this.httpclient.execute(this.target, httpget, null);
    HttpResponse response = future.get();
    Assert.assertNotNull(response);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    AuthScope authscope = credsProvider.getAuthScope();
    Assert.assertNotNull(authscope);
    Assert.assertEquals("test realm", authscope.getRealm());
}

3. TestClientAuthentication#testBasicAuthenticationFailure()

Project: httpasyncclient
File: TestClientAuthentication.java
@Test
public void testBasicAuthenticationFailure() throws Exception {
    TestCredentialsProvider credsProvider = new TestCredentialsProvider(new UsernamePasswordCredentials("test", "all-wrong"));
    this.httpclient.setCredentialsProvider(credsProvider);
    HttpGet httpget = new HttpGet("/");
    Future<HttpResponse> future = this.httpclient.execute(this.target, httpget, null);
    HttpResponse response = future.get();
    Assert.assertNotNull(response);
    Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
    AuthScope authscope = credsProvider.getAuthScope();
    Assert.assertNotNull(authscope);
    Assert.assertEquals("test realm", authscope.getRealm());
}

4. TestClientAuthentication#testBasicAuthenticationNoCreds()

Project: httpasyncclient
File: TestClientAuthentication.java
@Test
public void testBasicAuthenticationNoCreds() throws Exception {
    TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
    this.httpclient.setCredentialsProvider(credsProvider);
    HttpGet httpget = new HttpGet("/");
    Future<HttpResponse> future = this.httpclient.execute(this.target, httpget, null);
    HttpResponse response = future.get();
    Assert.assertNotNull(response);
    Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
    AuthScope authscope = credsProvider.getAuthScope();
    Assert.assertNotNull(authscope);
    Assert.assertEquals("test realm", authscope.getRealm());
}

5. LibRequestDirector#updateAuthState()

Project: YiBo
File: LibRequestDirector.java
private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) {
    if (!authState.isValid()) {
        return;
    }
    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }
    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName());
    if (DEBUG) {
        Logger.debug("Authentication scope: {}", authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (DEBUG) {
            if (creds != null) {
                Logger.debug("Found credentials");
            } else {
                Logger.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
            if (DEBUG) {
                Logger.debug("Authentication failed");
            }
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}

6. AsyncHttpClient#setBasicAuth()

Project: Libraries-for-Android-Developers
File: AsyncHttpClient.java
/**
     * Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as
     * setBasicAuth('username','password',AuthScope.ANY)
     *
     * @param username Basic Auth username
     * @param password Basic Auth password
     */
public void setBasicAuth(String username, String password) {
    AuthScope scope = AuthScope.ANY;
    setBasicAuth(username, password, scope);
}

7. DefaultAsyncRequestDirector#updateAuthState()

Project: httpasyncclient
File: DefaultAsyncRequestDirector.java
private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) {
    if (!authState.isValid()) {
        return;
    }
    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = this.connmgr.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }
    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName());
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication scope: " + authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (this.log.isDebugEnabled()) {
            if (creds != null) {
                this.log.debug("Found credentials");
            } else {
                this.log.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
            this.log.debug("Authentication failed");
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}

8. AsyncHttp#setBasicAuth()

Project: androidkit
File: AsyncHttp.java
/**
	 * Sets basic authentication for the request. Uses AuthScope.ANY. This is
	 * the same as setBasicAuth('username','password',AuthScope.ANY)
	 *
	 * @param user
	 * @param pass
	 */
public void setBasicAuth(String user, String pass) {
    AuthScope scope = AuthScope.ANY;
    setBasicAuth(user, pass, scope);
}