2016-10-16 5 views
0

を覚えている:春のセキュリティは:私は、オブジェクトのアカウントを持っている私とセッションデータ

public class Account { 
    String name; 
    List<Car> cars; 
} 

私は(カスタム認証プロバイダで)ログイン時に車を投入して、セッションにアカウントを保存します。それから私はブラウザを閉じます。私は再びそれを開くと、オブジェクトのアカウントは生きているが、車はnullです。同じセッションでオブジェクトのプロパティを保存する正しい方法は何ですか?ここで

は私のApplicationContext-のsecurity.xmlの抜粋です:

<http use-expressions="true" 
      authentication-manager-ref="authenticationManager" 
      auto-config="true" 
      create-session="ifRequired"> 
     <intercept-url pattern="/my/**" access="hasAnyRole('ROLE_USER','ROLE_ADMIN')"/> 
     <intercept-url pattern="/service/**" access="hasRole('ROLE_ADMIN')"/> 
     <form-login 
      login-page="/login" 
      authentication-failure-handler-ref="simpleUrlAuthenticationFailureHandler" 
      username-parameter="j_username" 
      password-parameter="j_password" 
      default-target-url="/home" 
      always-use-default-target="false"/> 
     <logout logout-success-url="/logout" invalidate-session="true" delete-cookies="JSESSIONID"/> 
     <http-basic /> 
     <remember-me key="uniqueAndSecret" 
      token-validity-seconds="1209600" 
      remember-me-cookie="edrive" 
      remember-me-parameter="_spring_security_remember_me" 
      user-service-ref="localUserService"/> 
    </http> 

とどのように私はアカウントを保存:

Account account = accountDao.getAccount(name, password); 
HttpSession session = httpUtilities.getSession(); // session from the HttpServletRequest 
account.setCars(domainUtilities.getAccountCars(account.getId())); 
session.setAttribute("account", account); 

春のセキュリティ4.1.3.RELEASE

UPDATE 1:私の調査によると、私が最初にログインすると、セッション中にアカウントオブジェクトが存続することがわかります:

SessionIdがnull -

org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository.CSRF_TOKEN [email protected] 
SPRING_SECURITY_CONTEXT [email protected]1c5848: Authentication: org.spring[email protected]5d1c5848: Principal: [email protected]: Username: someuser; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_USER 

をそして:

とのセッションも含まれています。私は、ブラウザを起動し

[email protected] 
SPRING_SECURITY_CONTEXT [email protected]e3a7b0: Authentication: org.springframew[email protected]a2e3a7b0: Principal: [email protected]: Username: someuser; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]ffff4c9c: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 0B7153F813D8F0B943C34EF19A7271C8; Granted Authorities: ROLE_USER 

次回は、Tomcatの8だけで新しいセッションを開きます。どうして? 2回目にアカウントにアクセスできないという理由はありますか?

答えて

0

問題は、標準チェーン(アプリケーションのWEB-APP/web.xmlで定義されている)に特別なフィルタを追加することで解決されています。ユーザーが認証され、アカウントがヌルであることを確認してから、必要なデータをリロードします。

第2セッションIDはnullです。これはcreate-session = "ifRequired"の問題でした。私はそれを「いつも」と置き換え、今では機能します。

関連する問題