2016-06-22 20 views
3

私は、トンネルのガイドを通して作成したSpring Security用のXML設定を持っています。 URLを傍受し、カスタムフィルタを使用してLDAP認証マネージャで認証を提供することになっています。Spring Security XML Config対Java Config

だからここにある:

<http create-session="stateless" auto-config='false' use-expressions="true"> 
    <anonymous enabled="true"/> 
    <intercept-url pattern="/index.html" access="permitAll()" method="GET"/> 
    <intercept-url pattern="/login" access="permitAll()" method="GET"/> 


    <custom-filter before="LAST" ref="statelessLoginFilter"/> 
    <custom-filter before="PRE_AUTH_FILTER" ref="statelessAuthFilter"/> 

    <intercept-url pattern="/one*" access="hasRole('ROLE_ONE')" method="GET"/> 
    <intercept-url pattern="/two*" access="hasRole('ROLE_TWO')" method="GET"/> 

    <!-- another intercept-url stuff --> 

    <csrf disabled="true"/> 

    <!-- authentication manager and stuff --> 
</http> 

今私は、Javaコンフィグでそれを書き換えしようとしています。しかし、そこにカスタムフィルターを使用する方法はありません。 .addFilterBeforeがありますが、前に= "LAST"または前に= PRE_AUTH_FILTERを置くことはできません。そんなことはないから。これをどのように書き換えることができますか?

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

@Autowired 
GenericFilterBean statelessAuthFilter; 
@Autowired 
AbstractAuthenticationProcessingFilter statelessLoginFilter; 

public SecurityConfig(){ 

} 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
      .authorizeRequests() 
      .antMatchers("/one**", "/two**").access("hasRole('ONE')") 
      .antMatchers("/login").permitAll() 
      .anyRequest().authenticated() 

      .and() 
      .addFilterBefore(statelessAuthFilter, GenericFilterBean.class) 
      .addFilterBefore(statelessLoginFilter, BasicAuthenticationFilter.class) 
      .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) 

      .and().anonymous() 
      .and().csrf().disable(); 
}} 

答えて

3

特定のフィルタクラスを特定する必要があります。

たとえば、デフォルトのLASTフィルタはFilterSecurityInterceptor - Filter Orderingである必要があります。

PRE_AUTH_FILTERは、設定した内容に応じて、AbstractPreAuthenticatedProcessingFilterまで拡張できます。

基本的にJava Configでは、後で不快な驚きを避けるために、注文に明示的に指定する必要があります。

+0

大きな説明。そしてそれは動作します)ありがとう! – ottercoder

関連する問題