同じベースURL部分にマップされたローカルサービスがいくつかあります。ユーザー向けのこのサービスは閉じている必要がありますが、そのうちの1つはZooKeeperによって使用されており、開いている必要があります。だから私は設定しました:
@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().antMatcher("/inner/service/event/bus").csrf().disable().anonymous()
.and().formLogin().and().logout().and().httpBasic();
}
}
この構成は機能しません。イベントだけでなく、オープンサービスも行っています。各サービスはオープンです。構成を次のように変更した場合:
@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();
}
}
すべてのサービスはより閉鎖されています。
どこでも匿名リクエストを設定することは可能ですか?
"/**"
パスによる認証済みサービス
"/inner/service/**"
開いたもので
"/inner/service/event/bus"
?
PS Openサービスは、ZooKeeperの応答に使用されます。
解決策は次のとおりです。
他のパスに移動します(交差していないパスを提供するため)
"/inner/service/event/bus"
// for example
"/inner/event/bus"
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();
}
このソリューションは、1つの命令を削除した場合にも機能します。
@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();
}
そしてもう1つの重要なポイント(私は重要だと思います)。* .ymlファイルからすべてのセキュリティカスタマイズを削除しました。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加