AOP solutions often are the greatest ones for testing, and Spring provides it with @WithMockUser, @WithUserDetails and @WithSecurityContext, in this artifact: In this post we will explain how to authenticate an API using tokens, which will help ensure that users who use our services have permissions to do so and are who they say they are. Typically, we could secure our service layer by, for example, restricting which roles are able to execute a particular method and test it using dedicated method-level security test support. User class set up: public class User implements UserDetails { private final String username; private final String password; private final List grantedAuthorities; public User( String username, String password, List