繁体   English   中英

如何在 Spring Security 中忽略/排除 url 模式

[英]How to ignore/exclude a url pattern in spring security

我是 spring security 的新手,无法找到有关如何忽略 web.xml 中 spring security 的 url 模式的正确答案

当前在 web.xml 文件中,我有以下配置

web.xml -

    <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

现在我想忽略带有“/test”的特定网址,如果不是所有可能的解决方案,我可以在这里使用 web.xml 来做到这一点。

经过大量研究,我找到了解决方案:

我在 web.xml 中添加了以下安全约束

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Public</web-resource-name>
    <description>Matches a few special pages.</description>
    <url-pattern>/test</url-pattern>
  </web-resource-collection>
</security-constraint>

并在 Java 配置类中添加如下:

@override
protected void configure(HttpSecurity http) {
      http
            .authorizeRequests()
            .antMatchers("/test").permitAll()
            .anyRequest().authenticated();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM