spring-boot - LemonWebSecurityConfig 自定义
问题描述
我在我的项目中使用 SpringLemon。我想自定义authorizeRequests
方法,以便任何以“/ xyz”开头的请求只能由经过身份验证的用户访问。(“/xyz/abc”、/xyz/def”、“xyz/ghi/jkl”等)为了做到这一点,我创建了自己的类扩展LemonWebSecurityConfig
类,并将其作为配置类。我已经覆盖authorizeRequests
方法看起来像这样:
@Override
protected void authorizeRequests(HttpSecurity http) throws Exception {
http.authorizeRequests()
.mvcMatchers("/xyz/**").authenticated()
.mvcMatchers("/**").permitAll();
}
当我测试它时,它适用于那些“ /xyz ” URL(未经身份验证得到 403),“ /api/core/context ”给了我“200”,但“ /api/core/login ” URL 总是给了我 404 .即使我没有覆盖authorizeRequests
方法并且我只有空的配置类,它也会响应 404。我错过了什么?
解决方案
实际上我扩展了错误的课程。使用正确的类(如在 lemon-demo-jpa 中看到的那样)它可以完美地工作:
@Component
public class MySecurityConfig extends LemonJpaSecurityConfig {
@Override
protected void authorizeRequests(HttpSecurity http) throws Exception {
http.authorizeRequests()
.mvcMatchers("/xyz/**").authenticated();
super.authorizeRequests(http);
}
}
推荐阅读
- javascript - setTimeout 无法访问变量
- sql - 排序字母+字符+数字?
- mysql - MariaDB 使用 PHP PDO 存储与原始字段不同的值的 varbinary 字段
- mysql - MySQL 查询在子查询中使用 JOINS 太慢
- python - 如何从列表中删除标点符号
- vue.js - Nuxt js如何在商店中调度动作并改变状态
- javascript - 使用 textarea 用 jQuery 填充数组
- python-3.x - 如何在没有 root 的情况下从源代码构建 Python 3.5.2
- git - Git rebase order - 混乱
- c-preprocessor - 如何在编译期间使用 C 预处理器显示条件错误?