【发布时间】:2020-01-07 11:37:55
【问题描述】:
我正在制作一个仅用于学习目的的 Spring Boot 应用程序。
在其中我有一个带有 URL 模式 /home, 的 home.jsp 页面
带有 URL 模式 /first 的 first.jsp 页面
以及类似的带有 URL 模式 /second 的 second.jsp 页面。
现在我想将/home 设为公共页面(所有人都可以访问)并希望使/first 和/second 安全。
我正在尝试的是:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/home").permitAll()
.anyRequest().authenticated();
}
http://localhost:8080/home 工作正常,但
http://localhost:8080/first 和 http://localhost:8080/second 出现以下错误:
白标错误页面
此应用程序没有显式映射 /error,因此您将其视为后备。
2019 年 9 月 4 日星期三 20:02:52 IST
出现意外错误(类型=禁止,状态=403)。 访问被拒绝
【问题讨论】:
-
所以 HTTP 403 表示页面
first和second是安全的......正是你想要的,对。 -
那我怎样才能移到那些页面
-
@SUMITLOHAN 您需要先登录。您没有配置任何身份验证机制。
-
@dur 如何配置认证机制
-
@SUMITLOHAN:见Spring Security Reference
标签: spring-boot spring-security