auth.getUserName(), new String(auth.getPassword()), challenge.charset()); return request.newBuilder() .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential)
auth.getUserName(), new String(auth.getPassword()), challenge.charset()); return request.newBuilder() .header(proxyAuthorization ? "Proxy-Authorization" : "Authorization", credential)
@Test public void configure_http_proxy_credentials() { DefaultHttpDownloader.AuthenticatorFacade system = mock(DefaultHttpDownloader.AuthenticatorFacade.class); MapSettings settings = new MapSettings(); settings.setProperty("https.proxyHost", "1.2.3.4"); settings.setProperty("http.proxyUser", "the_login"); settings.setProperty("http.proxyPassword", "the_passwd"); new DefaultHttpDownloader.BaseHttpDownloader(system, settings.asConfig(), null); verify(system).setDefaultAuthenticator(argThat(authenticator -> { DefaultHttpDownloader.ProxyAuthenticator a = (DefaultHttpDownloader.ProxyAuthenticator) authenticator; PasswordAuthentication authentication = a.getPasswordAuthentication(); return authentication.getUserName().equals("the_login") && new String(authentication.getPassword()).equals("the_passwd"); })); }
/** {@inheritDoc} */ @Override protected final PasswordAuthentication getPasswordAuthentication() { final String host = getRequestingHost(); final int port = getRequestingPort(); for (CachedAuthentication ca : cached) { if (ca.host.equals(host) && ca.port == port) return ca.toPasswordAuthentication(); } PasswordAuthentication pa = promptPasswordAuthentication(); if (pa != null) { CachedAuthentication ca = new CachedAuthentication(host, port, pa .getUserName(), new String(pa.getPassword())); add(ca); return ca.toPasswordAuthentication(); } return null; }
public static String encodeAuthorizationHeader(String scheme, PasswordAuthentication value) { if(value == null){ return null; }else if("basic".equalsIgnoreCase(scheme)){ // https://tools.ietf.org/html/rfc7617 char[] pwd = value.getPassword(); String encodedBytes = Base64.getEncoder().encodeToString((value.getUserName() + ":" + new String(pwd)).getBytes()); Arrays.fill(pwd, ' '); return "Basic " + encodedBytes; } return null; }
@Override public boolean authenticate(String username, String password) { return passwordAuthentication.getUserName().equals(username) && Arrays.equals(passwordAuthentication.getPassword(), password.toCharArray()); } }
public static ChallengeResponse create(PasswordAuthentication creds, ChallengeHandler nextChallengeHandler) { String unencoded = String.format("%s:%s", creds.getUserName(), new String(creds.getPassword())); byte[] encoded = Base64.encode(unencoded.getBytes(US_ASCII)); String response = String.format("Application Basic %s", new String(encoded, US_ASCII)); Arrays.fill(creds.getPassword(), (char) 0); return new ChallengeResponse(response.toCharArray(), nextChallengeHandler); } }
public static ChallengeResponse create(PasswordAuthentication creds, ChallengeHandler nextChallengeHandler) { String unencoded = String.format("%s:%s", creds.getUserName(), new String(creds.getPassword())); String response = String.format("Basic %s", Base64Util.encode(WrappedByteBuffer.wrap(unencoded.getBytes()))); Arrays.fill(creds.getPassword(), (char) 0); return new ChallengeResponse(response.toCharArray(), nextChallengeHandler); } }
public static ChallengeResponse create(PasswordAuthentication creds, ChallengeHandler nextChallengeHandler) { String unencoded = String.format("%s:%s", creds.getUserName(), new String(creds.getPassword())); String response = String.format("Basic %s", Base64Util.encode(WrappedByteBuffer.wrap(unencoded.getBytes()))); Arrays.fill(creds.getPassword(), (char) 0); return new ChallengeResponse(response.toCharArray(), nextChallengeHandler); } }
public static ChallengeResponse create(PasswordAuthentication creds, ChallengeHandler nextChallengeHandler) { String unencoded = String.format("%s:%s", creds.getUserName(), new String(creds.getPassword())); String response = String.format("Basic %s", Base64Util.encode(WrappedByteBuffer.wrap(unencoded.getBytes()))); Arrays.fill(creds.getPassword(), (char) 0); return new ChallengeResponse(response.toCharArray(), nextChallengeHandler); } }
protected String performBasicAuthentication(InetSocketAddress target, String challenge) throws IOException { int index = challenge.indexOf("realm="); if (index == -1) return null; String realm = challenge.substring(index + 6); // "realm=" String hostname = target.getHostName(); InetAddress addr = target.isUnresolved() ? null : target.getAddress(); PasswordAuthentication pa = Authenticator .requestPasswordAuthentication(hostname, addr, target.getPort(), "HTTP", realm, "Basic Authentication"); if (pa == null) return null; String auth = pa.getUserName() + ":" + new String(pa.getPassword()); return "Basic " + Base64.encodeBytes(auth.getBytes(), Base64.NO_OPTIONS); }
@Override public void setProxyAuthentication(PasswordAuthentication proxyAuthentication) { clientBuilder.proxyAuthenticator(new ProxyAuthenticator(Credentials.basic (proxyAuthentication.getUserName(), new String(proxyAuthentication.getPassword()) ))); }
@Override public void actionPerformed(ActionEvent e) { try { PasswordAuthentication passwordAuthentication = k.getPasswordAuthentication(); if (passwordAuthentication != null) { k.login(passwordAuthentication.getUserName(), passwordAuthentication.getPassword(), onlineCheckBoxForKenai.isSelected()); } } catch (KenaiException ex) { Exceptions.printStackTrace(ex); } } });
String createAuthenticationHeader() { PasswordAuthentication credentials = getCredentialsForRealm(); return getAuthenticationStrategy().createAuthenticationHeader( this, credentials.getUserName(), new String( credentials.getPassword() ) ); }
String createAuthenticationHeader() { PasswordAuthentication credentials = getCredentialsForRealm(); return getAuthenticationStrategy().createAuthenticationHeader( this, credentials.getUserName(), new String( credentials.getPassword() ) ); }
String createAuthenticationHeader() { PasswordAuthentication credentials = getCredentialsForRealm(); return getAuthenticationStrategy().createAuthenticationHeader( this, credentials.getUserName(), new String( credentials.getPassword() ) ); }
@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 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; }
@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; }