diff options
author | Scott Jackson <daneren2005@users.noreply.github.com> | 2020-09-25 16:59:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-25 16:59:17 -0700 |
commit | f34156e40c6eb01b13591b3c3b4973b027dc8a41 (patch) | |
tree | 0926e92db1a5f7ddb0c2f64c52678a218d6b774d /app | |
parent | 7aff3fa37b186b40d2ac73508b01628b212be8eb (diff) | |
parent | aeabf68e4be9f2240bfb9133b5d9727aada419d0 (diff) | |
download | dsub-f34156e40c6eb01b13591b3c3b4973b027dc8a41.tar.gz dsub-f34156e40c6eb01b13591b3c3b4973b027dc8a41.tar.bz2 dsub-f34156e40c6eb01b13591b3c3b4973b027dc8a41.zip |
Merge pull request #1012 from Kakadua/headerauth
Adds a checkbox for including Authorization headers to the server settings
Diffstat (limited to 'app')
5 files changed, 25 insertions, 5 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java index 326cebb4..1789ad15 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java @@ -575,6 +575,12 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); + final CheckBoxPreference serverAuthHeaderPreference = new CheckBoxPreference(context); + serverAuthHeaderPreference.setKey(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance); + serverAuthHeaderPreference.setChecked(Util.isAuthHeaderEnabled(context, instance)); + serverAuthHeaderPreference.setSummary(R.string.settings_server_authheaders_summary); + serverAuthHeaderPreference.setTitle(R.string.settings_server_authheaders); + final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); @@ -649,6 +655,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared screen.addPreference(serverPasswordPreference); screen.addPreference(serverTagPreference); screen.addPreference(serverSyncPreference); + screen.addPreference(serverAuthHeaderPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java index 100224e8..8fdafc11 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java @@ -1911,11 +1911,16 @@ public class RESTMusicService implements MusicService { 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); + boolean authHeader = prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance, true); + if(authHeader) { + 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) { diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java index 933f531f..9e6708be 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -85,6 +85,7 @@ public final class Constants { public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId"; public static final String PREFERENCES_KEY_USERNAME = "username"; public static final String PREFERENCES_KEY_PASSWORD = "password"; + public static final String PREFERENCES_KEY_SERVER_AUTHHEADER = "authHeader"; public static final String PREFERENCES_KEY_ENCRYPTED_PASSWORD = "encryptedPassword"; public static final String PREFERENCES_KEY_INSTALL_TIME = "installTime"; public static final String PREFERENCES_KEY_THEME = "theme"; diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index b58a81e4..872e9561 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -460,6 +460,11 @@ public final class Util { return prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_SYNC + instance, true); } + public static boolean isAuthHeaderEnabled(Context context, int instance) { + SharedPreferences prefs = getPreferences(context); + return prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance, true); + } + public static String getParentFromEntry(Context context, MusicDirectory.Entry entry) { if(Util.isTagBrowsing(context)) { if(!entry.isDirectory()) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 17e96487..a3dd6af2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -284,6 +284,8 @@ <string name="settings.server_open_browser">Open in browser</string> <string name="settings.server_sync_summary">Whether or not syncing is enabled for this server</string> <string name="settings.server_sync">Sync Enabled</string> + <string name="settings.server_authheaders_summary">If this is enabled the request headers will include Authorization: Basic</string> + <string name="settings.server_authheaders">Authorization Basic headers</string> <string name="settings.cache_title">Music cache</string> <string name="settings.preload_wifi">Songs to preload (Wifi)</string> <string name="settings.preload_mobile">Songs to preload (Mobile)</string> |