Spring CSRF token does not work, when the request to be sent is a multipart request

前端 未结 5 569
情歌与酒
情歌与酒 2020-11-27 22:24

I use,

  • Spring Framework 4.0.0 RELEASE (GA)
  • Spring Security 3.2.0 RELEASE (GA)
  • Struts 2.3.16

In which, I use an in-built securi

5条回答
  •  失恋的感觉
    2020-11-27 23:01

    In this case, since it is a multipart request in which the CSRF token is unavailable to Spring security unless MultipartFilter along with MultipartResolver is properly configured so that the multipart request can be processed by Spring.

    MulipartResolver in the applicationContext.xml file has to be registered as follows

     
    
        
     
    

    The attribute value -1 of maxUploadSize puts no limit on the uploaded file size. This value may vary depending upon the requirements. In case of multiple files, the file size is the size of all uploaded files.


    Also,

    /* 
    

    of of MultipartFilter needs to be changed to

    /*
    

    This is a bug in the documentation.

    This will work just fine, in case, it is Spring MVC alone.

    but if it is an integration of Spring and Struts(2), it incurs another problem in the associated Struts action class. The information of the uploaded file will be null in the associated Struts action class(es).

    To solve this particular issue, see this answer to customize a multipart request.

提交回复
热议问题