Category Archives: Spring Security

When the Spring Security Principal isn’t enough in a Spring MVC Controller

I had previously made a blog entry to retrieve the spring security principal via @AuthenticationPrincipal in a controller method. Getting the Spring Security Principal in a Spring MVC Controller method. That is useful if you need the username or the … Continue reading

Posted in Java, Spring, Spring MVC, Spring Security | 3 Comments

Mocking Spring Security Principal for testing Spring MVC Controllers

How do you mock a Spring security principal for testing spring MVC controllers? Create a spring security principal Create a spring authentication Add the spring security authentication to the security context The last step should not be needed because MockMVC … Continue reading

Posted in Java, MockMVC, Spring, Spring MVC, Spring Security | Tagged , , , , , , , , , , , , , , | 2 Comments

Getting the Spring Security Principal in a Spring MVC Controller method

You will need to create a Spring configuration class and annotate it with @EnableWebMvcSecurity The documentation then says to add a method parameter to a Spring MVC controller method with @AuthenticationPrincipal and you are done, like the following: What they … Continue reading

Posted in Spring, Spring MVC, Spring Security | Tagged , , , , , | 16 Comments