java - Spring security - authorizerequest()、anyRequest() 和 authenticated() 做什么?
问题描述
在下面的代码中,不同的链式方法有什么作用? PUBLIC_URL是一个包含公共 URL 的字符串数组。
protected void configure(HttpSecurity http ) throws Exception {
http.authorizeRequests()
.antMatchers(PUBLIC_URL).permitAll()
.anyRequest().authenticated();
}
解决方案
authorizeRequests()
允许基于HttpServletRequest
usingRequestMatcher
实现来限制访问。permitAll()
这将允许任何人无需身份验证即可访问端点PUBLIC_URL的公共访问 。anyRequest().authenticated()
将限制对PUBLIC_URL以外的任何其他端点的访问,并且用户必须经过身份验证。
我们还可以根据权限配置访问,可以管理会话、HTTPS 通道等等。您可以从configure(HttpSecurity http)中找到更多详细信息
推荐阅读
- azure-service-fabric - Service Fabric,确定是否存在特定参与者
- c# - C# 将侦听器附加到 Npgsql 连接
- php - 将原始 SQL 查询转换为 Laravel Eloquent
- javascript - 用于缓存 css 属性名称的通用函数
- android - 如何在tablayout上解析json
- c++ - 枚举类计算常量
- string - 如何为str,Python3的两个列表制作置换矩阵
- amazon-web-services - 账户之间的 AWS PrivateLink
- twitter - 如何区分现在不存在但之前退出的用户?
- sql-server - 如何加入 sys.databases、sys.tables 和 sys.columns