Skip to content

Commit

Permalink
Only send auth headers when the getUser path is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
magneticflux- committed Sep 25, 2020
1 parent 7aff3fa commit 9ce50c9
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1909,13 +1909,15 @@ private HttpURLConnection getConnectionDirect(Context context, String url, Map<S
sslConnection.setHostnameVerifier(selfSignedHostnameVerifier);
}

SharedPreferences prefs = Util.getPreferences(context);
int instance = getInstance(context);
String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
if (prefs.getBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + instance, false)) password = KeyStoreUtil.decrypt(password);
String encoded = Base64.encodeToString((username + ":" + password).getBytes("UTF-8"), Base64.NO_WRAP);;
connection.setRequestProperty("Authorization", "Basic " + encoded);
if(url.contains("getUser")) {
SharedPreferences prefs = Util.getPreferences(context);
int instance = getInstance(context);
String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
if (prefs.getBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + instance, false)) password = KeyStoreUtil.decrypt(password);
String encoded = Base64.encodeToString((username + ":" + password).getBytes("UTF-8"), Base64.NO_WRAP);
connection.setRequestProperty("Authorization", "Basic " + encoded);
}

// Force the connection to initiate
if(connection.getResponseCode() >= 500) {
Expand Down

0 comments on commit 9ce50c9

Please sign in to comment.