【发布时间】:2016-05-06 22:00:51
【问题描述】:
我使用 consul 作为服务发现/注册创建了 Spring 云应用程序。 我已将我的 spring 安全配置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.exceptionHandling()
.authenticationEntryPoint(myEntryPoint());
http
.authorizeRequests()
.antMatchers("/images/**").permitAll()
.antMatchers("/modules/**").permitAll()
.antMatchers("/vendor/**").permitAll()
.antMatchers("/views/**").permitAll()
.antMatchers("/index.html").permitAll()
.regexMatchers("/health").permitAll()// consul check health
.antMatchers("/api/**").authenticated()
.antMatchers("/**").permitAll();
http // login configuration
.addFilterAfter(springSecurityFilter(), BasicAuthenticationFilter.class);
http //logout configuration
.logout()
.logoutSuccessHandler(logoutHandler());
http.csrf().disable();
}
通常,使用此过滤器 spring consul 健康检查不会通过此过滤器(公共访问)。
但是 consul 健康检查 consul 会通过过滤器。
如果我使用以下网址,我将被重定向到身份验证页面:
https://localhost:8181/health
【问题讨论】:
-
有什么原因为什么这个 Matcher 是正则表达式匹配器,而不是 ant 匹配器?
-
并添加为什么复杂性?仅使用
antMatchers("/api/**).authenticated().antMatchers("/**").permitAll()会产生相同的结果(/**是全部,它也将涵盖所有先前提到的 URL,例如/images/**等)。 -
当我起飞时 .antMatchers("/**").permitAll() 我有同样的结果
-
你设置管理端口了吗? Spring boot 有文档说明如何禁用健康检查安全性。
标签: spring spring-security spring-cloud consul