diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-08-07 18:44:06 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-08-13 11:00:26 +0200 |
commit | b1340aa12959b28f103a4c58d7db578de717fd9c (patch) | |
tree | 3b5bcc70793b5f955cc8969f14cd21ad0aa20463 /src | |
parent | fcb5448017677999d956c652b2778f6a5e2435b8 (diff) | |
download | strongswan-b1340aa12959b28f103a4c58d7db578de717fd9c.tar.bz2 strongswan-b1340aa12959b28f103a4c58d7db578de717fd9c.tar.xz |
Prompt the user for a password if none is configured in the VPN profile
Diffstat (limited to 'src')
-rw-r--r-- | src/frontends/android/res/layout/login_dialog.xml | 51 | ||||
-rw-r--r-- | src/frontends/android/res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/frontends/android/src/org/strongswan/android/ui/MainActivity.java | 53 |
3 files changed, 107 insertions, 1 deletions
diff --git a/src/frontends/android/res/layout/login_dialog.xml b/src/frontends/android/res/layout/login_dialog.xml new file mode 100644 index 000000000..0262af0a3 --- /dev/null +++ b/src/frontends/android/res/layout/login_dialog.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2012 Tobias Brunner + Copyright (C) 2012 Giuliano Grassi + Copyright (C) 2012 Ralf Sager + Hochschule fuer Technik Rapperswil + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. +--> +<LinearLayout + android:layout_height="match_parent" + android:layout_width="match_parent" + android:orientation="vertical" + android:padding="5dp" + xmlns:android="http://schemas.android.com/apk/res/android"> + + <TextView + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/profile_username_label" + android:textStyle="bold" /> + + <EditText + android:layout_height="wrap_content" + android:layout_width="match_parent" + android:id="@+id/username" + android:enabled="false" + android:inputType="none" /> + + <TextView + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/profile_password_label" + android:textStyle="bold" /> + + <EditText + android:layout_height="wrap_content" + android:layout_width="match_parent" + android:id="@+id/password" + android:inputType="textPassword|textNoSuggestions" + android:singleLine="true" /> + +</LinearLayout> diff --git a/src/frontends/android/res/values/strings.xml b/src/frontends/android/res/values/strings.xml index f2db4a676..6e6fa3aa6 100644 --- a/src/frontends/android/res/values/strings.xml +++ b/src/frontends/android/res/values/strings.xml @@ -50,4 +50,8 @@ <string name="alert_text_nocertfound_title">No CA certificate selected</string> <string name="alert_text_nocertfound">Please select one or activate <i>Select automatically</i></string> + <!-- Dialogs --> + <string name="login_title">Enter password to connect</string> + <string name="login_confirm">Connect</string> + </resources> diff --git a/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java b/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java index 35f8c653f..7387dab8d 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java +++ b/src/frontends/android/src/org/strongswan/android/ui/MainActivity.java @@ -26,14 +26,23 @@ import org.strongswan.android.ui.VpnProfileListFragment.OnVpnProfileSelectedList import android.app.ActionBar; import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.net.VpnService; import android.os.AsyncTask; import android.os.Bundle; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; import android.view.Window; +import android.widget.EditText; public class MainActivity extends Activity implements OnVpnProfileSelectedListener { @@ -102,6 +111,8 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen { Intent intent = new Intent(this, CharonVpnService.class); intent.putExtra(VpnProfileDataSource.KEY_ID, activeProfile.getId()); + /* submit the password as the profile might not store one */ + intent.putExtra(VpnProfileDataSource.KEY_PASSWORD, activeProfile.getPassword()); this.startService(intent); } break; @@ -114,7 +125,14 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen public void onVpnProfileSelected(VpnProfile profile) { activeProfile = profile; - prepareVpnService(); + if (activeProfile.getPassword() == null) + { + new LoginDialog().show(getFragmentManager(), "LoginDialog"); + } + else + { + prepareVpnService(); + } } /** @@ -142,4 +160,37 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen setProgressBarIndeterminateVisibility(false); } } + + private class LoginDialog extends DialogFragment + { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) + { + LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.login_dialog, null); + EditText username = (EditText)view.findViewById(R.id.username); + username.setText(activeProfile.getUsername()); + final EditText password = (EditText)view.findViewById(R.id.password); + + Builder adb = new AlertDialog.Builder(MainActivity.this); + adb.setView(view); + adb.setTitle(getString(R.string.login_title)); + adb.setPositiveButton(R.string.login_confirm, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) + { + activeProfile.setPassword(password.getText().toString().trim()); + prepareVpnService(); + } + }); + adb.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) + { + dismiss(); + } + }); + return adb.create(); + } + } } |