java - 为什么添加弹簧安全后无法访问主页
问题描述
我正在向网站添加 Spring Security 我的目标是向所有用户显示所有图像、home.html 和 index.html(无需登录)。
我已允许对图像、主页和索引页面的所有请求,但匿名用户仍然无法在不登录的情况下进入主页
我的安全配置 Java
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin").hasRole("ADMIN")
.antMatchers("/", "home", "index").permitAll()
.antMatchers("/styles.css", "/css/**", "/js/**", "/fonts/**", "/images/**").permitAll()
.anyRequest().hasRole("USER")
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?login_error=1")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/")
.permitAll();
}
我的 index.html 页面
<!doctype html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<body>
<a href="login" class="btn btn-outline-danger btn-lg">login page </a>
<a href="home" class="btn btn-outline-danger btn-lg">home page</a>
</body>
</html>
解决方案
您是否尝试过这样的重构:
.antMatchers("/", "home", "index").permitAll()
-> .antMatchers("/", "/home", "/index").permitAll()
?
推荐阅读
- c - 如何获取和存储操作的二进制值?
- javascript - 如何通过传递 ID 从 JSON 中删除项目
- cmake - CMake 的 find_package 的 Build2 模拟
- python - 为什么 CPython 会预先分配一些整数?
- google-cloud-platform - Cloud Composer - BigQuery 作业状态检查失败
- spring - 背压在 Project Reactor 中是如何工作的?
- reactjs - React-Admin - 向 TextField 添加显示/隐藏属性?
- javascript - 当每个元素javascript中的响应代码为1时删除禁用的类
- build - 如何从构建脚本(build.rs)访问当前的货物配置文件(调试/发布,...)
- python - 全局变量未更新