Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

LogoutHandler not called after changing the configuration to lambdas

In my SpringBoot-App, I am using an implementation of a Logout-handler to put together a redirect-uri. Since the method logout() (without parameters) of HttpSecurity has been deprecated, I am attempting to configure the logout with lambdas. In my eyes, it should do the same, the behaviour however turns out to be different.

The logout handler looks like this:

public class MyCustomLogoutHandler implements LogoutHandler{

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) {
        try {
            response.sendRedirect(assembleUri());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}

Old (and working) config:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

httpSecurity.logout()
    .logoutUrl("/sso/logout")
    .permitAll()
    .addLogoutHandler(new MyCustomLogoutHandler());

I changed it into the following:

httpSecurity.logout(config -> config.logoutUrl("sso/logout")
    .permitAll()
    .addLogoutHandler(new MyCustomLogoutHandler()));

But now, the method "logout" is not called anymore and i end up in a 404.

What could be the mistake here?

>Solution :

Missing "/" in Logout URL:

In the lambda configuration, you’ve used .logoutUrl("sso/logout"). Make sure that the URL should begin with a "/" to be treated as an absolute URL path. So, it should be .logoutUrl("/sso/logout").

httpSecurity.logout(config -> config.logoutUrl("/sso/logout")
    .permitAll()
    .addLogoutHandler(new MyCustomLogoutHandler()));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading