2017-03-07 4 views
1

私はSpring Securityを使用していますが、ログイン中にフレームワークの異常な動作が検出されました。 Spring Security WebAuthenticationDetailsは、HTTPリクエストから取得しているパラメータsessionIdを持っていますが、すべてが良いはずですが、実際にはRESTリクエストによって別のセッションIDが返されます。 HttpSessionをautowireしてからセッションIDを取得すると、私はSpringのようなIDを取得します。だから、1人のユーザーに2つのIDがあるようです。それが正しいか?または私は何かを逃した?Autowiring HttpSessionはHttpServletRequestとは異なるオブジェクトを返します

EDITED:このクラスの意志は、この方法が与える

public class AuthenticationEventListener implements ApplicationListener<AbstractAuthenticationEvent> { 

    @Autowired 
    HttpSession httpSession; 

    @Override 
    public void onApplicationEvent(AbstractAuthenticationEvent event) { 
     if (event instanceof AuthenticationSuccessEvent) { 
      LoggedUser loggedUser = (LoggedUser) event.getAuthentication().getPrincipal(); 
      loggedUser.initSessionParams(event.getAuthentication()); 
      String sessionId = httpSession.getId(); 
     } 
    } 
} 

と、いくつかのセッションIDを与え例えば

別の1:

@RequestMapping(value = "/chart") 
public Map getTestStatusesChart(HttpServletRequest request) { 
    String sessionId= request.getSession(false).getId(); 
    return null; 
} 

答えて

0

だから、答えは次である:とセキュリティの条件SpringはデフォルトでセッションIDを変更します。このような動作を防ぐには、Spring Securityの設定でセッション固定保護を無効にする必要があります。詳細情報link

関連する問題