Springboot security using JdbcAuthentication

Опубликовано: 29 Октябрь 2021
на канале: Programming Tutorial
3,502
like

#springbootsecurityusingdatabase #springbootsecurity #springbootusingdatabase #springsecurity #loginspringboot #logoutspringboot
This implementation exist on my github (https://github.com/AminTurmudiYusup/s...)

How to Implement Springboot security based on JdbcAuthentication(Login and logout action using spring security)
In this capter we will continue previous part/chapter.
in the previous chapter we success create login page, and configuration admin lte template engine using thymeleaf.
The previous part login with username and password which wrong can access admin dashboard. We will avoid that behaviour, if username and password not match acording username and
password which stored in database, the user cannot login into dashboard.

Prerequisite, before to implement spring security you must know this basic technology
1. Java
2. Mysql/SQL
3. Intellij Idea
4. springboot



Let's go to implement springboot security based on JdbcAuthentication
1. add dependency which needed (springboot security, springboot starter jpa, mysql connector jpa)
2. create database by name (blog), run this script in your mysql
CREATE DATABASE `blog` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
3. run script for create tabel

-- blog.users definition

CREATE TABLE `users` (
`user_id` int NOT NULL AUTO_INCREMENT,
`username` varchar(45) NOT NULL,
`password` varchar(64) NOT NULL,
`role` varchar(45) NOT NULL,
`enabled` tinyint DEFAULT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

4. run script for insert data to table

INSERT INTO blog.users
(user_id, username, password, `role`, enabled)
VALUES(1, 'amin', '$2a$10$XptfskLsT1l/bRTLRiiCgejHqOpgXFreUnNUa35gJdCr2v2QbVFzu', 'ROLE_USER', 1);
INSERT INTO blog.users
(user_id, username, password, `role`, enabled)
VALUES(2, 'admin', '$2a$10$zxvEq8XzYEYtNjbkRsJEbukHeRx3XS6MDXHMu8cNuNsRfZJWwswDy', 'ROLE_ADMIN', 1);

for password, i using BCryptPasswordEncoder when you want to generate your password by yourself follow this instruction
create simple program
copy encrypted password
store your encrypted password using insert script
5. create class configuration for security
6. Create class mvc configuration for controller login page
7. comment login page url in class controller
8. edit auth_login.html
9. edit header.html for handling logout action
10. edit application.properties (to define database connection)
8. run app

Success, Happy learning and happy sharing!!! See you on the next tutorial :) :) :)


Смотрите видео Springboot security using JdbcAuthentication онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Programming Tutorial 29 Октябрь 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 3,502 раз и оно понравилось like людям.