Skip to content

Commit 69cd9c9

Browse files
authored
Make sure to clear cookies on logout (#5727)
* Ensure to clear the cookies when logging out It turns out that we failed to clear the cookies from the cookie JAR when logging the user out. As a consequence, the cookie were retained and it was possible to edit depictions as the previous user even without logging in to the app (using the retained cookies). Make sure we properly clear the cookies when we log the user out. As an aside, the fact that the edit button shouldn't have been shown is a different issue being tracked in #5726 * session: reuse removeAccount method for log out The removeAccount method takes care of invoking the non-deprecated API in applicable API levels. The logout method did not do such a thing. Avoid redundancy, and reuse the removeAccount method for logging out.
1 parent 1808699 commit 69cd9c9

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

app/src/main/java/fr/free/nrw/commons/CommonsApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ public void clearApplicationData(Context context, LogoutListener logoutListener)
294294
}
295295

296296
sessionManager.logout()
297+
.andThen(Completable.fromAction(() -> cookieJar.clear()))
297298
.andThen(Completable.fromAction(() -> {
298299
Timber.d("All accounts have been removed");
299300
clearImageCache();

app/src/main/java/fr/free/nrw/commons/auth/SessionManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@ public void forceLogin(Context context) {
122122
}
123123

124124
/**
125-
* 1. Clears existing accounts from account manager
126-
* 2. Calls MediaWikiApi's logout function to clear cookies
127-
* @return
125+
* Returns a Completable that clears existing accounts from account manager
128126
*/
129127
public Completable logout() {
130-
AccountManager accountManager = AccountManager.get(context);
131-
Account[] allAccounts = accountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE);
132-
return Completable.fromObservable(Observable.fromArray(allAccounts)
133-
.map(a -> accountManager.removeAccount(a, null, null).getResult()))
134-
.doOnComplete(() -> {
135-
currentAccount = null;
136-
});
128+
return Completable.fromObservable(
129+
Observable.empty()
130+
.doOnComplete(
131+
() -> {
132+
removeAccount();
133+
currentAccount = null;
134+
}
135+
)
136+
);
137137
}
138138

139139
/**

app/src/main/java/fr/free/nrw/commons/auth/csrf/CsrfTokenClient.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import fr.free.nrw.commons.auth.login.LoginResult
1010
import retrofit2.Call
1111
import retrofit2.Response
1212
import timber.log.Timber
13-
import java.io.IOException
1413
import java.util.concurrent.Callable
1514
import java.util.concurrent.Executors.newSingleThreadExecutor
1615

app/src/main/java/fr/free/nrw/commons/wikidata/cookies/CommonsCookieJar.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,9 @@ class CommonsCookieJar(private val cookieStorage: CommonsCookieStorage) : Cookie
9595

9696
private fun Cookie.domainSpec(url: HttpUrl): String =
9797
domain.ifEmpty { url.toUri().getAuthority() }
98+
99+
fun clear() {
100+
cookieStorage.clear()
101+
}
102+
98103
}

0 commit comments

Comments
 (0)