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
                            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());
                                authState.setAuthScheme(new BasicScheme());
                                authState.setCredentials(creds);
                            } 
                        } 
                    }; 
 
                    dhc.addRequestInterceptor(preemptiveAuth, 0);
                } 
            } else { 
                Log.w(TDDatabase.TAG,
                        "Unable to parse user info, not setting credentials"); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
                                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());
                                    authState.setAuthScheme(new BasicScheme());
                                    authState.setCredentials(creds);
                                } 
                            } 
                        }; 
 
                        dhc.addRequestInterceptor(preemptiveAuth, 0);
                    } 
                } 
                else { 
                    Log.w(CBLDatabase.TAG, "Unable to parse user info, not setting credentials");
                } 
            } 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
                                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());
                                    authState.setAuthScheme(new BasicScheme());
                                    authState.setCredentials(creds);
                                } 
                            } 
                        }; 
 
                        dhc.addRequestInterceptor(preemptiveAuth, 0);
                    } 
                } else { 
                    Log.w(CBLDatabase.TAG, "ChangeTracker Unable to parse user info, not setting credentials");
                } 
            } 
 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
                                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());
                                    authState.setAuthScheme(new BasicScheme());
                                    authState.setCredentials(creds);
                                } 
                            } 
                        }; 
 
                        dhc.addRequestInterceptor(preemptiveAuth, 0);
                    } 
                } 
                else { 
                    Log.w(TDDatabase.TAG, "Unable to parse user info, not setting credentials");
                } 
            } 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
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
                            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());
                                authState.setAuthScheme(new BasicScheme());
                                authState.setCredentials(creds);
                            } 
                        } 
                    }; 
 
                    dhc.addRequestInterceptor(preemptiveAuth, 0);
                } 
            } else { 
                Log.w(CBLDatabase.TAG,
                        "CBLRemoteRequest Unable to parse user info, not setting credentials"); 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
 
            AuthState authState = (AuthState) context.getAttribute(
                ClientContext.TARGET_AUTH_STATE );
 
            // If no auth scheme avaialble 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 ) {
                    Credentials creds = credsProvider.getCredentials(
                        new AuthScope(
                        targetHost.getHostName(),
                        targetHost.getPort() ) );
                    if( creds == null ) {
                        throw new HttpException( "No credentials for preemptive authentication" );
                    } 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
		{ 
			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); 
				} 
			} 
		} 
	}; 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
This code example shows how to use the following methods:getAuthScheme
             
            AuthState authState = (AuthState) context.getAttribute(
                    ClientContext.TARGET_AUTH_STATE);
             
            // If no auth scheme avaialble 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) {
                    Credentials creds = credsProvider.getCredentials(
                            new AuthScope(
                                    targetHost.getHostName(), 
                                    targetHost.getPort()));
                    if (creds == null) {
                        throw new HttpException("No credentials for preemptive authentication");
                    } 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
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, setAuthScheme, setCredentials
This code example shows how to use the following methods:getAuthScheme
             
            AuthState authState = (AuthState) context.getAttribute(
                    ClientContext.TARGET_AUTH_STATE);
             
            // If no auth scheme avaialble 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) {
                    Credentials creds = credsProvider.getCredentials(
                            new AuthScope(
                                    targetHost.getHostName(), 
                                    targetHost.getPort()));
                    if (creds == null) {
                        throw new HttpException("No credentials for preemptive authentication");
                    } 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
This code example shows how to use the following methods:getAuthScheme
					.getAttribute(ClientContext.CREDS_PROVIDER); 
			HttpHost targetHost = (HttpHost) context 
					.getAttribute(ExecutionContext.HTTP_TARGET_HOST); 
 
			// If not auth scheme has been initialized yet 
			if (authState.getAuthScheme() == null) { 
				AuthScope authScope = new AuthScope(targetHost.getHostName(), 
						targetHost.getPort()); 
				// Obtain credentials matching the target host 
				org.apache.http.auth.Credentials creds = credsProvider 
						.getCredentials(authScope); 
				// If found, generate BasicScheme preemptively 
				if (creds != null) { 
					authState.setAuthScheme(new BasicScheme()); 
					authState.setCredentials(creds); 
				} 
			} 
		} 
 
	}; 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
    @Override 
    public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
        final AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
 
        // If no auth scheme avaialble yet, try to initialize it preemptively 
        if (authState.getAuthScheme() == null) {
            final AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
            final CredentialsProvider credsProvider =
                (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
            final HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (authScheme != null) {
                final Credentials creds =
                    credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
                if (creds == null) {
                    throw new HttpException("No credentials for preemptive authentication.");
                } 
                authState.setAuthScheme(authScheme);
                authState.setCredentials(creds);
            } 
        } 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
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); 
				} 
			} 
		} 
	}; 
 
	/* 
	 * sends the request and retrieve the response 
	 *  
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthScheme
This code example shows how to use the following methods:
 
    @Before 
    public void setUp() throws Exception { 
        this.authScheme = Mockito.mock(ContextAwareAuthScheme.class);
        this.credentials = Mockito.mock(Credentials.class);
        this.authState = new AuthState();
        this.context = new BasicHttpContext();
        this.context.setAttribute("test-auth-state", this.authState);
        this.interceptor = new TestRequestAuthentication();
    } 
 
    @Test 
    public void testAuthFailureState() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        this.authState.setState(AuthProtocolState.FAILURE);
        this.authState.update(this.authScheme, this.credentials);
 
        this.interceptor.process(request, this.context);
 
        Assert.assertFalse(request.containsHeader(AUTH.WWW_AUTH_RESP));
4
CodeRank
Experience pair programming with AI  Get Codota for Java
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());
                                authState.setAuthScheme(new BasicScheme());
                                authState.setCredentials(creds);
                            } 
                        } 
                    }; 
 
                    dhc.addRequestInterceptor(preemptiveAuth, 0);
                } 
            } else { 
                Log.w(TDDatabase.TAG,
                        "Unable to parse user info, not setting credentials"); 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
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 not auth scheme has been initialized yet 
                if (authState.getAuthScheme() == null) { 
                    AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); 
                    org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope); 
                    if (creds != null) { 
                        authState.setAuthScheme(new BasicScheme()); 
                        authState.setCredentials(creds); 
                    } 
                } 
            } 
        }; 
    } 
     
    private static class StateHolder { 
        private String mHtml;
        private boolean mIsRunningTask;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
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 not auth scheme has been initialized yet 
                if (authState.getAuthScheme() == null) { 
                    AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); 
                    org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope); 
                    if (creds != null) { 
                        authState.setAuthScheme(new BasicScheme()); 
                        authState.setCredentials(creds); 
                    } 
                } 
            } 
        }; 
    } 
     
    private static class StateHolder { 
        private String mHtml;
        private boolean mIsRunningTask;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        this.authscheme2 = new BasicScheme();
 
        this.credProvider.setCredentials(this.authscope1, this.creds1);
        this.credProvider.setCredentials(this.authscope2, this.creds2);
 
        this.targetState = new AuthState();
        this.proxyState = new AuthState();
    } 
 
    @Test(expected=IllegalArgumentException.class) 
    public void testRequestParameterCheck() throws Exception { 
        HttpContext context = new BasicHttpContext();
        HttpRequestInterceptor interceptor = new RequestAuthCache();
        interceptor.process(null, context);
    } 
 
    @Test(expected=IllegalArgumentException.class) 
    public void testContextParameterCheck() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        HttpRequestInterceptor interceptor = new RequestAuthCache();
3
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Android AuthState Methods: