【问题标题】:Spring security - what does authorizerequest(), anyRequest() and authenticated() do?Spring security - authorizerequest()、anyRequest() 和 authenticated() 做什么?
【发布时间】:2020-09-18 22:15:09
【问题描述】:

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

protected void configure(HttpSecurity http ) throws Exception {

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

}

【问题讨论】:

    标签: java spring spring-boot rest spring-security


    【解决方案1】:

    表示除了匹配PUBLIC_URL的请求外,所有请求都必须经过身份验证

    【讨论】:

      【解决方案2】:
      • authorizeRequests() 允许使用RequestMatcher 实现基于HttpServletRequest 限制访问。

      • permitAll() 这将允许公共访问,即任何人都可以访问端点PUBLIC_URL 无需身份验证。

      • anyRequest().authenticated() 将限制对 PUBLIC_URL 以外的任何其他端点的访问,并且用户必须经过身份验证。

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

      【讨论】:

        猜你喜欢
        • 2018-09-23
        • 2018-01-18
        • 2020-03-19
        • 2017-10-11
        • 2017-08-07
        • 1970-01-01
        • 2021-08-25
        • 2017-02-09
        • 2018-10-07
        相关资源
        最近更新 更多