[英]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我是 spring security 的新手,无法找到有关如何忽略 web.xml 中 spring security 的 url 模式的正确答案
currently in web.xml file i have the following config当前在 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>
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.现在我想忽略带有“/test”的特定网址,如果不是所有可能的解决方案,我可以在这里使用 web.xml 来做到这一点。
I was able to found the solution after lot of research :经过大量研究,我找到了解决方案:
I added below security constraint in 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>
and added below in Java config class:并在 Java 配置类中添加如下:
@override
protected void configure(HttpSecurity http) {
http
.authorizeRequests()
.antMatchers("/test").permitAll()
.anyRequest().authenticated();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.