6

XML サーブレット構成を Java 構成に移行しようとしています。

以下の構成は私のサーブレット構成であり、コントローラー層でカスタム セキュリティ アノテーションを有効にします。

<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 構成に置き換えるためのものですが、今はそうではありません。ここに私のセキュリティ設定のいくつかの部分があります:

<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" />

コントローラ層でセキュリティとタグを有効にするサーブレット構成の移行を開始したいと考えています。@PreAuthorize@PostAuthorize

私はこの注釈を見つけました: @EnableGlobalMethodSecurity(prePostEnabled=true)、しかしそれを私のサーブレット設定に入れます:

@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 []

さらに、カスタムの式ハンドラーを設定する方法がわかりません!

ヒントのある人?ありがとうございました

4

2 に答える 2

3

まず、次のような別の構成クラスが必要です

@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {...

定義する必要がある場所

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService);
}

それはあなたの例外に役立つはずです。

expressionHandler の設定方法がわかりませんが、configure(WebSecurity web) で微調整できるようです。

@Override
public void configure(WebSecurity web) throws Exception {
    web.expressionHandler().....
}
于 2014-02-04T13:52:34.077 に答える