private HttpClientContext convertHttpClientContext(Request request, Site site, Proxy proxy) { HttpClientContext httpContext = new HttpClientContext(); if (proxy != null && proxy.getUsername() != null) { AuthState authState = new AuthState(); authState.update(new BasicScheme(ChallengeState.PROXY), new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword())); httpContext.setAttribute(HttpClientContext.PROXY_AUTH_STATE, authState); } if (request.getCookies() != null && !request.getCookies().isEmpty()) { CookieStore cookieStore = new BasicCookieStore(); for (Map.Entry<String, String> cookieEntry : request.getCookies().entrySet()) { BasicClientCookie cookie1 = new BasicClientCookie(cookieEntry.getKey(), cookieEntry.getValue()); cookie1.setDomain(UrlUtils.removePort(UrlUtils.getDomain(request.getUrl()))); cookieStore.addCookie(cookie1); } httpContext.setCookieStore(cookieStore); } return httpContext; }
@SuppressWarnings("unchecked") private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); this.credentialsCharset = CharsetUtils.get(in.readUTF()); if (this.credentialsCharset == null) { this.credentialsCharset = Consts.ASCII; } this.challengeState = (ChallengeState) in.readObject(); }
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState proxyAuthState = clientContext.getProxyAuthState(); // If there's no auth scheme available yet, try to initialize it preemptively if (proxyAuthState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); RouteInfo route = clientContext.getHttpRoute(); if (route == null) { log.debug("No route found for {}", clientContext.getTargetHost()); return; } HttpHost proxyHost = route.getProxyHost(); if (proxyHost == null) { log.warn("No proxy host found in route {} for host {}", route, clientContext.getTargetHost()); return; } Credentials creds = credsProvider.getCredentials( new AuthScope(proxyHost.getHostName(), proxyHost.getPort())); if (creds == null) { log.info("No credentials found for proxy: " + proxyHost); return; } proxyAuthState.update(new BasicScheme(ChallengeState.PROXY), creds); } }
/** * Creates an instance of <tt>RFC2617Scheme</tt> with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public RFC2617SchemeHC4(final ChallengeState challengeState) { super(challengeState); this.params = new HashMap<String, String>(); this.credentialsCharset = Consts.ASCII; }
/** * Creates an instance of {@code RFC2617Scheme} with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public RFC2617Scheme(final ChallengeState challengeState) { super(challengeState); this.params = new HashMap<String, String>(); this.credentialsCharset = Consts.ASCII; }
/** * Creates an instance of <tt>RFC2617Scheme</tt> with the given challenge * state. * * @since 4.2 */ public RFC2617Scheme(final ChallengeState challengeState) { super(challengeState); this.params = new HashMap<String, String>(); }
/** * Creates an instance of <tt>DigestScheme</tt> with the given challenge * state. * * @since 4.2 */ public DigestScheme(final ChallengeState challengeState) { super(challengeState); this.complete = false; }
/** * Creates an instance of <tt>BasicScheme</tt> with the given challenge * state. * * @since 4.2 */ public BasicScheme(final ChallengeState challengeState) { super(challengeState); this.complete = false; }
/** * Creates an instance of <tt>AuthSchemeBase</tt> with the given challenge * state. * * @since 4.2 */ public AuthSchemeBase(final ChallengeState challengeState) { super(); this.challengeState = challengeState; }
/** * Returns <code>true</code> if authenticating against a proxy, <code>false</code> * otherwise. */ public boolean isProxy() { return this.challengeState != null && this.challengeState == ChallengeState.PROXY; }
/** * Returns {@link ChallengeState} value or <code>null</code> if unchallenged. * * @since 4.2 */ public ChallengeState getChallengeState() { return this.challengeState; }
/** * Creates an instance of <tt>BasicScheme</tt> with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public BasicSchemeHC4(final ChallengeState challengeState) { super(challengeState); }
/** * Creates an instance of <tt>DigestScheme</tt> with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public DigestSchemeHC4(final ChallengeState challengeState) { super(challengeState); }
/** * Creates an instance of <tt>AuthSchemeBase</tt> with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public AuthSchemeBaseHC4(final ChallengeState challengeState) { super(); this.challengeState = challengeState; }
/** * Creates an instance of {@code DigestScheme} with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public DigestScheme(final ChallengeState challengeState) { super(challengeState); }
/** * Creates an instance of {@code BasicScheme} with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public BasicScheme(final ChallengeState challengeState) { super(challengeState); }
/** * Creates an instance of {@code AuthSchemeBase} with the given challenge * state. * * @since 4.2 * * @deprecated (4.3) do not use. */ @Deprecated public AuthSchemeBase(final ChallengeState challengeState) { super(); this.challengeState = challengeState; }
/** * Returns {@code true} if authenticating against a proxy, {@code false} * otherwise. */ public boolean isProxy() { return this.challengeState != null && this.challengeState == ChallengeState.PROXY; }
/** * Returns {@link ChallengeState} value or {@code null} if unchallenged. * * @since 4.2 */ public ChallengeState getChallengeState() { return this.challengeState; }