org.apache.http.auth.AuthScheme Java Examples
The following examples show how to use
org.apache.http.auth.AuthScheme.
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: Http4Util.java From httpsig-java with The Unlicense | 6 votes |
public static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId) { if (client == null) { throw new NullPointerException("client"); } if (keychain == null) { throw new NullPointerException("keychain"); } client.getAuthSchemes().register(Constants.SCHEME, new AuthSchemeFactory() { public AuthScheme newInstance(HttpParams params) { return new Http4SignatureAuthScheme(); } }); Signer signer = new Signer(keychain, keyId); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new SignerCredentials(signer)); client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(Constants.SCHEME)); HttpClientParams.setAuthenticating(client.getParams(), true); }
Example #2
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 #3
Source File: WebAuthentication.java From fess with Apache License 2.0 | 6 votes |
private AuthScheme getAuthScheme() { final String scheme = getProtocolScheme(); if (Constants.BASIC.equals(scheme)) { return new BasicScheme(); } else if (Constants.DIGEST.equals(scheme)) { return new DigestScheme(); } else if (Constants.NTLM.equals(scheme)) { final Properties props = new Properties(); getWebConfig().getConfigParameterMap(ConfigName.CONFIG).entrySet().stream() .filter(e -> e.getKey().startsWith(Config.JCIFS_PREFIX)).forEach(e -> { props.setProperty(e.getKey(), e.getValue()); }); return new NTLMScheme(new JcifsEngine(props)); } else if (Constants.FORM.equals(scheme)) { final Map<String, String> parameterMap = ParameterUtil.parse(getParameters()); return new FormScheme(parameterMap); } return null; }
Example #4
Source File: PreemptiveAuth.java From jenkins-client-java with MIT License | 6 votes |
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); 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.update(authScheme, creds); } } }
Example #5
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 #6
Source File: UriStrategy.java From activemq-artemis 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(HttpClientContext.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(HttpClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.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.update(authScheme, creds); } } }
Example #7
Source File: PreemptiveAuthHttpRequestInterceptor.java From gerrit-rest-java-client with Apache License 2.0 | 6 votes |
@Override public void process(final HttpRequest request, final HttpContext context) { // never ever send credentials preemptively to a host which is not the configured Gerrit host if (!isForGerritHost(request)) { return; } AuthState authState = (AuthState) context.getAttribute(HttpClientContext.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); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(authData.getLogin(), authData.getPassword()); authState.update(authScheme, creds); } }
Example #8
Source File: PreemptiveAuth.java From verigreen with Apache License 2.0 | 6 votes |
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); Credentials creds; 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) { creds = credsProvider.getCredentials(new AuthScope( targetHost.getHostName(), targetHost.getPort())); if (creds == null) { throw new HttpException("No credentials for preemptive authentication"); } authState.update(authScheme, creds); } } }
Example #9
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); } } }
Example #10
Source File: BasicAuthCacheAlias.java From camel-quarkus with Apache License 2.0 | 5 votes |
@Substitute @Override public void put(final HttpHost host, final AuthScheme authScheme) { Args.notNull(host, "HTTP host"); if (authScheme == null) { return; } this.map.put(getKey(host), authScheme); }
Example #11
Source File: Substitute_RestClient.java From quarkus with Apache License 2.0 | 5 votes |
@Override public void put(final HttpHost host, final AuthScheme authScheme) { Args.notNull(host, "HTTP host"); if (authScheme == null) { return; } this.map.put(getKey(host), authScheme); }
Example #12
Source File: HttpHelper.java From sputnik with Apache License 2.0 | 5 votes |
@NotNull public HttpClientContext buildClientContext(@NotNull HttpHost httpHost, @NotNull AuthScheme authScheme) { AuthCache basicAuthCache = new BasicAuthCache(); basicAuthCache.put(httpHost, authScheme); HttpClientContext httpClientContext = HttpClientContext.create(); httpClientContext.setAuthCache(basicAuthCache); httpClientContext.setTargetHost(httpHost); return httpClientContext; }
Example #13
Source File: CallbackProxyAuthenticationStrategy.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public void authSucceeded(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); final Credentials credentials = clientContext.getAttribute(PROXY_CREDENTIALS_INPUT_ID, Credentials.class); if(null != credentials) { clientContext.removeAttribute(PROXY_CREDENTIALS_INPUT_ID); if(log.isInfoEnabled()) { log.info(String.format("Save passphrase for proxy %s", authhost)); } keychain.addCredentials(authhost.toURI(), credentials.getUsername(), credentials.getPassword()); } super.authSucceeded(authhost, authScheme, context); }
Example #14
Source File: JolokiaClientFactory.java From hawkular-agent with Apache License 2.0 | 4 votes |
PreemptiveAuthInterceptor(AuthScheme pScheme) { authScheme = pScheme; }
Example #15
Source File: PreemptiveAuth.java From lucene-solr with Apache License 2.0 | 4 votes |
public PreemptiveAuth(AuthScheme authScheme) { this.authScheme = authScheme; }
Example #16
Source File: KnoxSpnegoAuthSchemeFactory.java From knox with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") @Override public AuthScheme newInstance(final HttpParams params ) { return new KnoxSpnegoAuthScheme( isStripPort() ); }
Example #17
Source File: KerberosKeytabSPNegoAuthSchemeProvider.java From nifi with Apache License 2.0 | 4 votes |
public AuthScheme create(HttpContext context) { return new KerberosKeytabSPNegoScheme(); }
Example #18
Source File: LibRequestDirector.java From YiBo with Apache License 2.0 | 4 votes |
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); }
Example #19
Source File: WebServiceNtlmSender.java From iaf with Apache License 2.0 | 4 votes |
public AuthScheme newInstance(final HttpParams params) { return new NTLMScheme(new JCIFSEngine()); }
Example #20
Source File: KeycloakSPNegoSchemeFactory.java From keycloak with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("deprecation") public AuthScheme newInstance(HttpParams params) { return new KeycloakSPNegoScheme(isStripPort(), isUseCanonicalHostname()); }
Example #21
Source File: NTLMSchemeFactory.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public AuthScheme newInstance(HttpParams params) { return new NTLMScheme(new JCIFSEngine()); }
Example #22
Source File: NTLMSchemeFactory.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public AuthScheme newInstance(HttpParams params) { return new NTLMScheme(new JCIFSEngine()); }
Example #23
Source File: BackportWindowsNegotiateSchemeFactory.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public AuthScheme create(final HttpContext context) { return new BackportWindowsNegotiateScheme(AuthSchemes.SPNEGO, servicePrincipalName); }
Example #24
Source File: CallbackProxyAuthenticationStrategy.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public void authFailed(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { keychain.deleteCredentials(authhost.getHostName()); super.authFailed(authhost, authScheme, context); }
Example #25
Source File: BackportWindowsNTLMSchemeFactory.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public AuthScheme create(final HttpContext context) { return new BackportWindowsNegotiateScheme(AuthSchemes.NTLM, servicePrincipalName); }
Example #26
Source File: SPNegoSchemeFactory.java From ats-framework with Apache License 2.0 | 4 votes |
public AuthScheme create( final HttpContext context ) { return new SPNegoScheme(gssClient, servicePrincipalName, servicePrincipalOid); }
Example #27
Source File: SPNegoSchemeFactory.java From ats-framework with Apache License 2.0 | 4 votes |
public AuthScheme newInstance( final HttpParams params ) { return new SPNegoScheme(gssClient, servicePrincipalName, servicePrincipalOid); }
Example #28
Source File: DefaultSpringCloudConfigClientGateway.java From quarkus with Apache License 2.0 | 4 votes |
@Override public AuthScheme get(HttpHost host) { return map.get(host); }
Example #29
Source File: DefaultSpringCloudConfigClientGateway.java From quarkus with Apache License 2.0 | 4 votes |
@Override public void put(HttpHost host, AuthScheme authScheme) { map.put(host, authScheme); }
Example #30
Source File: Substitute_RestClient.java From quarkus with Apache License 2.0 | 4 votes |
@Override public AuthScheme get(final HttpHost host) { Args.notNull(host, "HTTP host"); return this.map.get(getKey(host)); }