From 575ad75a0a1436cf2e9c3d841e8c01ef2970ced0 Mon Sep 17 00:00:00 2001 From: jendib Date: Tue, 10 May 2016 20:00:14 +0200 Subject: [PATCH] Closes #102: Android: Clear all auth tokens on logout --- docs-android/app/build.gradle | 2 +- .../java/com/sismics/docs/activity/MainActivity.java | 1 + .../java/com/sismics/docs/util/PreferenceUtil.java | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs-android/app/build.gradle b/docs-android/app/build.gradle index b99a5b46..062f5655 100644 --- a/docs-android/app/build.gradle +++ b/docs-android/app/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0-beta1' + classpath 'com.android.tools.build:gradle:2.1.0' } } apply plugin: 'com.android.application' diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java index 0c9232cb..e0db2430 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/MainActivity.java @@ -158,6 +158,7 @@ public class MainActivity extends AppCompatActivity { @Override public void onFinish() { // Force logout in all cases, so the user is not stuck in case of network error + PreferenceUtil.clearAuthToken(MainActivity.this); ApplicationContext.getInstance().setUserInfo(getApplicationContext(), null); startActivity(new Intent(MainActivity.this, LoginActivity.class)); finish(); diff --git a/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java b/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java index da8537ea..5df8974d 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java +++ b/docs-android/app/src/main/java/com/sismics/docs/util/PreferenceUtil.java @@ -126,6 +126,7 @@ public class PreferenceUtil { /** * Returns auth token cookie from shared preferences. * + * @param context Context * @return Auth token */ public static String getAuthToken(Context context) { @@ -140,6 +141,16 @@ public class PreferenceUtil { return null; } + /** + * Clear all auth tokens. + * + * @param context Context + */ + public static void clearAuthToken(Context context) { + PersistentCookieStore cookieStore = new PersistentCookieStore(context); + cookieStore.removeAll(); + } + /** * Returns cleaned server URL. *