我正在使用带有Spring-security,OAuth和apache-cxf的spring-boot 2.0.4。 出于健康检查的需要,应用程序正在注册默认bean,该默认bean使用“ ping.html”的urlMapping。
为了安全起见,我已标记所有请求均应具有特定角色,但“ ping.html”除外。但是,当我尝试访问ping.html时,它要求的安全性与应用程序中任何其他页面的安全性相同。
这是我的代码段:
@Override
protected void configure(HttpSecurity http) throws Exception {
http = http.antMatcher("**").sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).enableSessionUrlRewriting(true).and();
http.authorizeRequests().antMatchers("/ping.html").permitAll().anyRequest().access("oauthHasScope('myApplication.trust')").and().anonymous().disable();
http.httpBasic().authenticationEntryPoint(oAuthRedirectAuthenticationEntryPoint);
http.addFilterBefore(oAuthTokenAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
http.exceptionHandling().accessDeniedHandler(myAppAccessDeniedHandler);
http.authorizeRequests().expressionHandler(oAuth2WebSecurityExpressionHandler);
}
这是servlet注册的代码:
@Bean
public ServletRegistrationBean cxfServlet() {
final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new CXFServlet(), "/*");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
@Bean
public ServletRegistrationBean healthCheckServletBean() {
ServletRegistrationBean pingHealthCheckServletBean = new ServletRegistrationBean(new DefaultServlet(), "/ping.html");
pingHealthCheckServletBean.setLoadOnStartup(1);
return pingHealthCheckServletBean;
}
所以,我很少怀疑: 1. spring-security如何应用于这种情况下的多个servlet。 2.如何仅启用一个servlet的安全性,并允许所有(/ping.html)用作默认servlet。 3.尽管我已经为ping.html提到了allowAll(),但是为什么它会被安全性阻止。