I'd like to use just the Spring Security's CSRF feature without any of the other authentication/authorization features since those features are provided by a third party provider for me. If this can be done, how do I tell Spring not to look out for any authentication manager with its dependent beans and just intercept all URLs, and add the csrf token.
相关问题
- java.lang.IllegalArgumentException: Cannot set to
- Spring Data MongoDB - lazy access to some fields
- Declaring an explict object dependency in Spring
- Decoding body parameters with Spring
- Spring Integration - Inbound file endpoint. How to
相关文章
- java JDK动态代理和cglib动态代理最后获取的代理对象都为null的问题
- org.xml.sax.SAXParseException; lineNumber: 7; colu
- SpringMVC如何把File封装到Map中?
- Spring: controller inheritance using @Controller a
- How to load @Configuration classes from separate J
- Java spring framework - how to set content type?
- Java/Spring MVC: provide request context to child
- Spring 5 Web Reactive - Hot Publishing - How to us
I'd personally avoid to include the Spring Security Filter chain if you intend to use only its CSRF protection. Without proper configuration, you will end up burdening your application with unnecessary logic.
The CSRF protection in Spring Security is offered by the
org.springframework.security.web.csrf.CsrfFilter
servlet Filter.By default the filter stores the expected CSRF token on the
HttpSession
.You can easily implement something similar or attempt at declaring this filter only in your servlet filter chain /
web.xml
.I got the CSRF feature working by making the following changes/additions. Also, I used the
<form:form>
tag in my jsp to leverage the automatic insertion of the token by Spring.jars added:
web.xml additions:
New java file added:
Marco - With just the CSRF filter, it does not work.
You could try this:
CSRF is enabled per default. You can than make use of (for example in thymeleaf):