1
1
.
.
1
1
0
0
.
.
1
1
S
S
t
t
e
e
p
p
1
1
:
:
C
C
o
o
p
p
y
y
P
P
r
r
o
o
j
j
e
e
c
c
t
t
I
I
n
n
f
f
o
o
[
[
G
G
]
]
Since we want to use User - From DB tutorial as starting point, this tutorial shows how to create new Project, copy
content of User - From DB tutorial into it and then test functionality to make sure that everything works correctly.
Application Schema [Results]
DB Schema
DB Table: Account (Loaded Data)
ID
USERNAME
PASSWORD
ROLE
1
john
johnpassword
ROLE_ADMIN
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @Controller, @RequestMapping and Tomcat Server
SQL
Spring Data JPA
Enables @Entity and @Id
SQL
PostgreSQL Database
Enables Hibernate to work with PostgreSQL DB
Security
Spring Security
Enables Spring Security
Template Engines
Thyemeleaf
Enables Controller to return reference to HTML Page index.html
Developer Tools
Lombok
Enables @Data which generate helper methods (setters, getters, ...)
ACCOUNT
MyController
http://localhost:8080/hello
Tomcat
sayHello()
Browser
Account
AccountRepository
SecurityConfig
AccountLoader
AccountService
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: springboot_security_2f (add Spring Boot Starters from the table)
Copy Project: User - From DB (overwrite src Directory, rename main Package & Class to reflect new Name)
Edit File: application.properties (specify PostgreSQL DB)
application.properties
# POSTGRESQL DATABASE
spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = letmein
spring.datasource.driver-class-name = org.postgresql.Driver
# JPA / HIBERNATE
spring.jpa.hibernate.ddl-auto = create-drop
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8080/hello
You get redirected to http://localhost:8080/login
Username: john
Password: johnpassword
Sign in
You get redirected back to http://localhost:8080/hello
http://localhost:8080/login - john - johnpassword
http://localhost:8080/hello
DB Table: Account (Loaded Data)