Skip to content

Commit

Permalink
Merge pull request #8051 from ashcoding/TIMOB-20415_5_4_X
Browse files Browse the repository at this point in the history
(5_4_X)[TIMOB-20415] Android: HttpClient Basic Auth Infinite loop fix
  • Loading branch information
hieupham007 committed Jun 16, 2016
2 parents 2a48306 + ea6f851 commit f343fcd
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class TiAuthenticator extends Authenticator {
String user;
String password;

// MAX_RETRY_COUNT is set to 3 retries
private final static int MAX_RETRY_COUNT = 3;
private int retryCount = 0;

public TiAuthenticator(String user, String password) {
super();
this.domain = null;
Expand All @@ -27,9 +31,20 @@ public PasswordAuthentication getPasswordAuthentication() {
if (domain != null && !domain.isEmpty()) {
user = domain + "\\" + user;
}
if (password != null) {
return new PasswordAuthentication(user, password.toCharArray());
// This is for TIMOB-20415 with the solution from Android's Issue Tracker,
// https://code.google.com/p/android/issues/detail?id=7058
// The Authenticator will do a retry when when it gets a response from the
// server that the credentials provided is incorrect. When this happens,
// getPasswordAuthentication() is called again for as long it is incorrect.
// In order to stop the loop, the Authenticator needs to return a null
// object to indicate that the retry needs to stop. Hence, we have a MAX_RETRY_COUNT.
if (retryCount < MAX_RETRY_COUNT) {
retryCount++;
if (password != null) {
return new PasswordAuthentication(user, password.toCharArray());
}
return new PasswordAuthentication(user, null);
}
return new PasswordAuthentication(user, null);
return null;
}
}

0 comments on commit f343fcd

Please sign in to comment.