我正在尝试将我的 xml servlet 配置迁移到 java 配置。
下面的配置是我的servlet 配置,它在控制器层启用自定义安全注释。
<security:global-method-security pre-post-annotations="enabled">
<security:expression-handler ref="expressionHandler"/>
</security:global-method-security>
<bean id="expressionHandler" class="yyy.MyMethodSecurityExpressionHandler" />
我也有一个工作的 spring security xml 配置,这是为了被 java config 取代,但不是现在。这是我的一些安全配置:
<bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailsService" />
</bean>
<bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager">
<constructor-arg>
<ref bean="authenticationProvider"/>
</constructor-arg>
</bean>
<security:authentication-manager>
<security:authentication-provider user-service-ref="userDetailsService" />
</security:authentication-manager>
<security:global-method-security pre-post-annotations="enabled" />
我想开始迁移我的servlet 配置,在控制器层启用安全性@PreAuthorize
和@PostAuthorize
标记。
我找到了这个注释:@EnableGlobalMethodSecurity(prePostEnabled=true)
,但把它放在我的 servlet 配置中:
@Configuration
@ComponentScan(basePackages= {
"....."
})
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class WebappServletConfig extends WebMvcConfigurationSupport {
我得到这个例外:
java.lang.IllegalArgumentException: Expecting to only find a single bean for type interface org.springframework.security.authentication.AuthenticationManager, but found []
此外,我不知道如何设置我的自定义表达式处理程序!
有人有一些提示吗?谢谢