Login page connect to database with Spring security (part 2)

Thursday, December 3rd, 2015 (0 Comment)

Continue Develop login page simply with Spring security (part 1) , we will add mysql database to check spring security login with username and password from database, manage user’s information as insert/update/delete after logged in success.

In this article, you should review login spring connect to Mysql Database simply (Part 1)

Step 1: config xml files (spring security) to connect to mysql

you need create database name is “springdb” and run script below to create table and import data user admin

servlet-config-jdbc.xml:

web.xml: add servlet-config-jdbc.xml file to config database’s connection

Step 2: edit some java file

UserInfo.java: modify again this file to mapping entity with database

UserInfoDAO.java: define interface extends from GenericDAO (we will use genericdao library to manage entity easily)

UserInfoDAOImpl.java: implements UserInfoDAO and extends GenericDAOImpl

UserInfoService.java: business layer

CustomAuthenticationProvider.java: need to edit this file to get and check username, password from database

UserInfoController.java: modify create/update/delete user’s information

Step 3: edit layout for end user using

user.jsp:

Finally, build and run project spring security, open with url http://localhost:8080/springmvc  and login default admin/123, after logged in, render to home page, you click user link to manage user’s information (remember do not delete user admin, so will not login later)

Done with login user spring security, in part 3, we will custom login spring security with LDAP (use usern domain).

Tags: , , , , ,

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Leave a Reply

Your email address will not be published. Required fields are marked *