java - 仅对一页应用弹簧安全性
问题描述
我有一个典型的安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
//http.authorizeRequests().antMatchers("/resources/**").permitAll().anyRequest().permitAll();
}
现在 spring 要求登录除了登录页面之外的所有内容......但是我怎么能以另一种方式进行登录,所以它只要求视图/index 的登录页面?仅适用于一组端点?谢谢!
解决方案
尝试这个:
http
.authorizeRequests()
.antMatchers("/", "/index").authenticated()//Makes / and /index to be authenthicated
.anyRequest().permitAll()//Makes any other allow without authentication. Or if you want a group use antMatchers here too.
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
推荐阅读
- swift - Mac OS:有没有办法在没有内核的情况下嗅探系统打开调用
- javascript - 将数组转换为单个对象数组
- r - 使用自定义名称转置/重塑
- angular - import * as firebase from 'firebase' 自 Angular 6 更新起不再工作
- python - firefox61.01 64 位 (python 3.6 - 32bit) 中的 Selenium 属性错误
- javascript - 将单个待办事项更改为文本字段而不是所有待办事项时
- node.js - 猫鼬只保存“_id”和“_v”
- java - 自定义 SnakeYAML 转储样式
- identityserver4 - Unauthorized_Client 无效的重定向 Uri
- c# - 使用反射和运行时已知的类型调用 Func 对象