]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Allow setting the password in managed profiles
authorTobias Brunner <tobias@strongswan.org>
Tue, 4 Feb 2025 14:33:33 +0000 (15:33 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 18 Feb 2025 13:12:43 +0000 (14:12 +0100)
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.

src/frontends/android/app/src/main/java/org/strongswan/android/data/ManagedVpnProfile.java
src/frontends/android/app/src/main/java/org/strongswan/android/data/VpnProfileManagedDataSource.java
src/frontends/android/app/src/main/res/values-de/strings_managed_configuration.xml
src/frontends/android/app/src/main/res/values-pl/strings_managed_configuration.xml
src/frontends/android/app/src/main/res/values-ru/strings_managed_configuration.xml
src/frontends/android/app/src/main/res/values-uk/strings_managed_configuration.xml
src/frontends/android/app/src/main/res/values-zh-rCN/strings_managed_configuration.xml
src/frontends/android/app/src/main/res/values-zh-rTW/strings_managed_configuration.xml
src/frontends/android/app/src/main/res/values/strings_managed_configuration.xml
src/frontends/android/app/src/main/res/xml/managed_configuration.xml

index 054dde19f61170bcbb5df075978c03368d835f1a..5dc7b7744a794d3d18b74f03559bbda982ebed86 100644 (file)
@@ -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, "");
index a76241b4e502e76fff254fda6c200464a429b8b4..0f6ec6292df3f6f3f6fc12fa7bf6a30a94be8f24 100644 (file)
@@ -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<String, ManagedVpnProfile> managedVpnProfiles = mManagedConfigurationService.getManagedProfiles();
                final List<VpnProfile> 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;
        }
index b64f5461cfc330a37d827e060f8b80b87ca90de3..74e59cfe7da7d85532d3ff5325b9a90c20d142ba 100644 (file)
@@ -85,6 +85,8 @@
     <string name="managed_config_local_bundle_description">Specifies information about the client</string>
     <string name="managed_config_local_eap_id_title">Identity/username for EAP authentication (Optional)</string>
     <string name="managed_config_local_eap_id_description">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</string>
+    <string name="managed_config_local_eap_password_title">Password for EAP authentication (Optional)</string>
+    <string name="managed_config_local_eap_password_description">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>
     <string name="managed_config_local_id_title">@string/profile_local_id_label</string>
     <string name="managed_config_local_id_description">@string/profile_local_id_hint_user</string>
     <string name="managed_config_local_p12_title">@string/profile_user_certificate_label</string>
index b64f5461cfc330a37d827e060f8b80b87ca90de3..74e59cfe7da7d85532d3ff5325b9a90c20d142ba 100644 (file)
@@ -85,6 +85,8 @@
     <string name="managed_config_local_bundle_description">Specifies information about the client</string>
     <string name="managed_config_local_eap_id_title">Identity/username for EAP authentication (Optional)</string>
     <string name="managed_config_local_eap_id_description">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</string>
+    <string name="managed_config_local_eap_password_title">Password for EAP authentication (Optional)</string>
+    <string name="managed_config_local_eap_password_description">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>
     <string name="managed_config_local_id_title">@string/profile_local_id_label</string>
     <string name="managed_config_local_id_description">@string/profile_local_id_hint_user</string>
     <string name="managed_config_local_p12_title">@string/profile_user_certificate_label</string>
index b64f5461cfc330a37d827e060f8b80b87ca90de3..74e59cfe7da7d85532d3ff5325b9a90c20d142ba 100644 (file)
@@ -85,6 +85,8 @@
     <string name="managed_config_local_bundle_description">Specifies information about the client</string>
     <string name="managed_config_local_eap_id_title">Identity/username for EAP authentication (Optional)</string>
     <string name="managed_config_local_eap_id_description">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</string>
+    <string name="managed_config_local_eap_password_title">Password for EAP authentication (Optional)</string>
+    <string name="managed_config_local_eap_password_description">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>
     <string name="managed_config_local_id_title">@string/profile_local_id_label</string>
     <string name="managed_config_local_id_description">@string/profile_local_id_hint_user</string>
     <string name="managed_config_local_p12_title">@string/profile_user_certificate_label</string>
