com.squareup.okhttp.OkAuthenticator.Challenge Java Examples
The following examples show how to use
com.squareup.okhttp.OkAuthenticator.Challenge.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpAuthenticator.java From bluemix-parking-meter with MIT License | 6 votes |
@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; }
Example #2
Source File: HttpAuthenticator.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
@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; }
Example #3
Source File: HttpAuthenticator.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
@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; }
Example #4
Source File: HttpAuthenticator.java From phonegapbootcampsite with MIT License | 6 votes |
@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; }
Example #5
Source File: HttpAuthenticator.java From L.TileLayer.Cordova with MIT License | 6 votes |
@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; }
Example #6
Source File: HttpAuthenticator.java From reader with MIT License | 6 votes |
@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; }
Example #7
Source File: HttpAuthenticator.java From reader with MIT License | 6 votes |
@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; }
Example #8
Source File: HttpAuthenticator.java From phonegapbootcampsite with MIT License | 6 votes |
@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; }
Example #9
Source File: HttpAuthenticator.java From reader with MIT License | 6 votes |
@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; }
Example #10
Source File: HttpAuthenticator.java From reader with MIT License | 6 votes |
@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; }
Example #11
Source File: HttpAuthenticator.java From CordovaYoutubeVideoPlayer with MIT License | 6 votes |
@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; }
Example #12
Source File: HttpAuthenticator.java From CordovaYoutubeVideoPlayer with MIT License | 6 votes |
@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; }
Example #13
Source File: HttpAuthenticator.java From bluemix-parking-meter with MIT License | 6 votes |
@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; }
Example #14
Source File: HttpAuthenticator.java From android-discourse with Apache License 2.0 | 6 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #15
Source File: HttpAuthenticator.java From wildfly-samples with MIT License | 6 votes |
@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; }
Example #16
Source File: HttpAuthenticator.java From wildfly-samples with MIT License | 6 votes |
@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; }
Example #17
Source File: HttpAuthenticator.java From crosswalk-cordova-android with Apache License 2.0 | 6 votes |
@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; }
Example #18
Source File: HttpAuthenticator.java From IoTgo_Android_App with MIT License | 6 votes |
@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; }
Example #19
Source File: HttpAuthenticator.java From IoTgo_Android_App with MIT License | 6 votes |
@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; }
Example #20
Source File: HttpAuthenticator.java From crosswalk-cordova-android with Apache License 2.0 | 6 votes |
@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; }
Example #21
Source File: HttpAuthenticator.java From L.TileLayer.Cordova with MIT License | 6 votes |
@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; }
Example #22
Source File: HttpAuthenticator.java From reader with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #23
Source File: HttpAuthenticator.java From CordovaYoutubeVideoPlayer with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #24
Source File: HttpAuthenticator.java From phonegapbootcampsite with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #25
Source File: HttpAuthenticator.java From wildfly-samples with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #26
Source File: HttpAuthenticator.java From crosswalk-cordova-android with Apache License 2.0 | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #27
Source File: HttpAuthenticator.java From L.TileLayer.Cordova with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #28
Source File: HttpAuthenticator.java From reader with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #29
Source File: HttpAuthenticator.java From IoTgo_Android_App with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }
Example #30
Source File: HttpAuthenticator.java From bluemix-parking-meter with MIT License | 5 votes |
/** * React to a failed authorization response by looking up new credentials. * * @return true if credentials have been added to successorRequestHeaders * and another request should be attempted. */ public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException { String responseField; String requestField; if (responseCode == HTTP_UNAUTHORIZED) { responseField = "WWW-Authenticate"; requestField = "Authorization"; } else if (responseCode == HTTP_PROXY_AUTH) { responseField = "Proxy-Authenticate"; requestField = "Proxy-Authorization"; } else { throw new IllegalArgumentException(); // TODO: ProtocolException? } List<Challenge> challenges = parseChallenges(responseHeaders, responseField); if (challenges.isEmpty()) { return false; // Could not find a challenge so end the request cycle. } Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges); if (credential == null) { return false; // Could not satisfy the challenge so end the request cycle. } // Add authorization credentials, bypassing the already-connected check. successorRequestHeaders.set(requestField, credential.getHeaderValue()); return true; }