Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement special logout url for linked accounts feature (#19435) #19454

Open
wants to merge 1 commit into
base: 2.41
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import static com.google.common.base.Strings.isNullOrEmpty;
import static org.hisp.dhis.external.conf.ConfigurationKey.LINKED_ACCOUNTS_ENABLED;
import static org.hisp.dhis.external.conf.ConfigurationKey.LINKED_ACCOUNTS_LOGOUT_URL;
import static org.hisp.dhis.external.conf.ConfigurationKey.LINKED_ACCOUNTS_RELOGIN_URL;
import static org.hisp.dhis.external.conf.ConfigurationKey.OIDC_LOGOUT_REDIRECT_URL;
import static org.hisp.dhis.external.conf.ConfigurationKey.OIDC_OAUTH2_LOGIN_ENABLED;
Expand Down Expand Up @@ -101,15 +102,22 @@ private void handleLinkedAccountsLogout(
HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {

String currentUsername = request.getParameter("current");
String usernameToSwitchTo = request.getParameter("switch");
String linkedAccountsLogoutUrl = config.getProperty(LINKED_ACCOUNTS_LOGOUT_URL);
if (isNullOrEmpty(linkedAccountsLogoutUrl)) {
// Fallback if not defined in config
linkedAccountsLogoutUrl = "/";
}

if (isNullOrEmpty(currentUsername) || isNullOrEmpty(usernameToSwitchTo)) {
setOidcLogoutUrl();
if (isNullOrEmpty(usernameToSwitchTo)) {
// No switch parameter present: redirect to linked_accounts.logout_url
this.handler.setDefaultTargetUrl(linkedAccountsLogoutUrl);
} else {

userStore.setActiveLinkedAccounts(currentUsername, usernameToSwitchTo);

// switch parameter present: switch accounts and then redirect to re-login URL
String currentUsername = request.getParameter("current");
if (!isNullOrEmpty(currentUsername)) {
userStore.setActiveLinkedAccounts(currentUsername, usernameToSwitchTo);
}
this.handler.setDefaultTargetUrl(config.getProperty(LINKED_ACCOUNTS_RELOGIN_URL));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ public enum ConfigurationKey {
LINKED_ACCOUNTS_ENABLED("linked_accounts.enabled", Constants.OFF, false),

LINKED_ACCOUNTS_RELOGIN_URL("linked_accounts.relogin_url", "", false),

LINKED_ACCOUNTS_LOGOUT_URL("linked_accounts.logout_url", "", false),

SWITCH_USER_FEATURE_ENABLED("switch_user_feature.enabled", Constants.OFF, false),
SWITCH_USER_ALLOW_LISTED_IPS(
"switch_user_allow_listed_ips", "localhost,127.0.0.1,[0:0:0:0:0:0:0:1]", false),
Expand Down
Loading