index b64f5461cfc330a37d827e060f8b80b87ca90de3..74e59cfe7da7d85532d3ff5325b9a90c20d142ba 100644 (file)
@@ -85,6 +85,8 @@
     <string name="managed_config_local_bundle_description">Specifies information about the client</string>
     <string name="managed_config_local_eap_id_title">Identity/username for EAP authentication (Optional)</string>
     <string name="managed_config_local_eap_id_description">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</string>
+    <string name="managed_config_local_eap_password_title">Password for EAP authentication (Optional)</string>
+    <string name="managed_config_local_eap_password_description">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>
     <string name="managed_config_local_id_title">@string/profile_local_id_label</string>
     <string name="managed_config_local_id_description">@string/profile_local_id_hint_user</string>
     <string name="managed_config_local_p12_title">@string/profile_user_certificate_label</string>
index b64f5461cfc330a37d827e060f8b80b87ca90de3..74e59cfe7da7d85532d3ff5325b9a90c20d142ba 100644 (file)
@@ -85,6 +85,8 @@
     <string name="managed_config_local_bundle_description">Specifies information about the client</string>
     <string name="managed_config_local_eap_id_title">Identity/username for EAP authentication (Optional)</string>
     <string name="managed_config_local_eap_id_description">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</string>
+    <string name="managed_config_local_eap_password_title">Password for EAP authentication (Optional)</string>
+    <string name="managed_config_local_eap_password_description">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>
     <string name="managed_config_local_id_title">@string/profile_local_id_label</string>
     <string name="managed_config_local_id_description">@string/profile_local_id_hint_user</string>
     <string name="managed_config_local_p12_title">@string/profile_user_certificate_label</string>
index b64f5461cfc330a37d827e060f8b80b87ca90de3..74e59cfe7da7d85532d3ff5325b9a90c20d142ba 100644 (file)
@@ -85,6 +85,8 @@
     <string name="managed_config_local_bundle_description">Specifies information about the client</string>
     <string name="managed_config_local_eap_id_title">Identity/username for EAP authentication (Optional)</string>
     <string name="managed_config_local_eap_id_description">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</string>
+    <string name="managed_config_local_eap_password_title">Password for EAP authentication (Optional)</string>
+    <string name="managed_config_local_eap_password_description">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>
     <string name="managed_config_local_id_title">@string/profile_local_id_label</string>
     <string name="managed_config_local_id_description">@string/profile_local_id_hint_user</string>
     <string name="managed_config_local_p12_title">@string/profile_user_certificate_label</string>
index b64f5461cfc330a37d827e060f8b80b87ca90de3..74e59cfe7da7d85532d3ff5325b9a90c20d142ba 100644 (file)
@@ -85,6 +85,8 @@
     <string name="managed_config_local_bundle_description">Specifies information about the client</string>
     <string name="managed_config_local_eap_id_title">Identity/username for EAP authentication (Optional)</string>
     <string name="managed_config_local_eap_id_description">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</string>
+    <string name="managed_config_local_eap_password_title">Password for EAP authentication (Optional)</string>
+    <string name="managed_config_local_eap_password_description">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>
     <string name="managed_config_local_id_title">@string/profile_local_id_label</string>
     <string name="managed_config_local_id_description">@string/profile_local_id_hint_user</string>
     <string name="managed_config_local_p12_title">@string/profile_user_certificate_label</string>
index 105b3f83980ce36a28206817daf724f148724616..e86ad721edce5711c0f9bf6856f8229dd1559c66 100644 (file)
                     android:restrictionType="string"
                     android:title="@string/managed_config_local_eap_id_title" />
 
+                <restriction
+                    android:defaultValue=""
+                    android:description="@string/managed_config_local_eap_password_description"
+                    android:key="password"
+                    android:restrictionType="string"
+                    android:title="@string/managed_config_local_eap_password_title" />
+
                 <restriction
                     android:defaultValue=""
                     android:description="@string/managed_config_local_id_description"