@Override public Request authenticate(Route route, Response response) throws IOException { if (response.request().header("Authorization") != null) { return null; // Give up, we've already attempted to authenticate. } System.out.println("Authenticating for response: " + response); System.out.println("Challenges: " + response.challenges()); String credential = Credentials.basic("jesse", "password1"); return response.request().newBuilder() .header("Authorization", credential) .build(); } })
@Nullable @Override public Request authenticate(@Nonnull Route route, @Nonnull Response response) throws IOException { final Set<String> authenticationMethods = response.challenges().stream() .map(Challenge::scheme) .map(s -> s.toLowerCase(Locale.ROOT)) .collect(Collectors.toSet()); if (!authenticationMethods.contains(AUTH_BASIC)) { LOG.warn("Graylog only supports the \"{}\" authentication scheme but the proxy server asks for one of the following: {}", AUTH_BASIC, authenticationMethods); return null; } if (response.request().header(PROXY_AUTHORIZATION) != null) { return null; // Give up, we've already failed to authenticate. } return response.request().newBuilder().addHeader(PROXY_AUTHORIZATION, credentials).build(); } }
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url();
@Override public Request authenticate(Route route, Response response) throws IOException { if (response.request().header("Authorization") != null) { return null; // Give up, we've already attempted to authenticate. } System.out.println("Authenticating for response: " + response); System.out.println("Challenges: " + response.challenges()); String credential = Credentials.basic(userName, password); return response.request().newBuilder() .header("Authorization", credential) .build(); } }
@Nullable @Override public Request authenticate(@Nonnull Route route, @Nonnull Response response) throws IOException { final Set<String> authenticationMethods = response.challenges().stream() .map(Challenge::scheme) .map(s -> s.toLowerCase(Locale.ROOT)) .collect(Collectors.toSet()); if (!authenticationMethods.contains(AUTH_BASIC)) { LOG.warn("Graylog only supports the \"{}\" authentication scheme but the proxy server asks for one of the following: {}", AUTH_BASIC, authenticationMethods); return null; } if (response.request().header(PROXY_AUTHORIZATION) != null) { return null; // Give up, we've already failed to authenticate. } return response.request().newBuilder().addHeader(PROXY_AUTHORIZATION, credentials).build(); } }
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); if (!challenges.isEmpty()) { for (Challenge challenge : challenges) { final String scheme = challenge.scheme(); Authenticator authenticator = null; if (scheme != null) { authenticator = authenticatorRegistry.get(scheme.toLowerCase(Locale.getDefault())); } if (authenticator != null) { return authenticator.authenticate(route, response); } } } throw new IllegalArgumentException("unsupported auth scheme " + challenges); }
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); if (!challenges.isEmpty()) { for (Challenge challenge : challenges) { final String scheme = challenge.scheme(); Authenticator authenticator = null; if (scheme != null) { authenticator = authenticatorRegistry.get(scheme.toLowerCase(Locale.getDefault())); } if (authenticator != null) { return authenticator.authenticate(route, response); } } } return null; }
@Override public Request authenticateProxy(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue; InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.scheme(), challenge.realm(), challenge.scheme(), url.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; }
@Override public Request authenticateProxy(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue; InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.scheme(), challenge.realm(), challenge.scheme(), url.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; }
@Override public Request authenticate(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue; PasswordAuthentication 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) continue; String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword())); return request.newBuilder() .header("Authorization", credential) .build(); } return null; }
@Override public Request authenticate(Proxy proxy, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url(); for (int i = 0, size = challenges.size(); i < size; i++) { Challenge challenge = challenges.get(i); if (!"Basic".equalsIgnoreCase(challenge.scheme())) continue; PasswordAuthentication 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) continue; String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword())); return request.newBuilder() .header("Authorization", credential) .build(); } return null; }
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url();
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url();
@Override public Request authenticate(Route route, Response response) throws IOException { List<Challenge> challenges = response.challenges(); Request request = response.request(); HttpUrl url = request.url();