我已经像这样配置了spring security:
@EnableWebSecurity
@Order(1)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/rest/app/health").permitAll()
.antMatchers("/*/app/**").authenticated()
.antMatchers("/**").permitAll().and().httpBasic();
}
@Override
public final void configure(final WebSecurity web) throws Exception {
super.configure(web);
web.httpFirewall(new DefaultHttpFirewall());
}
}
我仅包含spring安全性,而没有包含oauth2。由于某些原因,例如某人正在访问任何允许的URL。 / rest / app / health带有 Authorization 标头,他将获得 401未经授权。没有标题,它工作正常。
如何忽略Authorization标头,因为我需要将此标头作为请求参数来将我的请求委托给第三方服务。
答案 0 :(得分:0)
将对通过 HttpSecurity 配置的所有端点执行过滤器。如果您不希望对某些端点应用过滤器,请将它们包含在配置 WebSecurity 的方法中。
你需要改变这个方法
@Override
public final void configure(final WebSecurity web) throws Exception {
super.configure(web);
web.httpFirewall(new DefaultHttpFirewall());
}
到:
@Override
public void configure(WebSecurity web) {
web.ignoring()
.antMatchers(HttpMethod.POST, "/rest/app/health");
}