diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt index db769ccc..fa1c1cd2 100644 --- a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt @@ -41,13 +41,17 @@ class SubsonicAPIClient(baseUrl: String, minimalProtocolVersion: SubsonicAPIVersions, clientID: String, allowSelfSignedCertificate: Boolean = false, + enableLdapUserSupport: Boolean = false, debug: Boolean = false) { private val versionInterceptor = VersionInterceptor(minimalProtocolVersion) { protocolVersion = it } - private val proxyPasswordInterceptor = ProxyPasswordInterceptor(minimalProtocolVersion, - PasswordHexInterceptor(password), PasswordMD5Interceptor(password)) + private val proxyPasswordInterceptor = ProxyPasswordInterceptor( + minimalProtocolVersion, + PasswordHexInterceptor(password), + PasswordMD5Interceptor(password), + enableLdapUserSupport) /** * Get currently used protocol version. diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptor.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptor.kt index 0273f984..ca796a17 100644 --- a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptor.kt +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptor.kt @@ -7,15 +7,21 @@ import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions /** * Proxy [Interceptor] that uses one of [hexInterceptor] or [mD5Interceptor] depends on [apiVersion]. + * + * To force [hexInterceptor] set [forceHexPassword] to `true`. Usually it should be done only for + * ldap users. */ internal class ProxyPasswordInterceptor( initialAPIVersions: SubsonicAPIVersions, private val hexInterceptor: PasswordHexInterceptor, - private val mD5Interceptor: PasswordMD5Interceptor) : Interceptor { + private val mD5Interceptor: PasswordMD5Interceptor, + private val forceHexPassword: Boolean = false +) : Interceptor { var apiVersion: SubsonicAPIVersions = initialAPIVersions override fun intercept(chain: Chain): Response = - if (apiVersion < SubsonicAPIVersions.V1_13_0) { + if (apiVersion < SubsonicAPIVersions.V1_13_0 || + forceHexPassword) { hexInterceptor.intercept(chain) } else { mD5Interceptor.intercept(chain) diff --git a/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt b/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt index 2b7d9bcd..4bac103f 100644 --- a/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt +++ b/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt @@ -6,6 +6,7 @@ import okhttp3.Interceptor.Chain import org.junit.Test import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_12_0 import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_13_0 +import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_16_0 /** * Unit test for [ProxyPasswordInterceptor]. @@ -16,7 +17,7 @@ class ProxyPasswordInterceptorTest { private val mockChain = mock() private val proxyInterceptor = ProxyPasswordInterceptor(V1_12_0, - mockPasswordHexInterceptor, mockPasswordMd5Interceptor) + mockPasswordHexInterceptor, mockPasswordMd5Interceptor, false) @Test fun `Should use hex password on versions less then 1 13 0`() { @@ -33,4 +34,14 @@ class ProxyPasswordInterceptorTest { verify(mockPasswordMd5Interceptor).intercept(mockChain) } + + @Test + fun `Should use hex password if forceHex is true`() { + val interceptor = ProxyPasswordInterceptor(V1_16_0, mockPasswordHexInterceptor, + mockPasswordMd5Interceptor, true) + + interceptor.intercept(mockChain) + + verify(mockPasswordHexInterceptor).intercept(mockChain) + } } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ServerSettingsFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ServerSettingsFragment.java index b9fcb529..85456be2 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ServerSettingsFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ServerSettingsFragment.java @@ -38,6 +38,7 @@ public class ServerSettingsFragment extends PreferenceFragment private CheckBoxPreference equalizerPref; private CheckBoxPreference jukeboxPref; private CheckBoxPreference allowSelfSignedCertificatePref; + private CheckBoxPreference enableLdapUserSupportPref; private Preference removeServerPref; private Preference testConnectionPref; @@ -77,6 +78,9 @@ public class ServerSettingsFragment extends PreferenceFragment testConnectionPref = findPreference(getString(R.string.settings_test_connection_title)); allowSelfSignedCertificatePref = (CheckBoxPreference) findPreference( getString(R.string.settings_allow_self_signed_certificate)); + enableLdapUserSupportPref = (CheckBoxPreference) findPreference( + getString(R.string.settings_enable_ldap_user_support) + ); setupPreferencesValues(); setupPreferencesListeners(); @@ -140,6 +144,11 @@ public class ServerSettingsFragment extends PreferenceFragment .putBoolean(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + serverId, (Boolean) newValue) .apply(); return true; + } else if (preference == enableLdapUserSupportPref) { + sharedPreferences.edit() + .putBoolean(Constants.PREFERENCES_KEY_LDAP_SUPPORT + serverId, (Boolean) newValue) + .apply(); + return true; } return false; } @@ -175,6 +184,9 @@ public class ServerSettingsFragment extends PreferenceFragment allowSelfSignedCertificatePref.setChecked(sharedPreferences .getBoolean(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + serverId, false)); + + enableLdapUserSupportPref.setChecked(sharedPreferences + .getBoolean(Constants.PREFERENCES_KEY_LDAP_SUPPORT + serverId, false)); } private void updatePassword() { @@ -213,6 +225,7 @@ public class ServerSettingsFragment extends PreferenceFragment equalizerPref.setOnPreferenceChangeListener(this); jukeboxPref.setOnPreferenceChangeListener(this); allowSelfSignedCertificatePref.setOnPreferenceChangeListener(this); + enableLdapUserSupportPref.setOnPreferenceChangeListener(this); removeServerPref.setOnPreferenceClickListener(this); testConnectionPref.setOnPreferenceClickListener(this); diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/MusicServiceFactory.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/MusicServiceFactory.java index e274412a..4d2b3d4b 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/MusicServiceFactory.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/MusicServiceFactory.java @@ -86,6 +86,8 @@ public class MusicServiceFactory { String password = preferences.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null); boolean allowSelfSignedCertificate = preferences .getBoolean(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + instance, false); + boolean enableLdapUserSupport = preferences + .getBoolean(Constants.PREFERENCES_KEY_LDAP_SUPPORT + instance , false); if (serverUrl == null || username == null || @@ -93,11 +95,13 @@ public class MusicServiceFactory { Log.i("MusicServiceFactory", "Server credentials is not available"); return new SubsonicAPIClient("http://localhost", "", "", SubsonicAPIVersions.fromApiVersion(Constants.REST_PROTOCOL_VERSION), - Constants.REST_CLIENT_ID, allowSelfSignedCertificate, BuildConfig.DEBUG); + Constants.REST_CLIENT_ID, allowSelfSignedCertificate, + enableLdapUserSupport, BuildConfig.DEBUG); } return new SubsonicAPIClient(serverUrl, username, password, SubsonicAPIVersions.fromApiVersion(Constants.REST_PROTOCOL_VERSION), - Constants.REST_CLIENT_ID, allowSelfSignedCertificate, BuildConfig.DEBUG); + Constants.REST_CLIENT_ID, allowSelfSignedCertificate, + enableLdapUserSupport, BuildConfig.DEBUG); } } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java b/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java index a3aab7e5..de3b0a70 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java @@ -77,6 +77,7 @@ public final class Constants public static final String PREFERENCES_KEY_USERNAME = "username"; public static final String PREFERENCES_KEY_PASSWORD = "password"; public static final String PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE = "allowSSCertificate"; + public static final String PREFERENCES_KEY_LDAP_SUPPORT = "enableLdapSupport"; public static final String PREFERENCES_KEY_INSTALL_TIME = "installTime"; public static final String PREFERENCES_KEY_THEME = "theme"; public static final String PREFERENCES_KEY_DISPLAY_BITRATE_WITH_ARTIST = "displayBitrateWithArtist"; diff --git a/ultrasonic/src/main/res/values-es/strings.xml b/ultrasonic/src/main/res/values-es/strings.xml index c047418a..525a11ee 100644 --- a/ultrasonic/src/main/res/values-es/strings.xml +++ b/ultrasonic/src/main/res/values-es/strings.xml @@ -299,6 +299,9 @@ Claro Tema Permir certificado HTTPS autofirmado + Habilitar soporte para usuarios LDAP + Esto obliga a la aplicación a enviar siempre la contraseña en modo antiguo, + porque Subsonic api no soporta nueva autorización para usuarios LDAP. Usar carpetas para el nombre del artista Se asume que la carpeta en el nivel mal alto es el nombre del artista del álbum Navegar usando las etiquetas ID3 diff --git a/ultrasonic/src/main/res/values-fr/strings.xml b/ultrasonic/src/main/res/values-fr/strings.xml index 0dfb8284..54b0c249 100644 --- a/ultrasonic/src/main/res/values-fr/strings.xml +++ b/ultrasonic/src/main/res/values-fr/strings.xml @@ -299,6 +299,9 @@ Clair Thème Autoriser le certificat HTTPS auto-signé + Activer la prise en charge des utilisateurs LDAP + Cela force l\'application à toujours envoyer le mot de passe à l\'ancienne, + parce que Subsonic api ne supporte pas les nouvelles autorisations pour les utilisateurs LDAP. Utilisez des dossiers pour les noms d\'artistes Dossier de niveau supérieur devient le nom de l\'artiste de l\'album Naviguer en utilisant ID3 Tags diff --git a/ultrasonic/src/main/res/values-hu/strings.xml b/ultrasonic/src/main/res/values-hu/strings.xml index d94a0a88..0bf3027c 100644 --- a/ultrasonic/src/main/res/values-hu/strings.xml +++ b/ultrasonic/src/main/res/values-hu/strings.xml @@ -299,6 +299,9 @@ Világos Téma Engedélyezze az önaláírt HTTPS tanúsítványt + Az LDAP-felhasználók támogatásának engedélyezése + Ez arra kényszeríti az alkalmazást, hogy mindig jelszót küldjön régi módon, + mert a Subsonic api nem támogatja az LDAP-felhasználók új engedélyezését. Mappanevek használata az előadók neveként Feltételezi, hogy a legfelső szintű mappa az előadó neve. Böngészés ID3 Tag használatával diff --git a/ultrasonic/src/main/res/values-pt-rBR/strings.xml b/ultrasonic/src/main/res/values-pt-rBR/strings.xml index ba5042ac..2fe7fba0 100644 --- a/ultrasonic/src/main/res/values-pt-rBR/strings.xml +++ b/ultrasonic/src/main/res/values-pt-rBR/strings.xml @@ -302,6 +302,9 @@ Claro Tema Permitir o certificado HTTPS auto-assinado + Ative o suporte para usuários LDAP + Isso força o aplicativo a enviar sempre a senha de forma antiga, + porque o Subsonic api não suporta nova autorização para usuários LDAP. Pasta para Nome do Artista Assume que a pasta mais acima é o nome do artista Navegar Usando Etiquetas ID3 diff --git a/ultrasonic/src/main/res/values-pt/strings.xml b/ultrasonic/src/main/res/values-pt/strings.xml index b5f1e6c5..3908daca 100644 --- a/ultrasonic/src/main/res/values-pt/strings.xml +++ b/ultrasonic/src/main/res/values-pt/strings.xml @@ -302,6 +302,9 @@ Claro Tema Permitir o certificado HTTPS auto-assinado + Ative o suporte para usuários LDAP + Isso força o aplicativo a enviar sempre a senha de forma antiga, + porque o Subsonic api não suporta nova autorização para usuários LDAP. Pasta para Nome do Artista Assume que a pasta mais acima é o nome do artista Navegar Usando Etiquetas ID3 diff --git a/ultrasonic/src/main/res/values/strings.xml b/ultrasonic/src/main/res/values/strings.xml index 21ac1e74..91777b4f 100644 --- a/ultrasonic/src/main/res/values/strings.xml +++ b/ultrasonic/src/main/res/values/strings.xml @@ -143,6 +143,7 @@ No saved playlists on server Contacting server, please wait. allowSelfSignedCertificate + enableLdapUserSupport Appearance Buffer Length Disabled @@ -303,6 +304,9 @@ Light Theme Allow self-signed HTTPS certificate + Enable support for LDAP users + This forces app to always send password in old-way, + because Subsonic api does not support new authorization for LDAP users. Use Folders For Artist Name Assume top-level folder is the name of the album artist Browse Using ID3 Tags diff --git a/ultrasonic/src/main/res/xml/server_settings.xml b/ultrasonic/src/main/res/xml/server_settings.xml index 3f755b58..46ea55dd 100644 --- a/ultrasonic/src/main/res/xml/server_settings.xml +++ b/ultrasonic/src/main/res/xml/server_settings.xml @@ -44,6 +44,13 @@ android:defaultValue="false" android:title="@string/settings.title.allow_self_signed_certificate" /> +