Spring Security with Hibernate using @preAuthorize annotation
In the current demonstration we are using two different databases. The authentication manager is configured with tenant1DataSource
which connects to a Derby database which holds the user and role information. Using this data source we will do that authentication and authorization.
For displaying the horrormovie
list we have created another datasource in Derby which is used with the Hibernate configuration file.
In the DAOImpl
class methods we are using @preAuthorize
annotations.
Let's use the GlassFish application server to run the application.
Getting ready
Edit the
application-security.xml
.Edit the
horrormovie-servlet.xml
.Use the
@preAuthorize
annotation inDAOImpl
. Spring Security authorizes the user when the method is invoked.
How to do it...
The following steps will do authentication and authorization with a Hibernate application:
Edit the
application-security.xml
file with data source details and Bean information.<global-method...