tempus/app/src/main/java/com/cappielloantonio/play/subsonic/SubsonicPreferences.java

87 lines
2.1 KiB
Java
Raw Normal View History

2021-07-24 12:27:45 +02:00
package com.cappielloantonio.play.subsonic;
import com.cappielloantonio.play.subsonic.utils.StringUtil;
import java.util.UUID;
public class SubsonicPreferences {
private String serverUrl;
private String username;
2021-12-23 17:10:03 +01:00
private String clientName = "Play";
private SubsonicAuthentication authentication;
2021-07-24 12:27:45 +02:00
public String getServerUrl() {
return serverUrl;
}
public String getUsername() {
return username;
}
public String getClientName() {
return clientName;
}
public SubsonicAuthentication getAuthentication() {
return authentication;
}
2021-07-28 18:28:47 +02:00
public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
}
public void setUsername(String username) {
this.username = username;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public void setAuthentication(String password, String token, String salt, boolean isLowSecurity) {
if (password != null) {
this.authentication = new SubsonicAuthentication(password, isLowSecurity);
}
if (token != null && salt != null) {
2021-08-01 11:48:18 +02:00
this.authentication = new SubsonicAuthentication(token, salt);
}
2021-07-24 12:27:45 +02:00
}
public static class SubsonicAuthentication {
private String password;
2021-07-24 12:27:45 +02:00
private String salt;
private String token;
public SubsonicAuthentication(String password, boolean isLowSecurity) {
if (isLowSecurity) {
this.password = password;
} else {
update(password);
}
2021-07-24 12:27:45 +02:00
}
2021-07-28 13:55:05 +02:00
public SubsonicAuthentication(String token, String salt) {
this.token = token;
this.salt = salt;
}
public String getPassword() {
return password;
}
2021-07-24 12:27:45 +02:00
public String getSalt() {
return salt;
}
public String getToken() {
return token;
}
void update(String password) {
this.salt = UUID.randomUUID().toString();
this.token = StringUtil.tokenize(password + salt);
}
}
}