Merge pull request #140 from ultrasonic/special-case-for-ldap-user
Special case for ldap user
This commit is contained in:
commit
9389af5a79
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Chain>()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -299,6 +299,9 @@
|
|||
<string name="settings.theme_light">Claro</string>
|
||||
<string name="settings.theme_title">Tema</string>
|
||||
<string name="settings.title.allow_self_signed_certificate">Permir certificado HTTPS autofirmado</string>
|
||||
<string name="settings.title.enable_ldap_users_support">Habilitar soporte para usuarios LDAP</string>
|
||||
<string name="settings.summary.enable_ldap_users_support">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.</string>
|
||||
<string name="settings.use_folder_for_album_artist">Usar carpetas para el nombre del artista</string>
|
||||
<string name="settings.use_folder_for_album_artist_summary">Se asume que la carpeta en el nivel mal alto es el nombre del artista del álbum</string>
|
||||
<string name="settings.use_id3">Navegar usando las etiquetas ID3</string>
|
||||
|
|
|
@ -299,6 +299,9 @@
|
|||
<string name="settings.theme_light">Clair</string>
|
||||
<string name="settings.theme_title">Thème</string>
|
||||
<string name="settings.title.allow_self_signed_certificate">Autoriser le certificat HTTPS auto-signé</string>
|
||||
<string name="settings.title.enable_ldap_users_support">Activer la prise en charge des utilisateurs LDAP</string>
|
||||
<string name="settings.summary.enable_ldap_users_support">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.</string>
|
||||
<string name="settings.use_folder_for_album_artist">Utilisez des dossiers pour les noms d\'artistes</string>
|
||||
<string name="settings.use_folder_for_album_artist_summary">Dossier de niveau supérieur devient le nom de l\'artiste de l\'album</string>
|
||||
<string name="settings.use_id3">Naviguer en utilisant ID3 Tags</string>
|
||||
|
|
|
@ -299,6 +299,9 @@
|
|||
<string name="settings.theme_light">Világos</string>
|
||||
<string name="settings.theme_title">Téma</string>
|
||||
<string name="settings.title.allow_self_signed_certificate">Engedélyezze az önaláírt HTTPS tanúsítványt</string>
|
||||
<string name="settings.title.enable_ldap_users_support">Az LDAP-felhasználók támogatásának engedélyezése</string>
|
||||
<string name="settings.summary.enable_ldap_users_support">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.</string>
|
||||
<string name="settings.use_folder_for_album_artist">Mappanevek használata az előadók neveként</string>
|
||||
<string name="settings.use_folder_for_album_artist_summary">Feltételezi, hogy a legfelső szintű mappa az előadó neve.</string>
|
||||
<string name="settings.use_id3">Böngészés ID3 Tag használatával</string>
|
||||
|
|
|
@ -302,6 +302,9 @@
|
|||
<string name="settings.theme_light">Claro</string>
|
||||
<string name="settings.theme_title">Tema</string>
|
||||
<string name="settings.title.allow_self_signed_certificate">Permitir o certificado HTTPS auto-assinado</string>
|
||||
<string name="settings.title.enable_ldap_users_support">Ative o suporte para usuários LDAP</string>
|
||||
<string name="settings.summary.enable_ldap_users_support">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.</string>
|
||||
<string name="settings.use_folder_for_album_artist">Pasta para Nome do Artista</string>
|
||||
<string name="settings.use_folder_for_album_artist_summary">Assume que a pasta mais acima é o nome do artista</string>
|
||||
<string name="settings.use_id3">Navegar Usando Etiquetas ID3</string>
|
||||
|
|
|
@ -302,6 +302,9 @@
|
|||
<string name="settings.theme_light">Claro</string>
|
||||
<string name="settings.theme_title">Tema</string>
|
||||
<string name="settings.title.allow_self_signed_certificate">Permitir o certificado HTTPS auto-assinado</string>
|
||||
<string name="settings.title.enable_ldap_users_support">Ative o suporte para usuários LDAP</string>
|
||||
<string name="settings.summary.enable_ldap_users_support">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.</string>
|
||||
<string name="settings.use_folder_for_album_artist">Pasta para Nome do Artista</string>
|
||||
<string name="settings.use_folder_for_album_artist_summary">Assume que a pasta mais acima é o nome do artista</string>
|
||||
<string name="settings.use_id3">Navegar Usando Etiquetas ID3</string>
|
||||
|
|
|
@ -143,6 +143,7 @@
|
|||
<string name="select_playlist.empty">No saved playlists on server</string>
|
||||
<string name="service.connecting">Contacting server, please wait.</string>
|
||||
<string name="settings.allow_self_signed_certificate" translatable="false">allowSelfSignedCertificate</string>
|
||||
<string name="settings.enable_ldap_user_support" translatable="false">enableLdapUserSupport</string>
|
||||
<string name="settings.appearance_title">Appearance</string>
|
||||
<string name="settings.buffer_length">Buffer Length</string>
|
||||
<string name="settings.buffer_length_0">Disabled</string>
|
||||
|
@ -303,6 +304,9 @@
|
|||
<string name="settings.theme_light">Light</string>
|
||||
<string name="settings.theme_title">Theme</string>
|
||||
<string name="settings.title.allow_self_signed_certificate">Allow self-signed HTTPS certificate</string>
|
||||
<string name="settings.title.enable_ldap_users_support">Enable support for LDAP users</string>
|
||||
<string name="settings.summary.enable_ldap_users_support">This forces app to always send password in old-way,
|
||||
because Subsonic api does not support new authorization for LDAP users.</string>
|
||||
<string name="settings.use_folder_for_album_artist">Use Folders For Artist Name</string>
|
||||
<string name="settings.use_folder_for_album_artist_summary">Assume top-level folder is the name of the album artist</string>
|
||||
<string name="settings.use_id3">Browse Using ID3 Tags</string>
|
||||
|
|
|
@ -44,6 +44,13 @@
|
|||
android:defaultValue="false"
|
||||
android:title="@string/settings.title.allow_self_signed_certificate"
|
||||
/>
|
||||
<CheckBoxPreference
|
||||
android:key="@string/settings.enable_ldap_user_support"
|
||||
android:persistent="false"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/settings.title.enable_ldap_users_support"
|
||||
android:summary="@string/settings.summary.enable_ldap_users_support"
|
||||
/>
|
||||
<CheckBoxPreference
|
||||
android:key="@string/jukebox.is_default"
|
||||
android:persistent="false"
|
||||
|
|
Loading…
Reference in New Issue