List of usage examples for org.springframework.security.web.session HttpSessionDestroyedEvent getSecurityContexts
@SuppressWarnings("unchecked") @Override public List<SecurityContext> getSecurityContexts()
From source file:com.cruz.sec.config.SessionExpirationFilter.java
@Override public void onApplicationEvent(HttpSessionDestroyedEvent event) { List<org.springframework.security.core.context.SecurityContext> lstSecurityContext = event .getSecurityContexts();// w ww.j a v a2s . c om UserDetails ud; for (org.springframework.security.core.context.SecurityContext securityContext : lstSecurityContext) { ud = (UserDetails) securityContext.getAuthentication().getPrincipal(); System.out.println("OBJECTO SESION DESTRUIDO: " + ud.toString()); HttpSession httpSession = event.getSession(); // long createdTime = httpSession.getCreationTime(); long lastAccessedTime = httpSession.getLastAccessedTime(); int maxInactiveTime = httpSession.getMaxInactiveInterval(); long currentTime = System.currentTimeMillis(); // System.out.println("Session Id :"+httpSession.getId() ); // System.out.println("Created Time : " + createdTime); // System.out.println("Last Accessed Time : " + lastAccessedTime); // System.out.println("Current Time : " + currentTime); boolean possibleSessionTimeout = (currentTime - lastAccessedTime) >= (maxInactiveTime * 1000); if (possibleSessionTimeout) { System.out.println("SESIN CERRADA POR INACTIVIDAD"); //Se realiza la peticin al Node JS // requestNodeJS.sendRequestWithUsernameAndMethod(ud.getUsername(), "/session-close"); } } }
From source file:com.gs.config.SessionExpirationFilter.java
@Override public void onApplicationEvent(HttpSessionDestroyedEvent event) { List<org.springframework.security.core.context.SecurityContext> lstSecurityContext = event .getSecurityContexts();/* w ww .j a v a 2 s . c om*/ UserDetails ud; for (org.springframework.security.core.context.SecurityContext securityContext : lstSecurityContext) { ud = (UserDetails) securityContext.getAuthentication().getPrincipal(); System.out.println("SESIN DESTRUIDA: " + ud.toString()); HttpSession httpSession = event.getSession(); // long createdTime = httpSession.getCreationTime(); long lastAccessedTime = httpSession.getLastAccessedTime(); int maxInactiveTime = httpSession.getMaxInactiveInterval(); long currentTime = System.currentTimeMillis(); // System.out.println("Session Id :"+httpSession.getId() ); // System.out.println("Created Time : " + createdTime); // System.out.println("Last Accessed Time : " + lastAccessedTime); // System.out.println("Current Time : " + currentTime); boolean possibleSessionTimeout = (currentTime - lastAccessedTime) >= (maxInactiveTime * 1000); if (possibleSessionTimeout) { //Se realiza la peticin al Node JS // requestNodeJS.sendRequestWithUsernameAndMethod(ud.getUsername(), "/session-close"); } // System.out.println("Possbile Timeout : " + possibleSessionTimeout); } }