hr.diskobolos.config.security.authentication.CustomLogoutHandler.java Source code

Java tutorial

Introduction

Here is the source code for hr.diskobolos.config.security.authentication.CustomLogoutHandler.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package hr.diskobolos.config.security.authentication;

import hr.diskobolos.service.IUserService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;

/**
 * Custom logout handler class
 *
 * @author Tomislav avka
 */
@Component
public class CustomLogoutHandler implements LogoutHandler {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IUserService userService;

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        Integer userId = Integer.valueOf(request.getParameter("userId"));
        logger.info("Prelogut actions for user with ID: " + userId);
        userService.preLogoutActions(userId);
        response.setStatus(HttpServletResponse.SC_OK);
    }
}