Spring Boot Security - Database Authentication Example
Till now we were making use of in memory configuration for authenticating users and associated roles. In this example we will authenticate users and roles against database tables.
Spring Boot Security - Table Of Contents
Spring Boot + Simple Security Configuration Spring Boot Form Security Login Hello World Example Spring Boot Security - Custom Login Page Example Spring Boot Security - JDBC Authentication Example Spring Boot Security - Creating Users Programmatically Using JdbcUserDetailsManager Spring Boot Security - Password Encoding Using Bcrypt Spring Boot Security - Enabling CSRF Protection Spring Boot Security - Authentication Handler Example Spring Boot Security - Introduction to OAuth Spring Boot OAuth2 Part 1 - Getting The Authorization Code Spring Boot OAuth2 Part 2 - Getting The Access Token And Using it to Fetch Data.
Video
This tutorial is explained in the below Youtube Video.Lets Begin-
Maven Project will be as follows-

By default spring security expects tables named users table for storing username, passwords and authorities table for storing the associated roles. In the schema-mysql.sql add these schemas and insert statements
DROP TABLE IF EXISTS employee; DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS authorities; CREATE TABLE employee ( empId VARCHAR(10) NOT NULL, empName VARCHAR(100) NOT NULL ); create table users ( username varchar(50) not null primary key, password varchar(120) not null, enabled boolean not null ); create table authorities ( username varchar(50) not null, authority varchar(50) not null, foreign key (username) references users (username) ); insert into users(username, password, enabled)values('javainuse','javainuse',true); insert into authorities(username,authority)values('javainuse','ROLE_ADMIN'); insert into users(username, password, enabled)values('employee','employee',true); insert into authorities(username,authority)values('javainuse','ROLE_USER');Spring Boot JDBC runs this script before starting the application