Add a basic form of unsecure authentication (in plain password)

This commit is contained in:
CappielloAntonio 2022-01-11 12:49:40 +01:00
parent e5aec08c8e
commit d93c3bb45c
8 changed files with 44 additions and 9 deletions

View file

@ -54,6 +54,7 @@ public class App extends Application {
SubsonicPreferences preferences = new SubsonicPreferences();
preferences.setServerUrl(server);
preferences.setUsername(username);
preferences.setPassword(password);
preferences.setAuthentication(password, token, salt);
return new Subsonic(context, preferences);

View file

@ -21,9 +21,9 @@ import com.cappielloantonio.play.model.Server;
@SuppressLint("RestrictedApi")
@Database(
version = 30,
version = 31,
entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Playlist.class},
autoMigrations = { @AutoMigration(from = 29, to = 30) }
autoMigrations = { @AutoMigration(from = 30, to = 31) }
)
public abstract class AppDatabase extends RoomDatabase {
private static final String TAG = "AppDatabase";

View file

@ -33,7 +33,10 @@ public class Server implements Parcelable {
@ColumnInfo(name = "timestamp")
private long timestamp;
public Server(@NonNull String serverId, String serverName, String username, String address, String token, String salt, long timestamp) {
@ColumnInfo(name = "low_security", defaultValue = "false")
private boolean lowSecurity;
public Server(@NonNull String serverId, String serverName, String username, String address, String token, String salt, long timestamp, boolean lowSecurity) {
this.serverId = serverId;
this.serverName = serverName;
this.username = username;
@ -41,6 +44,7 @@ public class Server implements Parcelable {
this.token = token;
this.salt = salt;
this.timestamp = timestamp;
this.lowSecurity = lowSecurity;
}
@NonNull
@ -100,6 +104,14 @@ public class Server implements Parcelable {
this.timestamp = timestamp;
}
public boolean isLowSecurity() {
return lowSecurity;
}
public void setLowSecurity(boolean lowSecurity) {
this.lowSecurity = lowSecurity;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View file

@ -100,7 +100,7 @@ public class Subsonic {
public String getUrl() {
String url = preferences.getServerUrl() + "/rest/";
return url.replace("//rest","/rest");
return url.replace("//rest", "/rest");
}
public Map<String, String> getParams() {
@ -112,6 +112,8 @@ public class Subsonic {
params.put("c", preferences.getClientName());
params.put("f", "xml");
if (preferences.getPassword() != null && !preferences.getPassword().trim().equals("")) params.put("p", preferences.getPassword());
return params;
}
}

View file

@ -7,6 +7,7 @@ import java.util.UUID;
public class SubsonicPreferences {
private String serverUrl;
private String username;
private String password;
private String clientName = "Play";
private SubsonicAuthentication authentication;
@ -18,6 +19,10 @@ public class SubsonicPreferences {
return username;
}
public String getPassword() {
return password;
}
public String getClientName() {
return clientName;
}
@ -34,6 +39,10 @@ public class SubsonicPreferences {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}

View file

@ -41,6 +41,7 @@ public class ServerSignupDialog extends DialogFragment {
private String password;
private String server;
private boolean directAccess = false;
private boolean lowSecurity = false;
@NonNull
@Override
@ -90,7 +91,10 @@ public class ServerSignupDialog extends DialogFragment {
bind.passwordTextView.setText("");
bind.serverTextView.setText(loginViewModel.getServerToEdit().getAddress());
bind.directAccessCheckbox.setChecked(false);
bind.lowSecurityCheckbox.setChecked(loginViewModel.getServerToEdit().isLowSecurity());
}
} else {
loginViewModel.setServerToEdit(null);
}
}
@ -115,6 +119,7 @@ public class ServerSignupDialog extends DialogFragment {
password = Objects.requireNonNull(bind.passwordTextView.getText()).toString();
server = Objects.requireNonNull(bind.serverTextView.getText()).toString().trim();
directAccess = bind.directAccessCheckbox.isChecked();
lowSecurity = bind.lowSecurityCheckbox.isChecked();
if (TextUtils.isEmpty(serverName)) {
bind.serverNameTextView.setError(getString(R.string.error_required));
@ -162,14 +167,13 @@ public class ServerSignupDialog extends DialogFragment {
if (token != null && salt != null) {
String serverID = loginViewModel.getServerToEdit() != null ? loginViewModel.getServerToEdit().getServerId() : UUID.randomUUID().toString();
PreferenceUtil.getInstance(context).setPassword(null);
PreferenceUtil.getInstance(context).setToken(token);
PreferenceUtil.getInstance(context).setSalt(salt);
PreferenceUtil.getInstance(context).setServerId(serverID);
loginViewModel.addServer(new Server(serverID, this.serverName, this.username, this.server, token, salt, System.currentTimeMillis()));
if (!lowSecurity) PreferenceUtil.getInstance(context).setPassword(null);
return;
loginViewModel.addServer(new Server(serverID, this.serverName, this.username, this.server, token, salt, System.currentTimeMillis(), this.lowSecurity));
}
App.getSubsonicClientInstance(context, true);

View file

@ -60,8 +60,6 @@
app:endIconTint="?android:textColorSecondary"
app:errorEnabled="true">
<!-- Navidrome android:text="!$4EBXhSPUi4$E#oagvAisCA" -->
<!-- Gonic android:text="hYP3%yD!rx@GBf95B2wbRUk8" -->
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password_text_view"
android:layout_width="match_parent"
@ -101,4 +99,12 @@
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="@string/server_signup_dialog_action_direct_access"/>
<CheckBox
android:id="@+id/low_security_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="@string/server_signup_dialog_action_low_security"/>
</LinearLayout>

View file

@ -198,4 +198,5 @@
<string name="starred_sync_dialog_title">Sync starred tracks</string>
<string name="settings_title_transcoding">Transcoding</string>
<string name="settings_summary_transcoding">Priority given to the transcoding mode. If set to \"Direct play\" the bitrate of the file will not be changed.</string>
<string name="server_signup_dialog_action_low_security">Low security</string>
</resources>