1
1
.
.
3
3
.
.
1
1
A
A
u
u
t
t
o
o
m
m
a
a
t
t
i
i
c
c
-
-
L
L
o
o
g
g
i
i
n
n
F
F
o
o
r
r
m
m
-
-
D
D
e
e
f
f
a
a
u
u
l
l
t
t
I
I
n
n
f
f
o
o
[
[
G
G
]
]
This tutorial shows how to allow User to provide Username and Password through default Login Form.
User is stored in application.properties (these two tutorials are exactly the same since they both use default Login Form).
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @RequestMapping, Tomcat Server
Security
Spring Security
Enables Spring Security
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: springboot_security_default (add Spring Boot Starters from the table)
Edit File: application.properties (add Role, User, Password)
Create Package: controllers (inside main package)
Create Class: MyController.java (inside controllers package)
application.properties
# SECURITY
spring.security.user.name = myuser
spring.security.user.password = mypassword
spring.security.user.roles = USER
MyController.java
package com.ivoronline.springboot_security_default.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
return "Hello from Controller";
}
}
MyController
http://localhost:8080/Hello
Tomcat
Browser
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: myuser
Password: mypassword
Sign in
You get redirected back to http://localhost:8080/Hello
Logout Form http://localhost:8080/logout
Log Out
http://localhost:8080/login
Redirects to http://localhost:8080/Hello
http://localhost:8080/logout