Java Code Examples for org.apache.http.auth.AuthState#setAuthScheme()
The following examples show how to use
org.apache.http.auth.AuthState#setAuthScheme() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebRealmServiceTest.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override 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 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 Credentials creds = credsProvider.getCredentials( authScope ); // If found, generate BasicScheme preemptively if( creds != null ) { authState.setAuthScheme( new BasicScheme() ); authState.setCredentials( creds ); } } }
Example 2
Source File: LibRequestDirector.java From YiBo with Apache License 2.0 | 6 votes |
private void processChallenges( final Map<String, Header> challenges, final AuthState authState, final AuthenticationHandler authHandler, final HttpResponse response, final HttpContext context) throws MalformedChallengeException, AuthenticationException { AuthScheme authScheme = authState.getAuthScheme(); if (authScheme == null) { // Authentication not attempted before authScheme = authHandler.selectScheme(challenges, response, context); authState.setAuthScheme(authScheme); } String id = authScheme.getSchemeName(); Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH)); if (challenge == null) { throw new AuthenticationException(id + " authorization challenge expected, but not found"); } authScheme.processChallenge(challenge); if (DEBUG) { Logger.debug("Authorization challenge processed"); } }
Example 3
Source File: HttpSender.java From cloudhopper-commons with Apache License 2.0 | 6 votes |
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { 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"); } authState.setAuthScheme(authScheme); authState.setCredentials(creds); } } }
Example 4
Source File: PreemptiveBasicAuthHttpRequestInterceptor.java From cloudhopper-commons with Apache License 2.0 | 6 votes |
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { // // get the authentication state for the request // AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); // // if no auth scheme avaialble yet, try to initialize it preemptively // if (authState.getAuthScheme() == null) { // check if credentials are set if (this.credentials == null) { throw new HttpException("No credentials for preemptive authentication"); } // add the credentials to the auth state authState.setAuthScheme(this.basicAuthScheme); authState.setCredentials(this.credentials); // HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); //CredentialsProvider credsProvider = (CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER); } }
Example 5
Source File: PreemtiveAuthorizationHttpRequestInterceptor.java From Mobike with Apache License 2.0 | 5 votes |
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); } } }
Example 6
Source File: PreemtiveAuthorizationHttpRequestInterceptor.java From android-project-wo2b with Apache License 2.0 | 5 votes |
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); } } }
Example 7
Source File: PreemtiveAuthorizationHttpRequestInterceptor.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
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); } } }
Example 8
Source File: PreemtiveAuthorizationHttpRequestInterceptor.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
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); } } }
Example 9
Source File: PreemtiveAuthorizationHttpRequestInterceptor.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
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); } } }
Example 10
Source File: PreemtiveAuthorizationHttpRequestInterceptor.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public void process(HttpRequest httprequest, HttpContext httpcontext) { AuthState authstate = (AuthState)httpcontext.getAttribute("http.auth.target-scope"); CredentialsProvider credentialsprovider = (CredentialsProvider)httpcontext.getAttribute("http.auth.credentials-provider"); HttpHost httphost = (HttpHost)httpcontext.getAttribute("http.target_host"); if (authstate.getAuthScheme() == null) { org.apache.http.auth.Credentials credentials = credentialsprovider.getCredentials(new AuthScope(httphost.getHostName(), httphost.getPort())); if (credentials != null) { authstate.setAuthScheme(new BasicScheme()); authstate.setCredentials(credentials); } } }
Example 11
Source File: c.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public void process(HttpRequest httprequest, HttpContext httpcontext) { AuthState authstate = (AuthState)httpcontext.getAttribute("http.auth.target-scope"); CredentialsProvider credentialsprovider = (CredentialsProvider)httpcontext.getAttribute("http.auth.credentials-provider"); HttpHost httphost = (HttpHost)httpcontext.getAttribute("http.target_host"); if (authstate.getAuthScheme() == null) { org.apache.http.auth.Credentials credentials = credentialsprovider.getCredentials(new AuthScope(httphost.getHostName(), httphost.getPort())); if (credentials != null) { authstate.setAuthScheme(new BasicScheme()); authstate.setCredentials(credentials); } } }
Example 12
Source File: RemoteSystemClient.java From ghwatch with Apache License 2.0 | 5 votes |
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); } } }
Example 13
Source File: HttpPostMain.java From cloudhopper-commons with Apache License 2.0 | 5 votes |
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { 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"); } authState.setAuthScheme(authScheme); authState.setCredentials(creds); } } }