Authentication object is null in custom logout handler

Viewed 62

I am trying to add a custom logout handler in my spring boot application, I want to perform few modifications to the user's data in DB before logging the user out.

    @Service
    public class CustomLogoutHandler implements LogoutHandler {

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        if (authentication != null) {
            // perform modifications to user's data in DB
            new SecurityContextLogoutHandler().logout(request, response, authentication);
        }
    }
    }

and in SecurityConfig i have configured the handler like this.

    .logout()
    .addLogoutHandler(customLogoutHandler)
    .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK))
    .permitAll()

to perform modifications on the user's data in DB I need to know who the user is from Authentication object, but it's always coming as null. What can be the reason behind this, am i doing any configuration incorrectly? TIA

0 Answers
Related