2017-10-10 20 views
0

하는 방법은 사용자하여 Tomcat 컨테이너로그 아웃 링크 프레스에 의해세션 시간 제한 사이가 구별인가?사용자가 Tomcat 컨테이너와 로그 아웃 링크로 세션 시간 초과를 구별하는 방법은 무엇입니까?

EDIT1 :환경 세부 정보 : 자바 1.8, 내가 javax.servlet.http.HttpSessionListener

public class MyHttpSessionListener implements HttpSessionListener {   
    @Override 
    public void sessionCreated(HttpSessionEvent httpSessionEvent) { 
     System.out.println(httpSessionEvent.getSession().getId()+" was CREATED"); 
    } 

    @Override 
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { 
     System.out.println(httpSessionEvent.getSession().getId()+" was DESTROYED"); 
    } 
} 
를 구현하는 MyHttpSessionListener 클래스가 윈도우 서버 2012

아파치 톰캣 8.0.36

및내의 해당 구성 선언파일

<listener> 
    <listener-class>com.webapp.listeners.MyHttpSessionListener</listener-class> 
</listener> 

내 webapp에 Spring Security을 사용하고 있지 않습니다.

답변

1

HttpSessionListener은 서블릿 수준에서 처리 할 것입니다. 여기서 한 가지 중요한 질문은 어떤 Application/Web Server를 사용하고 있습니까? 당신은 SessionDestroyedEvent

@Component 
public class SessionEndedListener implements ApplicationListener<SessionDestroyedEvent> { 

    @Override 
    public void onApplicationEvent(SessionDestroyedEvent event) 
    { 
     for (SecurityContext securityContext : event.getSecurityContexts()) 
     { 
      Authentication authentication = securityContext.getAuthentication(); 
      YourPrincipalClass user = (YourPrincipalClass) authentication.getPrincipal(); 
      // do something 
     } 
    } 

} 

와 시도가 지금은 SessionDeletedEvent and SessionExpiredEvent
봐이 필요하고 당신은 또한 최근 한 web.xml

<listener> 
    <listener-class> 
     org.springframework.security.web.session.HttpSessionEventPublisher 
    </listener-class> 
</listener> 

업데이트 대답
이 등록해야 편집, 지금이 경우에 사용해야합니다.

HttpSessionBindingListener 


이 개체는 세션에서 개체가 제거 될 때 호출됩니다 (removeAttribute() 메서드가 명시 적으로 HTTPSession이거나 세션의 유효 기간 만료/만료에 의해). 고맙습니다 칸 (@Freak) 회신에 대한

+0

, 내 응용 프로그램에 대한 ** ** 미리 봄 보안을 사용하지 않는. 일반'Servlets'에서 세션 시간 초과의 원인을 감지하는 방법이 있습니까? 위의 ** EDIT1 **에서 환경 세부 정보를 업데이트했습니다. – Shiva

+0

당신은 편집하기 전에 질문에 명확하지 않았고 Spring-MVC라는 태그를 가지고 있었기 때문에 Spring에서 몇 가지 해결책을 찾고 있다고 생각했습니다. – Freak

+0

@Shiva 업데이트 된 답변보기 – Freak