【发布时间】:2019-10-22 12:03:43
【问题描述】:
我正在尝试让 Spring 应用程序允许一些公共请求(无需登录)和一些私有请求(需要登录)。
此时我想让公共部分正常工作。
我已经尝试了 Spring Security 文档中列出的大多数示例配置,包括各种匿名() 和 permitAll() 组合。所有最终都重定向到登录页面。
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers("/resources/**", "/signup", "/about","/api/home").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")
.anyRequest().authenticated()
.and()
// ...
.formLogin();
}
预期结果: permitAll() 下的项目无需登录即可访问
实际结果:
重定向到登录页面。这显示在日志中:2019-06-06 17:29:43.593 信息 56330 --- [主要] o.s.s.web.DefaultSecurityFilterChain :创建过滤器链:任何 请求,[org.srin...
这让我相信它甚至没有读取此配置。有没有办法解决这个问题?
谢谢!
更新:我尝试添加网络安全忽略,但它似乎仍然无法正常工作。它似乎仍然打印“defaultsecuritychain”错误,所以我觉得这可能与它有关。
更新 2:在 src/main/resources 下添加了 application.properties 文件,其中包含此行 logging.level.org.springframework.security=DEBUG 以使其记录调试消息。
pastebin.com/2u9k7eHD
【问题讨论】:
标签: spring spring-boot spring-security