Simple Spring Security Demo Using Eclipse Maven Project



Role Based Spring Security

I will show you how to integrate Spring Security with a Spring MVC web application to secure a URL access.

Step 1:
Lets see Dependencies required for implementing spring security. 
Note :: only security related dependencies are added here u will require to add other dependencies required by ur project like spring-webmvc, spring web etc.


Step 2:
Configure your Spring Security Filter Chain in Web.xml


Step 3:
Create a xml file in WEB-INF folder name it as application-security.xml  as  we have defined this name inside web.xml file. Write below code in this file.





NOTE:  User and UserRole are a tables in database connected to dataSource bean. User has columns userid,username, password and enable whereas Userrole has columns userid  and authority.

Step 4:

Create a Login Page:




Step 5:
Create a new Controller class  called it as LoginController.




Step 6:
Authorize and restrict links using spring security tags according to your project for example:











No comments: