O'Reilly logo

Spring Security 3.x Cookbook by Anjana Mankale

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Spring Security with Hibernate using UserDetailsService with Derby database

So far we have seen Hibernate and Spring security with various authentication providers. In this section we will use Hibernate to retrieve users and authorities from the database.

For that we are going to implement the UserDetailsService interface and implement a method in the interface. To begin we need to create entity classes for users and roles.

We also moved the @preAuthorize annotation to the controller class.

Getting ready

  • Create a new class which implements the UserDetailsService interface and add the Bean definition to the application-security.xml file
  • Edit the application-security.xml file
  • Use the @preAuthorize annotation in controller
  • In the horror database add the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required