How to use JdbcUserDetailsManager to perform authentication

김가빈·2023년 7월 28일
0

springsecurity

목록 보기
5/23

database(mysql)

create database eazybank;

use eazybank;

CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(45) NOT NULL,
`password` VARCHAR(45) NOT NULL,
`enabled` INT NOT NULL,
PRIMARY KEY (`id`));

CREATE TABLE `authorities` (
  `id` int NOT NULL AUTO_INCREMENT,
  `username` varchar(45) NOT NULL,
  `authority` varchar(45) NOT NULL,
  PRIMARY KEY (`id`));

INSERT IGNORE INTO `users` VALUES (NULL, 'happy', '12345', '1');
INSERT IGNORE INTO `authorities` VALUES (NULL, 'happy', 'write');

CREATE TABLE `customer` (
  `id` int NOT NULL AUTO_INCREMENT,
  `email` varchar(45) NOT NULL,
  `pwd` varchar(200) NOT NULL,
  `role` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
);

INSERT INTO `customer` (`email`, `pwd`, `role`)
 VALUES ('johndoe@example.com', '54321', 'admin');

dependencies

  • delete ldap dependencies

  • add jdbc dependencies
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>com.mysql</groupId>
			<artifactId>mysql-connector-j</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>

application.properties

spring.datasource.url=jdbc:mysql://localhost/eazybank
spring.datasource.username=admin
spring.datasource.password=mysql123
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
  • spring.jpa.show-sql show all quries in console
  • spring.jpa.properties.hibernate.format_sql make more eazy to read quries in console

projectSecurityConfig.java



SIGN IN

  • There are users in user table

  • you can enter by using this username and password in security login page

profile
신입 웹개발자입니다.

0개의 댓글