2016-09-22 28 views
0

Wicket 1.4からWicket 6.20へ私たちのWebアプリケーションを移行するのはかなり止まっています。 また、Spring Securityをバージョン3.2.8.RELEASEに以前の(そして古い)バージョン2.0.4から移行しています。SessionManagementFilterがSessionAuthenticationStrategyを呼び出すことはありません

ここでは、春のセキュリティコンテキストのコンフィギュレーションのコピーです:

<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy"> 
    <security:filter-chain-map path-type="ant" > 
     <security:filter-chain request-matcher-ref="requestMatcher" 
       filters=" 
     securityContextPersistenceFilter, 
     concurrentSessionFilter,sessionManagementFilter" 
       pattern="/**" /> 
    </security:filter-chain-map> 
</bean> 

<beans:bean id="securityContextPersistenceFilter" 
    class="org.springframework.security.web.context.SecurityContextPersistenceFilter"> 
    <beans:constructor-arg ref="securityContextRepository"></beans:constructor-arg> 
</beans:bean> 

<beans:bean id="sessionManagementFilter" 
    class="org.springframework.security.web.session.SessionManagementFilter"> 
    <beans:constructor-arg ref="securityContextRepository"></beans:constructor-arg> 
    <beans:constructor-arg ref="sas"></beans:constructor-arg> 
</beans:bean> 

<beans:bean id="requestMatcher" class="org.springframework.security.web.util.matcher.AntPathRequestMatcher" > 
    <beans:constructor-arg value="/**"></beans:constructor-arg> 
</beans:bean> 

<beans:bean id="concurrentSessionFilter" 
    class="org.springframework.security.web.session.ConcurrentSessionFilter"> 
    <beans:constructor-arg ref="sessionRegistry" ></beans:constructor-arg> 
    <beans:constructor-arg value="/petrol/login" ></beans:constructor-arg> 
</beans:bean> 

<beans:bean id="sas" class="org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy"> 
    <beans:constructor-arg> 
    <beans:list> 
     <beans:bean class="org.springframework.security.web.authentication.session.ConcurrentSessionControlAuthenticationStrategy"> 
     <beans:constructor-arg ref="sessionRegistry"/> 
     <beans:property name="maximumSessions" value="1" /> 
     <beans:property name="exceptionIfMaximumExceeded" value="true" /> 
     </beans:bean> 
     <beans:bean class="org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy"> 
     </beans:bean> 
     <beans:bean class="org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy"> 
     <beans:constructor-arg ref="sessionRegistry"/> 
     </beans:bean> 
    </beans:list> 
    </beans:constructor-arg> 
</beans:bean> 

<beans:bean id="sessionRegistry" 
    class="org.springframework.security.core.session.SessionRegistryImpl" /> 

<beans:bean id="authenticationManager" 
    class="org.springframework.security.authentication.ProviderManager"> 
    <beans:property name="providers"> 
     <beans:list> 
      <beans:ref local="petrolAuthenticationProvider" /> 
     </beans:list> 
    </beans:property> 
</beans:bean> 

<beans:bean name='securityContextRepository' 
    class='org.springframework.security.web.context.HttpSessionSecurityContextRepository'> 
    <beans:property name='allowSessionCreation' value='true' /> 
</beans:bean> 

<beans:bean id="petrolAuthenticationProvider" 
    class="it.loginet.petrol.infrastructure.security.PetrolAuthenticationProvider"> 
    <beans:property name="utenteRepository" ref="utenteRepository" /> 
</beans:bean> 

SessionManagementFilterは、同時ログインをユーザーに許可されている場合のテスト、私たちの要求をフィルタリングする必要があります。 問題は、成功した認証を検証する場合、SecurityContextRepositoryにSecurityContextが既に含まれており、 "SessionAuthenticationStrategy.onAuthentication"メソッドが呼び出されないということです。 HttpSessionの上SPRING_SECURITY_KEY属性保存

 if (!securityContextRepository.containsContext(request)) { 
     Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 

     if (authentication != null && !trustResolver.isAnonymous(authentication)) { 
     // The user has been authenticated during the current request, so call the session strategy 
      try { 
       sessionAuthenticationStrategy.onAuthentication(authentication, request, response); 
      } catch (SessionAuthenticationException e) { 
       // The session strategy can reject the authentication 
       logger.debug("SessionAuthenticationStrategy rejected the authentication object", e); 
       SecurityContextHolder.clearContext(); 
       failureHandler.onAuthenticationFailure(request, response, e); 

       return; 
      } 
......... 

SaveToSessionResponseWrapperクラス、SessionManagementFilterはすでにのHttpSessionにこの属性を見つけ、実際に内部SessionAuthenticationStrategyの検証をスキップします。

マイグレーションで何が間違っているのですか?

答えて

2

OK、私は自分のアプリケーションでそれを使用していたとして、フォームのログイン認証を認識しない(http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#ftn.d5e3442)ここで述べたように、私は、私の問題..

SessionManagementFilterに解決策を見つけたと思います。だからインナーAuthenticationManager及び2を使用して)1を適用するProviderManager.authenticate()メソッドをオーバーライドする、新しいSessionManagementProviderManagerインスタンスとproviderManagerのクラスを拡張するために初期の認証プロセスを決定したがって、このフィルタ内の同時方式が..

と呼ばれることはないであろう )SessionAuthenticationStrategy.onAuthentication()得オンポイント1から返された認証)。

多分、この回答は、Spring Securityを移行する同じ問題を持つ他の誰かを助けることができます。

関連する問題