diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/OidcUserManagementAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/OidcUserManagementAutoConfiguration.java index 907751a36..bf3c64322 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/OidcUserManagementAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/OidcUserManagementAutoConfiguration.java @@ -93,9 +93,7 @@ public class OidcUserManagementAutoConfiguration { */ @Bean public LogoutSuccessHandler oidcLogoutSuccessHandler() { - SimpleUrlLogoutSuccessHandler logoutSuccessHandler = new SimpleUrlLogoutSuccessHandler(); - logoutSuccessHandler.setDefaultTargetUrl("/"); - return logoutSuccessHandler; + return new OidcLogoutSuccessHandler(); } /** @@ -226,6 +224,24 @@ class OidcLogoutHandler extends SecurityContextLogoutHandler { } } +/** + * LogoutSuccessHandler that decides where to redirect to after logout, depending on + * the previously used auth mechanism + */ +class OidcLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler { + + @Override + public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) + throws IOException, ServletException { + if (authentication instanceof OAuth2AuthenticationToken) { + this.setTargetUrlParameter("/"); + } else { + this.setTargetUrlParameter("login"); + } + super.onLogoutSuccess(request, response, authentication); + } +} + /** * Utility class to extract authorities out of the jwt. It interprets the user's * role as their authorities.