Android AuthState - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AuthState class.

This code example shows how to use the following methods:getAuthScheme
This code example shows how to use the following methods:update
        BasicScheme authscheme = new BasicScheme();
        Credentials creds = new UsernamePasswordCredentials("user", "secret");
        BasicHeader challenge = new BasicHeader(AUTH.WWW_AUTH, "BASIC realm=auth-realm");
        authscheme.processChallenge(challenge);
 
        AuthState authstate = new AuthState();
        authstate.update(authscheme, creds);
 
        context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
 
        HttpRequestInterceptor interceptor = new RequestTargetAuthentication();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(AUTH.WWW_AUTH_RESP);
        Assert.assertNotNull(header);
        Assert.assertEquals("Basic dXNlcjpzZWNyZXQ=", header.getValue());
    } 
 
    @Test 
    public void testNoTargetAuthForConnectRequests() throws Exception { 
        HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");
5
CodeRank
This code example shows how to use the following methods:getAuthScheme
 
    public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
      AuthState authState = (AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
      CredentialsProvider credsProvider = (CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
      HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
      if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
          authState.setAuthScheme(new BasicScheme());
          authState.setCredentials(creds);
        } 
      } 
    } 
  } 
 
  /** 
   * @author Patrick Woodworth 
   */ 
  static class WeaveHostnameVerifier extends AbstractVerifier {
3
CodeRank
This code example shows how to use the following methods:getAuthScheme
			CredentialsProvider credsProvider = (CredentialsProvider) context 
					.getAttribute(ClientContext.CREDS_PROVIDER); 
			HttpHost targetHost = (HttpHost) context 
					.getAttribute(ExecutionContext.HTTP_TARGET_HOST); 
 
			if (authState.getAuthScheme() == null) { 
				AuthScope authScope = new AuthScope(targetHost.getHostName(), 
						targetHost.getPort()); 
				Credentials creds = credsProvider.getCredentials(authScope); 
				if (creds != null) { 
					authState.setAuthScheme(new BasicScheme()); 
					authState.setCredentials(creds); 
				} 
			} 
		} 
	}; 
 
	/** 
	 * Setup Credentials for HTTP Basic Auth 给HTTP基本认证设置证书 
	 *  
2
CodeRank
This code example shows how to use the following methods:getAuthScheme
			public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
				AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
 
				// If no auth scheme available yet, try to initialize it 
				// preemptively 
				if (authState.getAuthScheme() == null) {
					AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
					CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
					HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
					if (authScheme != null) {
						AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
						Credentials creds = credsProvider.getCredentials(authScope);
						if (creds == null) {
							throw new HttpException("No credentials for preemptive authentication");
						} 
						authState.setAuthScheme(authScheme);
						authState.setCredentials(creds);
					} 
				} 
			} 
3
CodeRank
This code example shows how to use the following methods:getAuthScheme
                    .getAttribute(ClientContext.CREDS_PROVIDER); 
            final HttpHost targetHost = (HttpHost) context 
                    .getAttribute(ExecutionContext.HTTP_TARGET_HOST); 
 
            // If not auth scheme has been initialized yet 
            if (authState.getAuthScheme() == null) { 
                final AuthScope authScope = new AuthScope(targetHost.getHostName(), 
                        targetHost.getPort()); 
                // Obtain credentials matching the target host 
                final Credentials creds = credsProvider.getCredentials(authScope); 
                // If found, generate BasicScheme preemptively 
                if (creds != null) { 
                    if (creds.getUserPrincipal() != null) { 
                        if (DEBUG) { 
                            Log.d("NetworkClient", "Pre-emptively authenticating as: " 
                                    + creds.getUserPrincipal().getName()); 
                        } 
                    } 
                    authState.setAuthScheme(new BasicScheme()); 
                    authState.setCredentials(creds); 
3
CodeRank
This code example shows how to use the following methods:getAuthScheme
This code example shows how to use the following methods:getAuthScheme
This code example shows how to use the following methods:getAuthScheme
This code example shows how to use the following methods:getAuthScheme
See Code Examples for Android AuthState Methods: