2012-08-27 50 views
0

後應用程序將無法啓動我有一個使用自定義的認證網絡升級從3.0.2到3.1.2

<global-method-security pre-post-annotations="disabled"> 

</global-method-security> 

<http use-expressions="true"> 

    <intercept-url pattern="/diagnostics/**" access="hasRole('ROLE_USER')" /> 


    <form-login login-page="/genesis" default-target-url="/diagnostics/start-diagnostics" 
     authentication-failure-url="/genesis?authfailed=true" 
     authentication-success-handler-ref="customTargetUrlResolver"/> 
     <access-denied-handler error-page="/genesis?notauthorized=true"/> 

    <logout logout-success-url="/genesis"/> 
    <session-management session-authentication-error-url="/genesis"> 
     <concurrency-control max-sessions="1" expired-url="/genesis?sessionExpired=true"/> 
    </session-management> 
</http> 

<authentication-manager> 
<authentication-provider ref="genesisAuthenticator"> 
    <jdbc-user-service data-source-ref="dataSource"/> 
</authentication-provider> 
</authentication-manager> 

<beans:bean id="genesisAuthenticator" class="com.blackbox.x.web.security.Authenticator"/> 
<beans:bean id="customTargetUrlResolver" class="com.blackbox.x.web.security.StartPageRouter"/> 

</beans:beans> 

升級到3.1.2後一個工作3.0.2的applicationContext-security.xml文件我應用程序不會啓動,並且我收到錯誤消息

「配置問題:authentication-provider元素在與'ref'屬性一起使用時不能有子元素。我假設問題在於

<jdbc-user-service data-source-ref="dataSource"/> 

元素其中data-source-ref指向我的application-context.xml文件中的定義。

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
<property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
<property name="url" value="jdbc:mysql://localhost:3306/genesis"/> 
<property name="username" value="dbuser"/> 
<property name="password" value="********"/> 

什麼我需要做的就是這個工作。回落到3.0.2並不是真正的選擇。

回答

0

如果您使用自定義的AuthenticationProvider實現,你必須配置它在「傳統」春路XML,因爲<security:authentication-provider ref="yourImpl">只是點到豆可以在認證任何任何方式,並沒有真正必須完全使用UserDetailsService。在你的例子中,你試圖使用jdbc-user-service這只是創建JdbcDaoImpl bean的快捷方式。

所以你要做的是確保所有的genesisAuthenticator依賴關係都是你自己解決的,而不是Spring Security。也就是說,您應該將@Autowired setUserDetailsService(UserDetailsService userDetailsService)方法添加到您的bean中,或者像這樣使用XML配置它(使用id屬性):

<beans:bean id="genesisAuthenticator" 
    class="com.blackbox.x.web.security.Authenticator"> 
    <property name="userDetailsService" ref="jdbcUserService"/>  
</beans:bean> 

<jdbc-user-service id="jdbcUserService" data-source-ref="dataSource" />