Posts tagged spring

Spring Security authentication with a Neo4j backend

I am currently working on a Spring-based Neo4j (a graph database) application and needed to add user authentication. Since Spring Security allows integrating custom authentication providers it felt only natural to implement a provider based on Neo4j. A data structure to support users and groups is already provided in the Neo4j Wiki. I used it as the basis for my implementation with some wrapping so it could be integrated with Spring Security and provides administrative methods.


Iterating over nested objects in a Spring form

Spring 3 allows for wonderfully simply forms and automatic binding of form values back to the command object. However if your command object has further nested objects that you want to make editable from the form as well things get a little tricky. In that case you can’t just use a standard JSTL forEach loop as this will not allow you to build the path to the nested object correctly. The trick is to use the varStatus attribute to keep track of the index.


Unit Testing a Spring @Controller

Thanks to Spring’s new MVC Annotations (@Controller, @RequestMapping, @RequestParam etc.) unit testing a Spring controller is now easier than ever before. Still, I had a hard time figuring out how to do this since most of your controller methods will not take a ServletRequest as input. Instead they use a form-backing / command object, a BindingResult and maybe a ModelMap. In a web environment Spring takes care of filling the command object and validation results however in a unit test you will have to do this yourself.

Following is the basic outline for writing such a test.


Go to Top