1
1
.
.
2
2
.
.
1
1
D
D
e
e
f
f
a
a
u
u
l
l
t
t
U
U
s
s
e
e
r
r
I
I
n
n
f
f
o
o
[
[
G
G
]
]
This tutorial shows how to use Default User that has
Username: user
Password: (randomly generated when you start Application, it is displayed in the Console)
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @RequestMapping and Tomcat
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)
Create Package: controllers (inside main package)
Create Class: MyController.java (inside controllers package)
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: user
Password: 506e6f00-2b11-4036-96d6-74633e94da2d (copy from Console output)
Sign in (JSESSIONID Cookie is returned and stored in your Browser)
You get redirected back to http://localhost:8080/Hello
http://localhost:8080/logout
Log Out
Console
Using generated security password: 506e6f00-2b11-4036-96d6-74633e94da2d
http://localhost:8080/login (JSESSIONID Cookie is stored in the Browser)
Redirects to http://localhost:8080/Hello
http://localhost:8080/logout (Redirects to http://localhost:8080/login)
Application Structure (Temporary Code is displayed in the Console)
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>