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-07-28 09:20:22 +02:00
|
|
|
private String clientName = "Play for Subsonic";
|
2021-07-24 12:27:45 +02:00
|
|
|
|
2021-07-28 09:20:22 +02:00
|
|
|
private SubsonicAuthentication authentication;
|
2021-07-24 12:27:45 +02:00
|
|
|
|
2021-07-28 09:20:22 +02:00
|
|
|
public SubsonicPreferences(String serverUrl, String username, String password, String token, String salt) {
|
2021-07-24 12:27:45 +02:00
|
|
|
this.serverUrl = serverUrl;
|
|
|
|
|
this.username = username;
|
2021-07-28 09:20:22 +02:00
|
|
|
if(password != null) this.authentication = new SubsonicAuthentication(password);
|
2021-07-28 13:55:05 +02:00
|
|
|
if(token != null && salt != null) this.authentication = new SubsonicAuthentication(token, salt);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPassword(String password) {
|
|
|
|
|
authentication.update(password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class SubsonicAuthentication {
|
|
|
|
|
private String salt;
|
|
|
|
|
private String token;
|
|
|
|
|
|
|
|
|
|
public SubsonicAuthentication(String password) {
|
|
|
|
|
update(password);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 13:55:05 +02:00
|
|
|
public SubsonicAuthentication(String token, String salt) {
|
|
|
|
|
this.token = token;
|
|
|
|
|
this.salt = salt;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|