0

我有一个使用自定义身份验证器的工作 3.0.2 applicationContext-security.xml

<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 后,我的应用程序将无法启动并收到错误消息

“配置问题:与 '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 并不是一个真正的选择。

4

1 回答 1

0

如果您使用自定义 AuthenticationProvider 实现,则必须以“传统” Spring 方式在 XML 中配置它,因为它只<security:authentication-provider ref="yourImpl">指向可以以任何方式验证任何内容的 bean ,并且根本不必使用。在您的示例中,您尝试使用这只是创建bean 的快捷方式。UserDetailsServicejdbc-user-serviceJdbcDaoImpl

所以你要做的是确保所有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" />
于 2012-08-27T09:30:36.003 回答