spring-projects / spring-projects/spring-data-rest

Adding Spring Data REST prevents CsrfTokenArgumentResolver [DATAREST-656]

Open
#1,034 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: enhancement
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Rob Winch opened DATAREST-656 and commented

In a standard Spring MVC controller adding Spring Data REST causes Spring Security's to be ignored CsrfTokenArgumentResolver. The problem is that ProxyingHandlerMethodArgumentResolver is registered first which will intercept any interface.

The issue can be worked around by using the following:

@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE   )
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addArgumentResolvers(
            List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new CsrfTokenArgumentResolver());
    }
}

You can see a sample at https://github.com/rwinch/spring-state-securing-restful-apis/tree/DATAREST-656 by running SpringSessionApplicationTests.


Reference URL: https://github.com/rwinch/spring-state-securing-restful-apis/tree/DATAREST-656

Issue Links:

  • DATAREST-657 Unable to resolve PersistentEntityResourceAssembler

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.