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 theapplication-security.xml
fileEdit the
application-security.xml
fileUse the
@preAuthorize
annotation in controllerIn the horror database add the tables
USERS
andUSER_ROLE
Insert role
ROLE_EDITOR
and users namedravi
andravi123
How to do it...
The following steps are used to integrate Spring Security authentication with Hibernate by implementing the UserDetailsService
interface that interacts...