I have a Spring Boot application (REST-based using JAX-RS) and couple of endpoints secured with a custom AuthenticationProvider. For integration testing I'm not using MockMVC, but REST-assured.
How can I make use of @WithSecurityContext annotation to mock my SecurityContext?
Comment From: rwinch
@poznachowski I don't think this is currently possible. Does REST-assured have some hook like MockMvc's RequestPostProcessor?
Comment From: jgoldhammer
Yes, it has... https://github.com/jayway/rest-assured/wiki/Usage#bootstrapping-restassuredmockmvc
Comment From: rwinch
@jgoldhammer Thanks for the response. This appears to be rest assured with Spring MVC. The request is to support JAX-RS. Is there something I'm missing?
Comment From: jgoldhammer
Yeah, you are right... I could not understand why anyone will use Jaxrs instead of Spring MVC with Spring Boot... :-)
Comment From: poznachowski
Sorry for lack of response. As stated REST-assured has only Spring MVC support included. Afaik, there is no way to make it work in a similar fashion, as REST-assured will be solely used as HTTP client.
About choosing JAX-RS over Spring MVC.. I welcomed Spring ecosystem quite recently, coming from a custom-made stack of Guice, JAX-RS, Jackson etc. (way before Dropwizard became popular). Hence, everything in Spring was new and I was tempted to stick with JAX-RS (+ Swagger works flawlessly). To be honest, I still like the syntax more. The choice can be considered a little short-sighted, as it introduced different set of issues (like the one described here), but it helped understand Spring codebase better.
Back to the topic. I created custom test configuration along with custom annotation to allow mocking out security in integration tests.
Comment From: rwinch
There is nothing wrong with using JAX-RS (after all, Spring is about choice).
I'd be glad to accept a pull request for support on this, but I'm not sure that I will have time to implement this myself in the near future.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.