/*
 * 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 httpauthenticationmechanism;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import controller.person.PersonController;


/**
 *
 * @author Patrick
 */
@WebListener
public class LogoutListener implements HttpSessionListener{
    final static Logger LOGGER = LogManager.getLogger(LogoutListener.class);
    
    @Override
    public void sessionCreated(HttpSessionEvent event) {
        // NOOP.
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        LOGGER.info("Session destroyed");
        PersonController userManager = (PersonController) event.getSession().getAttribute("user");
        String username = (String) event.getSession().getAttribute("realUsername");
        if (userManager != null && username != null) {
            LOGGER.info("not nulls");
            userManager.getLogins().remove(username);
        }
    }
}
