简体   繁体   中英

Spring Security CSRF: How to retrieve token in Java

I can see how to include the CSRF token in a JSP form, simply include the line

<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />

and you're done. But, how can I get the parameter name and token in one of my @Controler classes? I've looked through docs and found nothing on this, and also looked through both Model and HttpSession attributes and failed to find it.

you can retrieve the token use:

CsrfToken token = (CsrfToken) request.getAttribute("_csrf");

You can have the request in the controller method parameter list.

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