/** * Test that the given url is "compatible" with the * session specified dataset. Wrapper around * HTTPAuthUtil.httphostCompatible(). * * @param other to test for compatibility against this method's * @return true if compatible, false otherwise. */ protected boolean sessionCompatible(AuthScope other) { return HTTPAuthUtil.authscopeCompatible(session.getAuthScope(), other); }
public HTTPSession clearCredentialsCache(AuthScope template) { if(this.sessioncache != null) { HttpHost h = HTTPAuthUtil.authscopeToHost(template); this.sessioncache.remove(h); } return this; }
HTTPSession(HttpHost httphost) throws HTTPException { init(HTTPAuthUtil.hostToAuthScope(httphost), null); }
AuthScope bestMatch = HTTPAuthUtil.bestmatch(scope, localcreds.keySet()); CredentialsProvider cp = null; if(bestMatch != null) { cp = localcreds.get(bestMatch); } else { bestMatch = HTTPAuthUtil.bestmatch(scope, globalcredfactories.keySet()); if(bestMatch != null) { HTTPProviderFactory factory = globalcredfactories.get(bestMatch); if(user != null && (httpproxy != null || httpsproxy != null)) { if(httpproxy != null) proxyscope = HTTPAuthUtil.hostToAuthScope(httpproxy); else //httpsproxy != null proxyscope = HTTPAuthUtil.hostToAuthScope(httpsproxy); proxycreds = new UsernamePasswordCredentials(user, pwd);
setheaders(rb, this.headers); this.lastrequest = buildRequest(rb, this.settings); AuthScope methodscope = HTTPAuthUtil.uriToAuthScope(this.methodurl); AuthScope target = HTTPAuthUtil.authscopeUpgrade(session.getSessionScope(), methodscope); HttpHost targethost = HTTPAuthUtil.authscopeToHost(target); HttpClientBuilder cb = HttpClients.custom(); configClient(cb, this.settings);
HTTPSession(String uri) throws HTTPException { init(HTTPAuthUtil.uriToAuthScope(uri), uri); }
public Credentials getCredentials(AuthScope scope) { Credentials credentials = this.creds.get(scope); if(credentials == null) { AuthScope bestMatch = HTTPAuthUtil.bestmatch(scope,this.creds.keySet()); if(bestMatch != null) credentials = this.creds.get(bestMatch); } if(credentials != null) return credentials; String up = login(this.dfaltuser, this.dfaltpwd, scope); if(up == null) throw new IllegalStateException(); String[] pieces = up.split("[:]"); UsernamePasswordCredentials upc = null; if(pieces.length == 2) { if(DEBUG) { System.out.println("user= (" + pieces[0] + ")"); System.out.println("password= (" + pieces[1] + ")"); } // Is this really necessary? upc = new UsernamePasswordCredentials(pieces[0], pieces[1]); } else upc = null; return upc; }
protected void init(AuthScope scope, String actualurl) throws HTTPException { assert (scope != null); if(actualurl != null) this.sessionURI = actualurl; else this.sessionURI = HTTPAuthUtil.authscopeToURI(scope).toString(); this.scope = scope; this.scopeURI = HTTPAuthUtil.authscopeToURI(scope); this.cachevalid = false; // Force build on first use this.sessioncontext.setCookieStore(new BasicCookieStore()); this.sessioncache = new BasicAuthCache(); this.sessioncontext.setAuthCache(sessioncache); }
@Deprecated static public void setGlobalCredentials(String url, Credentials creds) throws HTTPException { assert (url != null && creds != null); AuthScope scope = HTTPAuthUtil.uriToAuthScope(url); CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(scope, creds); setGlobalCredentialsProvider(provider, scope); }
@Deprecated public HTTPSession setCredentialsProvider(String url, CredentialsProvider provider) throws HTTPException { assert (url != null && provider != null); AuthScope scope = HTTPAuthUtil.uriToAuthScope(url); setCredentialsProvider(provider, scope); return this; }
@Deprecated protected boolean sessionCompatible(HttpHost otherhost) { AuthScope other = HTTPAuthUtil.hostToAuthScope(otherhost); return sessionCompatible(other); }
/** * Given a session url AuthScope and a Method url AuthScope, * return a new AuthScope that is the upgrade/merge of the other two. * Here, upgrade changes the scheme (only) to move http -> https. * Assumes authscopeCompatible() is true. * * @param ss Session authScope * @param ms Method authScope * @return upgraded AuthScope. */ static AuthScope authscopeUpgrade(AuthScope ss, AuthScope ms) { assert (HTTPAuthUtil.authscopeCompatible(ss, ms)); String sss = ss.getScheme().toLowerCase(); String mss = ms.getScheme().toLowerCase(); String upgrade = sss; if(sss.startsWith("http") && mss.startsWith("http")) { if(sss.equals("https") || mss.equals("https")) upgrade = "https"; } AuthScope host = new AuthScope(ss.getHost(), ss.getPort(), AuthScope.ANY_REALM, upgrade); return host; }
protected boolean sessionCompatible(URI otheruri) { AuthScope other = HTTPAuthUtil.uriToAuthScope(otheruri); return sessionCompatible(other); }
@Deprecated static public void setGlobalCredentialsProvider(String url, CredentialsProvider provider) throws HTTPException { assert (url != null && provider != null); AuthScope scope = HTTPAuthUtil.uriToAuthScope(url); setGlobalCredentialsProvider(provider, scope); }
@Deprecated public HTTPSession setCredentials(String url, Credentials creds) throws HTTPException { assert (creds != null); AuthScope scope = HTTPAuthUtil.uriToAuthScope(url); setCredentials(creds, scope); return this; }
static AuthScope uriToAuthScope(String surl) throws HTTPException { try { URI uri = HTTPUtil.parseToURI(surl); return uriToAuthScope(uri); } catch (URISyntaxException e) { throw new HTTPException(e); } }