Do you rely on getting information based on an AuthenticationPrincipal with Spring Security and want to use MockMVC for Unit-testing? Do not worry, we got you covered.
Use this Security Interceptor file in your Unit tests:
And here is how to setup your MockMVC instance and how to make sure your AuthenticationPrincipal is passed along:
This comment has been removed by the author.
ReplyDeleteGreat solution! It really helped me.
ReplyDeleteCan someone tell me what playlistController is?. Also Principal is an interface and implementation is missing.
ReplyDeleteCould you please add the imports as well. Facing hardtime finding the right import
ReplyDeleteIt never htis the API...instead I get 200 HttpStatus with empty content.
ReplyDelete