2016-07-12 4 views
1

私は、同じベースURLの部分にマップされたローカルサービスをいくつか持っています。このサービスは閉鎖されていなければなりませんが、ZooKeeperがそのサービスの1つを使用しており、オープンしている必要があります。 これで設定しました:Spring Security 4マッチャをカスタマイズする

この設定は機能しません。私はイベントだけでなく、オープンなサービスを持っています。各サービスは開いています。設定を次のように変更した場合:

@Configuration 
@EnableWebSecurity(debug = true) 
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Override 
    public void configure(AuthenticationManagerBuilder auth) throws Exception { 
    auth 
     .inMemoryAuthentication() 
     .withUser("user").password("us").roles("USER"); 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
    http.authorizeRequests() 
     .antMatchers("/inner/service/**").hasRole("USER") 
     .and().formLogin().and().logout().and().httpBasic(); 
    } 
} 

すべてのサービスが閉じられています。

はどこにでも

オープン1

"/inner/service/event/bus" 

でパス

"/inner/service/**" 

てサービスを認証し

"/**" 

匿名の要求を設定することが可能ですか?

P.S. オープンサービスはZooKeeperの応答に使用されます。

答えて

2

溶液である:他のパスへ

  1. 移動(非交差提供する通過)

    "/inner/service/event/bus" 
    // for example 
    "/inner/event/bus" 
    
  2. 変化HTTPセキュリティ設定:

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
    
        // to ignore csrf filter for zookeeper client api 
        http.csrf().ignoringAntMatchers("/inner/event/bus"); 
    
        // configure the HttpSecurity 
        http.antMatcher("/inner/service/**").authorizeRequests() 
         // configure open resources. this configuration can be missed because of root level security (see line before) 
         .antMatchers("/", "/index.html", "/inner/event/bus", "view.html").permitAll() 
    
         // configure role for specified api 
         .antMatchers("/inner/service/**").hasRole("USER") 
    
         // to use default login and logout api 
         .and().formLogin().and().logout().logoutSuccessUrl("/").and().httpBasic(); 
    } 
    

この溶液作品また、ir emoveつの命令:

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.csrf().ignoringAntMatchers("/inner/event/bus"); 
     http.antMatcher("/inner/service/**").authorizeRequests() 
      .antMatchers("/inner/service/**").hasRole("USER") 
      .and().formLogin().and().logout().logoutSuccessUrl("/").and().httpBasic(); 
    } 

そして、もう一つの重要なポイント(iは重要だと思います)。 私は* .ymlからすべてのセキュリティカスタマイズを削除しました。

関連する問題