gpt4 book ai didi

java - Spring security - authorizerequest()、anyRequest() 和authenticated() 有什么作用?

转载 作者:行者123 更新时间:2023-12-04 16:27:00 28 4
gpt4 key购买 nike

在下面的代码中,不同的链式方法有什么作用?
PUBLIC_URL 是一个包含公共(public) URL 的字符串数组。

protected void configure(HttpSecurity http ) throws Exception {

http.authorizeRequests()
.antMatchers(PUBLIC_URL).permitAll()
.anyRequest().authenticated();

}

最佳答案

  • authorizeRequests() 允许基于 HttpServletRequest 限制访问使用 RequestMatcher实现。
  • permitAll() 这将允许任何人都可以在没有身份验证的情况下访问端点 PUBLIC_URL 的公共(public)访问。
  • anyRequest().authenticated() 将限制对 PUBLIC_URL 以外的任何其他端点的访问,并且用户必须经过身份验证。

  • 我们还可以根据权限配置访问,可以管理 session 、HTTPS channel 等等。您可以从 configure(HttpSecurity http) 中找到更多详细信息

    关于java - Spring security - authorizerequest()、anyRequest() 和authenticated() 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62118216/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com