Spring 4 - Apache POI - Security: Error 403 when generating Excel spreadsheet

0

I'm in a project with Spring MVC 4, and I need to generate an Excel with a set of data on the screen. For this I use Apache POI to make the generation integrating it with Spring. However, when the file download runs, I get a 403 error. The application includes Spring security and is configured with Java and Annotations. I have made the trace but it does not even enter the controller to manage the URL that is invoked when requesting the Excel download. It shows the correct URL, the controller is correctly configured ... Has anyone encountered something similar?

    
asked by user1748166 13.12.2016 в 21:25
source

1 answer

1

If you use the Security Spring with the Java configuration, the CSRF protection is enabled by default. In this context, if an Ajax request is made to a REST endpoint using the POST method, you will get a csrf lost token error.

To solve this, there are two options:

Option 1: csrf Deactivate

@Override
protected void configure (HttpSecurity http) throws Exception {
    http.csrf().disable();
}

Option 2: Add csrf to the ajax request. See

    
answered by 13.12.2016 в 21:42