簡體   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