Monthly Archives: February 2014

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

Testing Spring MVC Rest controllers

Spring MVC 3.2 introduced the ability to test controllers via MockMVC. In this example, we will test a controller that returns JSON via @ResponseBody. Here are the dependencies that you will need. This is an example of the spring context. … Continue reading

Posted in Java, MockMVC, Spring, Spring MVC | Tagged , , , , , , , | Leave a comment

Velocity templating notes

The documentation is here An if statement looks like this An if-elseif-else looks like this A for loop looks like Values can be output by ${…} or $… There is a particular case where the ${…} notation should be … Continue reading

Posted in templating, velocity | Tagged | Leave a comment

How to get the absolute file path of a file loaded with a class loader

Posted in Java | Tagged , , , , , , , , , | Leave a comment

Joda getting a date without a time (midnight)

LocalDate localDate = new LocalDate(); localDate.toDateTimeAtStartOfDay();

Posted in Java, Joda-Time | Leave a comment

Get the active Spring profiles

Inject the Environment object The Environment object has getActiveProfiles that returns an array of active profiles. To get the first active profile, do…

Posted in Spring, Spring Profile | Tagged , , , | Leave a comment