@Override public Credential authenticate( Proxy proxy, URL url, List<Challenge> challenges) throws IOException { for (Challenge challenge : challenges) { if (!"Basic".equalsIgnoreCase(challenge.getScheme())) { continue; } PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(), getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER); if (auth != null) { return Credential.basic(auth.getUserName(), new String(auth.getPassword())); } } return null; }
@Override public Credential authenticateProxy( Proxy proxy, URL url, List<Challenge> challenges) throws IOException { for (Challenge challenge : challenges) { if (!"Basic".equalsIgnoreCase(challenge.getScheme())) { continue; } InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); PasswordAuthentication auth = Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.PROXY); if (auth != null) { return Credential.basic(auth.getUserName(), new String(auth.getPassword())); } } return null; }