Created
January 9, 2014 08:57
-
-
Save letenkov/8331349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Filter which adds CSRF information as response headers. | |
* | |
* @author Patrick Grimard | |
* @since 12/31/2013 4:48 PM | |
*/ | |
public final class CsrfTokenGeneratorFilter extends OncePerRequestFilter { | |
@Override | |
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | |
CsrfToken token = (CsrfToken) request.getAttribute("_csrf"); | |
// Spring Security will allow the Token to be included in this header name | |
response.setHeader("X-CSRF-HEADER", token.getHeaderName()); | |
// Spring Security will allow the token to be included in this parameter name | |
response.setHeader("X-CSRF-PARAM", token.getParameterName()); | |
// this is the value of the token to be included as either a header or an HTTP parameter | |
response.setHeader("X-CSRF-TOKEN", token.getToken()); | |
filterChain.doFilter(request, response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment