From: Tobias Brunner Date: Tue, 4 Feb 2025 14:33:33 +0000 (+0100) Subject: android: Allow setting the password in managed profiles X-Git-Tag: android-2.5.3^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4f808cb2b0cab9b022c50e0534bf95843e4c50d6;p=thirdparty%2Fstrongswan.git android: Allow setting the password in managed profiles To avoid complicated changes in the UI, users can still update it. But the default, if they clear the field, will be the managed password. --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/data/ManagedVpnProfile.java b/src/frontends/android/app/src/main/java/org/strongswan/android/data/ManagedVpnProfile.java index 054dde19f6..5dc7b7744a 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/data/ManagedVpnProfile.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/data/ManagedVpnProfile.java @@ -135,6 +135,7 @@ public class ManagedVpnProfile extends VpnProfile setLocalId(local.getString(VpnProfileDataSource.KEY_LOCAL_ID)); setUsername(local.getString(VpnProfileDataSource.KEY_USERNAME)); + setPassword(local.getString(VpnProfileDataSource.KEY_PASSWORD)); final String userCertificateData = local.getString(VpnProfileDataSource.KEY_USER_CERTIFICATE); final String userCertificatePassword = local.getString(VpnProfileDataSource.KEY_USER_CERTIFICATE_PASSWORD, ""); diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileManagedDataSource.java b/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileManagedDataSource.java index a76241b4e5..0f6ec6292d 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileManagedDataSource.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileManagedDataSource.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2025 Tobias Brunner * Copyright (C) 2023 Relution GmbH * * Copyright (C) secunet Security Networks AG @@ -75,17 +76,14 @@ public class VpnProfileManagedDataSource implements VpnProfileDataSource @Override public boolean updateVpnProfile(VpnProfile profile) { - final VpnProfile existingProfile = getVpnProfile(profile.getUUID()); - if (existingProfile == null) + final VpnProfile managedProfile = mManagedConfigurationService.getManagedProfiles().get(profile.getUUID().toString()); + if (managedProfile == null) { return false; } - final String password = profile.getPassword(); - existingProfile.setPassword(password); - final SharedPreferences.Editor editor = mSharedPreferences.edit(); - editor.putString(profile.getUUID().toString(), password); + editor.putString(profile.getUUID().toString(), profile.getPassword()); return editor.commit(); } @@ -95,17 +93,28 @@ public class VpnProfileManagedDataSource implements VpnProfileDataSource return false; } + /** + * Clone and prepare the given managed profile before handing it out. + * @param managedProfile profile to prepare + */ + private VpnProfile prepareVpnProfile(VpnProfile managedProfile) + { + final String password = mSharedPreferences.getString(managedProfile.getUUID().toString(), managedProfile.getPassword()); + final VpnProfile vpnProfile = managedProfile.clone(); + vpnProfile.setPassword(password); + vpnProfile.setDataSource(this); + return vpnProfile; + } + @Override public VpnProfile getVpnProfile(UUID uuid) { - final VpnProfile vpnProfile = mManagedConfigurationService.getManagedProfiles().get(uuid.toString()); - if (vpnProfile != null) + final VpnProfile managedProfile = mManagedConfigurationService.getManagedProfiles().get(uuid.toString()); + if (managedProfile != null) { - final String password = mSharedPreferences.getString(uuid.toString(), vpnProfile.getPassword()); - vpnProfile.setPassword(password); - vpnProfile.setDataSource(this); + return prepareVpnProfile(managedProfile); } - return vpnProfile; + return null; } @Override @@ -113,12 +122,9 @@ public class VpnProfileManagedDataSource implements VpnProfileDataSource { final Map managedVpnProfiles = mManagedConfigurationService.getManagedProfiles(); final List vpnProfiles = new ArrayList<>(); - for (final VpnProfile vpnProfile : managedVpnProfiles.values()) + for (final VpnProfile managedProfile : managedVpnProfiles.values()) { - final String password = mSharedPreferences.getString(vpnProfile.getUUID().toString(), vpnProfile.getPassword()); - vpnProfile.setPassword(password); - vpnProfile.setDataSource(this); - vpnProfiles.add(vpnProfile); + vpnProfiles.add(prepareVpnProfile(managedProfile)); } return vpnProfiles; } diff --git a/src/frontends/android/app/src/main/res/values-de/strings_managed_configuration.xml b/src/frontends/android/app/src/main/res/values-de/strings_managed_configuration.xml index b64f5461cf..74e59cfe7d 100644 --- a/src/frontends/android/app/src/main/res/values-de/strings_managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/values-de/strings_managed_configuration.xml @@ -85,6 +85,8 @@ Specifies information about the client Identity/username for EAP authentication (Optional) If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it. If it is set, the user is not able to change it. In both cases the user may optionally enter the password + Password for EAP authentication (Optional) + If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it and may store it locally @string/profile_local_id_label @string/profile_local_id_hint_user @string/profile_user_certificate_label diff --git a/src/frontends/android/app/src/main/res/values-pl/strings_managed_configuration.xml b/src/frontends/android/app/src/main/res/values-pl/strings_managed_configuration.xml index b64f5461cf..74e59cfe7d 100644 --- a/src/frontends/android/app/src/main/res/values-pl/strings_managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/values-pl/strings_managed_configuration.xml @@ -85,6 +85,8 @@ Specifies information about the client Identity/username for EAP authentication (Optional) If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it. If it is set, the user is not able to change it. In both cases the user may optionally enter the password + Password for EAP authentication (Optional) + If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it and may store it locally @string/profile_local_id_label @string/profile_local_id_hint_user @string/profile_user_certificate_label diff --git a/src/frontends/android/app/src/main/res/values-ru/strings_managed_configuration.xml b/src/frontends/android/app/src/main/res/values-ru/strings_managed_configuration.xml index b64f5461cf..74e59cfe7d 100644 --- a/src/frontends/android/app/src/main/res/values-ru/strings_managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/values-ru/strings_managed_configuration.xml @@ -85,6 +85,8 @@ Specifies information about the client Identity/username for EAP authentication (Optional) If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it. If it is set, the user is not able to change it. In both cases the user may optionally enter the password + Password for EAP authentication (Optional) + If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it and may store it locally @string/profile_local_id_label @string/profile_local_id_hint_user @string/profile_user_certificate_label diff --git a/src/frontends/android/app/src/main/res/values-uk/strings_managed_configuration.xml b/src/frontends/android/app/src/main/res/values-uk/strings_managed_configuration.xml index b64f5461cf..74e59cfe7d 100644 --- a/src/frontends/android/app/src/main/res/values-uk/strings_managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/values-uk/strings_managed_configuration.xml @@ -85,6 +85,8 @@ Specifies information about the client Identity/username for EAP authentication (Optional) If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it. If it is set, the user is not able to change it. In both cases the user may optionally enter the password + Password for EAP authentication (Optional) + If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it and may store it locally @string/profile_local_id_label @string/profile_local_id_hint_user @string/profile_user_certificate_label diff --git a/src/frontends/android/app/src/main/res/values-zh-rCN/strings_managed_configuration.xml b/src/frontends/android/app/src/main/res/values-zh-rCN/strings_managed_configuration.xml index b64f5461cf..74e59cfe7d 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rCN/strings_managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rCN/strings_managed_configuration.xml @@ -85,6 +85,8 @@ Specifies information about the client Identity/username for EAP authentication (Optional) If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it. If it is set, the user is not able to change it. In both cases the user may optionally enter the password + Password for EAP authentication (Optional) + If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it and may store it locally @string/profile_local_id_label @string/profile_local_id_hint_user @string/profile_user_certificate_label diff --git a/src/frontends/android/app/src/main/res/values-zh-rTW/strings_managed_configuration.xml b/src/frontends/android/app/src/main/res/values-zh-rTW/strings_managed_configuration.xml index b64f5461cf..74e59cfe7d 100644 --- a/src/frontends/android/app/src/main/res/values-zh-rTW/strings_managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/values-zh-rTW/strings_managed_configuration.xml @@ -85,6 +85,8 @@ Specifies information about the client Identity/username for EAP authentication (Optional) If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it. If it is set, the user is not able to change it. In both cases the user may optionally enter the password + Password for EAP authentication (Optional) + If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it and may store it locally @string/profile_local_id_label @string/profile_local_id_hint_user @string/profile_user_certificate_label diff --git a/src/frontends/android/app/src/main/res/values/strings_managed_configuration.xml b/src/frontends/android/app/src/main/res/values/strings_managed_configuration.xml index b64f5461cf..74e59cfe7d 100644 --- a/src/frontends/android/app/src/main/res/values/strings_managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/values/strings_managed_configuration.xml @@ -85,6 +85,8 @@ Specifies information about the client Identity/username for EAP authentication (Optional) If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it. If it is set, the user is not able to change it. In both cases the user may optionally enter the password + Password for EAP authentication (Optional) + If this is required (for username/password-based EAP authentication) but not configured here, the user is prompted for it and may store it locally @string/profile_local_id_label @string/profile_local_id_hint_user @string/profile_user_certificate_label diff --git a/src/frontends/android/app/src/main/res/xml/managed_configuration.xml b/src/frontends/android/app/src/main/res/xml/managed_configuration.xml index 105b3f8398..e86ad721ed 100644 --- a/src/frontends/android/app/src/main/res/xml/managed_configuration.xml +++ b/src/frontends/android/app/src/main/res/xml/managed_configuration.xml @@ -176,6 +176,13 @@ android:restrictionType="string" android:title="@string/managed_config_local_eap_id_title" /> + +