private static PasswordAuthentication privilegedRequestPasswordAuthentication( final String host, final InetAddress addr, final int port, final String protocol, final String prompt, final String scheme, final URL url, final RequestorType authType) { return java.security.AccessController.doPrivileged( new java.security.PrivilegedAction<PasswordAuthentication>() { public PasswordAuthentication run() { if (logger.isLoggable(PlatformLogger.Level.FINEST)) { logger.finest("Requesting Authentication: host =" + host + " url = " + url); } PasswordAuthentication pass = Authenticator.requestPasswordAuthentication( host, addr, port, protocol, prompt, scheme, url, authType); if (logger.isLoggable(PlatformLogger.Level.FINEST)) { logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null")); } return pass; } }); }
/** * Constructor an un-schemed object for site access. */ public HttpCallerInfo(URL url) { this.url= url; prompt = ""; host = url.getHost(); int p = url.getPort(); if (p == -1) { port = url.getDefaultPort(); } else { port = p; } InetAddress ia; try { ia = InetAddress.getByName(url.getHost()); } catch (Exception e) { ia = null; } addr = ia; protocol = url.getProtocol(); authType = RequestorType.SERVER; scheme = ""; }
public Request authenticate(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.httpUrl(); int size = challenges.size(); for (int i = 0; i < size; i++) { Challenge challenge = (Challenge) challenges.get(i); if ("Basic".equalsIgnoreCase(challenge.getScheme())) { PasswordAuthentication auth = java.net.Authenticator .requestPasswordAuthentication(url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(), challenge.getRealm(), challenge .getScheme(), url.url(), RequestorType.SERVER); if (auth != null) { return request.newBuilder().header("Authorization", Credentials.basic(auth .getUserName(), new String(auth.getPassword()))).build(); } } } return null; }
public Request authenticateProxy(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.httpUrl(); int size = challenges.size(); for (int i = 0; i < size; i++) { Challenge challenge = (Challenge) challenges.get(i); if ("Basic".equalsIgnoreCase(challenge.getScheme())) { InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); PasswordAuthentication auth = java.net.Authenticator .requestPasswordAuthentication(proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url .scheme(), challenge.getRealm(), challenge.getScheme(), url.url(), RequestorType.PROXY); if (auth != null) { return request.newBuilder().header("Proxy-Authorization", Credentials.basic (auth.getUserName(), new String(auth.getPassword()))).build(); } } } return null; }
/** * Constructor an un-schemed object for site access. */ public HttpCallerInfo(URL url, Authenticator a) { this.url= url; prompt = ""; host = url.getHost(); int p = url.getPort(); if (p == -1) { port = url.getDefaultPort(); } else { port = p; } InetAddress ia; try { ia = InetAddress.getByName(url.getHost()); } catch (Exception e) { ia = null; } addr = ia; protocol = url.getProtocol(); authType = RequestorType.SERVER; scheme = ""; authenticator = a; }
/** * privileged request password authentication. */ private static PasswordAuthentication privilegedRequestPasswordAuthentication(final String host, final InetAddress addr, final int port, final String protocol, final String prompt, final String scheme, final URL url, final RequestorType authType) { return java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<PasswordAuthentication>() { @Override public PasswordAuthentication run() { return Authenticator.requestPasswordAuthentication( host, addr, port, protocol, prompt, scheme, url, authType); } }); }
private static PasswordAuthentication privilegedRequestPasswordAuthentication( final String host, final InetAddress addr, final int port, final String protocol, final String prompt, final String scheme, final URL url, final RequestorType authType) { return java.security.AccessController.doPrivileged( new java.security.PrivilegedAction<>() { public PasswordAuthentication run() { if (logger.isLoggable(PlatformLogger.Level.FINEST)) { logger.finest("Requesting Authentication: host =" + host + " url = " + url); } PasswordAuthentication pass = Authenticator.requestPasswordAuthentication( host, addr, port, protocol, prompt, scheme, url, authType); if (logger.isLoggable(PlatformLogger.Level.FINEST)) { logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null")); } return pass; } }); }
public final Request authenticate(Proxy paramProxy, Response paramResponse) throws IOException { List localList = paramResponse.challenges(); Request localRequest = paramResponse.request; URL localURL = localRequest.url(); int i = 0; int j = localList.size(); while (i < j) { Challenge localChallenge = (Challenge)localList.get(i); if ("Basic".equalsIgnoreCase(localChallenge.scheme)) { PasswordAuthentication localPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(localURL.getHost(), getConnectToInetAddress(paramProxy, localURL), localURL.getPort(), localURL.getProtocol(), localChallenge.realm, localChallenge.scheme, localURL, Authenticator.RequestorType.SERVER); if (localPasswordAuthentication != null) { String str = Credentials.basic(localPasswordAuthentication.getUserName(), new String(localPasswordAuthentication.getPassword())); return localRequest.newBuilder().header("Authorization", str).build(); } } i++; } return null; }
public final Request authenticateProxy(Proxy paramProxy, Response paramResponse) throws IOException { List localList = paramResponse.challenges(); Request localRequest = paramResponse.request; URL localURL = localRequest.url(); int i = 0; int j = localList.size(); while (i < j) { Challenge localChallenge = (Challenge)localList.get(i); if ("Basic".equalsIgnoreCase(localChallenge.scheme)) { InetSocketAddress localInetSocketAddress = (InetSocketAddress)paramProxy.address(); PasswordAuthentication localPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(localInetSocketAddress.getHostName(), getConnectToInetAddress(paramProxy, localURL), localInetSocketAddress.getPort(), localURL.getProtocol(), localChallenge.realm, localChallenge.scheme, localURL, Authenticator.RequestorType.PROXY); if (localPasswordAuthentication != null) { String str = Credentials.basic(localPasswordAuthentication.getUserName(), new String(localPasswordAuthentication.getPassword())); return localRequest.newBuilder().header("Proxy-Authorization", str).build(); } } i++; } return null; }
private static PasswordAuthentication privilegedRequestPasswordAuthentication( final String host, final InetAddress addr, final int port, final String protocol, final String prompt, final String scheme, final URL url, final RequestorType authType) { return java.security.AccessController.doPrivileged( new java.security.PrivilegedAction<PasswordAuthentication>() { public PasswordAuthentication run() { if (logger.isLoggable(PlatformLogger.FINEST)) { logger.finest("Requesting Authentication: host =" + host + " url = " + url); } PasswordAuthentication pass = Authenticator.requestPasswordAuthentication( host, addr, port, protocol, prompt, scheme, url, authType); if (logger.isLoggable(PlatformLogger.FINEST)) { logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null")); } return pass; } }); }
@Override public Request authenticate(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); URL url = request.url(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.getScheme())) continue; PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication( url.getHost(), getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url, RequestorType.SERVER); if (auth == null) continue; String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword())); return request.newBuilder() .header("Authorization", credential) .build(); } return null; }
@Override public Request authenticateProxy(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); URL url = request.url(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.getScheme())) continue; InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url, RequestorType.PROXY); if (auth == null) continue; String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword())); return request.newBuilder() .header("Proxy-Authorization", credential) .build(); } return null; }
private static PasswordAuthentication privilegedRequestPasswordAuthentication( final String host, final InetAddress addr, final int port, final String protocol, final String prompt, final String scheme, final URL url, final RequestorType authType) { return java.security.AccessController.doPrivileged( new java.security.PrivilegedAction<PasswordAuthentication>() { public PasswordAuthentication run() { return Authenticator.requestPasswordAuthentication( host, addr, port, protocol, prompt, scheme, url, authType); } }); }
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url(); boolean proxyAuthorization = response.code() == 407; Proxy proxy = route.proxy(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue; PasswordAuthentication auth; if (proxyAuthorization) { InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); auth = java.net.Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.scheme(), challenge.realm(), challenge.scheme(), url.url(), RequestorType.PROXY); } else { auth = java.net.Authenticator.requestPasswordAuthentication( url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(), challenge.realm(), challenge.scheme(), url.url(), RequestorType.SERVER); } if (auth != null) { String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword())); return request.newBuilder() .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential) .build(); } } return null; // No challenges were satisfied! }
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url(); boolean proxyAuthorization = response.code() == 407; Proxy proxy = route.proxy(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue; PasswordAuthentication auth; if (proxyAuthorization) { InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); auth = java.net.Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.scheme(), challenge.realm(), challenge.scheme(), url.url(), RequestorType.PROXY); } else { auth = java.net.Authenticator.requestPasswordAuthentication( url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(), challenge.realm(), challenge.scheme(), url.url(), RequestorType.SERVER); } if (auth != null) { String credential = Credentials.basic( auth.getUserName(), new String(auth.getPassword()), challenge.charset()); return request.newBuilder() .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential) .build(); } } return null; // No challenges were satisfied! }
/** * Constructor used for both WWW and proxy entries. * @param hci a schemed object. */ public NegotiateAuthentication(HttpCallerInfo hci) { super(RequestorType.PROXY==hci.authType ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION, hci.scheme.equalsIgnoreCase("Negotiate") ? NEGOTIATE : KERBEROS, hci.url, ""); this.hci = hci; }
/** * Constructor an un-schemed object for proxy access. */ public HttpCallerInfo(URL url, String host, int port) { this.url= url; this.host = host; this.port = port; prompt = ""; addr = null; protocol = url.getProtocol(); authType = RequestorType.PROXY; scheme = ""; }
@Override protected PasswordAuthentication getPasswordAuthentication() { //If user sets proxy user and passwd and the RequestType is from proxy server then create // PasswordAuthentication using proxyUser and proxyPasswd; if ((getRequestorType() == RequestorType.PROXY) && proxyUser != null && proxyPasswd != null) { return new PasswordAuthentication(proxyUser, proxyPasswd.toCharArray()); } for (AuthInfo auth : authInfo) { if (auth.matchingHost(getRequestingURL())) { return new PasswordAuthentication(auth.getUser(), auth.getPassword().toCharArray()); } } return null; }