Skip to content

Commit 4c5ff61

Browse files
committed
Add Custom Pages Sample
1 parent cb1b716 commit 4c5ff61

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.example.magiclink;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.Profile;
6+
import org.springframework.security.config.Customizer;
7+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8+
import org.springframework.security.web.SecurityFilterChain;
9+
import org.springframework.stereotype.Controller;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
12+
@Profile("custom-pages")
13+
@Configuration(proxyBeanMethods = false)
14+
public class CustomPagesSecurityConfig {
15+
16+
@Controller
17+
@Profile("custom-pages")
18+
static class LoginController {
19+
@GetMapping("/login/form")
20+
public String login() {
21+
return "login";
22+
}
23+
24+
@GetMapping("/login/ott")
25+
public String ott() {
26+
return "ott";
27+
}
28+
}
29+
30+
@Bean
31+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
32+
// @formatter:off
33+
http
34+
.authorizeHttpRequests((authz) -> authz.anyRequest().authenticated())
35+
.formLogin((form) -> form
36+
.loginPage("/login/form").permitAll()
37+
.factor(Customizer.withDefaults())
38+
)
39+
.oneTimeTokenLogin((ott) -> ott
40+
.loginPage("/login/ott").permitAll()
41+
.factor(Customizer.withDefaults())
42+
);
43+
// @formatter:on
44+
return http.build();
45+
}
46+
}

servlet/spring-boot/java/authentication/mfa/formLogin+ott/src/main/resources/templates/login.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<meta name="description" content="">
77
<meta name="author" content="">
88
<title>Please sign in</title>
9-
<link href="/css/default-ui.css" rel="stylesheet" />
9+
<link href="/default-ui.css" rel="stylesheet" />
1010
</head>
1111
<body>
1212
<div class="content">
13-
<form class="login-form" method="post" th:action="@{/login}">
13+
<form class="login-form" method="post" th:action="@{/login/form}">
1414
<h2>Please sign in</h2>
1515

1616
<p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="https://www.thymeleaf.org" lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="description" content="">
7+
<meta name="author" content="">
8+
<title>Please sign in</title>
9+
<link href="/default-ui.css" rel="stylesheet" />
10+
</head>
11+
<body>
12+
<div class="content">
13+
<form class="login-form" method="post" th:action="@{/login/ott}">
14+
<h2>Please supply a token</h2>
15+
16+
<p>
17+
<label for="token" class="screenreader">Token</label>
18+
<input type="text" id="token" name="token" placeholder="Token" required autofocus>
19+
</p>
20+
21+
<button type="submit" class="primary">Use this Token</button>
22+
</form>
23+
</div>
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)