简体   繁体   中英

How to ignore/exclude a url pattern in spring security

I'm new to spring security and unable to find the correct answer on how to ignore a url patter from spring security in web.xml

currently in web.xml file i have the following config

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>

and now I want to ignore a particular url with "/test" can I do this using web.xml here if not what are all the possible solutions.

I was able to found the solution after lot of research :

I added below security constraint in 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>

and added below in Java config class:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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