4

HttpSessionユーザー認証が成功した後にオブジェクトを追加したい。SavedRequestAwareAuthenticationSuccessHandlerこのアプリでは何らかの理由でアプリケーションが元のリクエストを無視しているため、解決策を提案しないでください。

public class AuthenticationSuccessListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> {
    @Override
    public void onApplicationEvent(InteractiveAuthenticationSuccessEvent e) {
        //adding object to HttpSession
    }
} 
4

1 に答える 1

10

私の知る限り、ApplicationListenerインスタンスは .xml 内の単なる BeanApplicationContextです。したがって、他の Bean またはリソースをそれらに注入できるはずです。

したがって、現在のHttpSessionインスタンスへの参照を取得するには:

public class AuthenticationSuccessListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> {

@Autowired
private HttpSession httpSession;

        @Override
        public void onApplicationEvent(InteractiveAuthenticationSuccessEvent e) {
               //adding object to HttpSession
        }
}

Spring は、スコープ指定されたプロキシ メカニズムHttpSessionを使用してを挿入し、現在の実行スレッドに関連するものを確実に取得します。HTTPSession

またRequestContextListener、Spring が現在のHTTPSession.

<listener>  
   <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>  
</listener>
于 2013-11-05T17:43:53.043 に答える