6

私は春を学んでいます。ログイン/ログアウト機能を実行します。これは私のコントローラーがどのように見えるかです:

@RequestMapping(value="/successfulLoginAuth", method=RequestMethod.GET)
public ModelAndView postHttpLogin(HttpSession session, Authentication authInfo) 
{

ModelAndView mav = new ModelAndView();
mav.setViewName("redirect:/index.html");
session.setAttribute("authInfo", authInfo);

return mav;

}

ログインは、私が実装した dao サービスを使用して Spring Security 経由で実行されます。それはうまくいきます。

これは、index.jsp の内容です。

<% 
    HttpSession session1 = request.getSession(false);
    Authentication authInfo; 
    if( (session1 != null) && 
        ( (authInfo = (Authentication)session1.getAttribute("authInfo")) != null) 
      )
    {

        out.print(" yo " + authInfo.getName() + " " + authInfo.getAuthorities().iterator().next().getAuthority());
    }
    else
    {
%>    
<a href="${pageContext.request.contextPath}/registration">New? Sign Up!</a><br/>

<a href="${pageContext.request.contextPath}/login">Existing? Sign In!</a><br/>
<%} %>

ログインしてサーバーを再起動しても、ログインしたままです。サーバーの再起動後にセッション情報が失われることはありませんか? ブラウザを再起動すると、正常に動作します (つまり、セッション情報が失われます)。

これは私のSpring Security構成です:

<http auto-config="true"  use-expressions="true">
        <intercept-url pattern="/" access="permitAll" />
        <intercept-url pattern="/logout" access="permitAll" />
        <intercept-url pattern="/accessdenied" access="permitAll" />
        <form-login login-page="/login" default-target-url="/successfulLoginAuth" authentication-failure-url="/accessdenied" />
        <logout logout-success-url="/logout" />
    </http>

<authentication-manager>
    <authentication-provider user-service-ref="myUserDetailsService"></authentication-provider>
  </authentication-manager>
4

2 に答える 2

11

TomcatManager コンポーネントを使用して、アプリケーションのライフサイクル間でセッションを永続化する を使用していると想定しています。これらの設定はすべてManager コンポーネント構成で変更できます。

変化の種類にもよると思います。Tomcat サーバー用の Eclipse のプラグインは、シリアル化された s をフラッシュするかどうかを決定しますHttpSession

于 2013-09-27T13:52:56.223 に答える