提交 64b5ef15 编写于 作者: alvachien's avatar alvachien

Refactor the HTML pages

上级 2aa9a110
package com.poc.alvachien.authserverdemo.component;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
public class AuthenticationEvents {
private static final Logger log = LoggerFactory.getLogger(AuthenticationEvents.class);
// Available events:
// Refer to : https://docs.spring.io/spring-security/reference/servlet/authentication/events.html
@EventListener
public void onSuccess(AuthenticationSuccessEvent success) {
log.info("Authorizaton success: ", success.toString());
}
@EventListener
public void onFailure(AbstractAuthenticationFailureEvent failures) {
log.info("Authorizaton failed: ", failures.toString());
}
}
......@@ -17,9 +17,12 @@ import com.nimbusds.jose.jwk.source.JWKSource;
import com.nimbusds.jose.proc.SecurityContext;
import com.poc.alvachien.authserverdemo.service.MyUserDetailsService;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationEventPublisher;
import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
......@@ -97,7 +100,7 @@ public class SecurityConfig {
form -> form
.loginPage("/login")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/users")
.defaultSuccessUrl("/user")
.permitAll()
)
.logout(
......@@ -203,10 +206,10 @@ public class SecurityConfig {
@Bean
public PasswordEncoder passwordEncoder() {
String idForEncode = "bcrypt";
Map encoders = new HashMap<>();
Map<String, PasswordEncoder> encoders = new HashMap<>();
encoders.put(idForEncode, new BCryptPasswordEncoder());
//encoders.put("noop", NoOpPasswordEncoder.getInstance());
encoders.put("pbkdf2", Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_5());
//encoders.put("pbkdf2", Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_5());
encoders.put("pbkdf2@SpringSecurity_v5_8", Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8());
//encoders.put("scrypt", SCryptPasswordEncoder.defaultsForSpringSecurity_v4_1());
encoders.put("scrypt@SpringSecurity_v5_8", SCryptPasswordEncoder.defaultsForSpringSecurity_v5_8());
......@@ -217,5 +220,10 @@ public class SecurityConfig {
PasswordEncoder passwordEncoder = new DelegatingPasswordEncoder(idForEncode, encoders);
return passwordEncoder;
}
@Bean
public AuthenticationEventPublisher authenticationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
return new DefaultAuthenticationEventPublisher(applicationEventPublisher);
}
}
......@@ -70,12 +70,19 @@ public class MainController {
return "redirect:/register?success";
}
@GetMapping("/users")
@GetMapping("/user")
public String currentUser(Model model) {
log.info("Requiring /user");
return "user";
}
@GetMapping("/admin")
public String listRegisteredUsers(Model model){
log.info("Requiring /users");
log.info("Requiring /admin");
List<UserAccountDto> users = userService.findAllUsers();
model.addAttribute("users", users);
return "users";
return "admin";
}
}
......@@ -3,11 +3,9 @@ package com.poc.alvachien.authserverdemo.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.poc.alvachien.authserverdemo.model.AuthorizationConsent;
@Repository
public interface AuthorizationConsentRepository extends JpaRepository<AuthorizationConsent, AuthorizationConsent.AuthorizationConsentId> {
Optional<AuthorizationConsent> findByRegisteredClientIdAndPrincipalName(String registeredClientId, String principalName);
void deleteByRegisteredClientIdAndPrincipalName(String registeredClientId, String principalName);
......
......@@ -5,11 +5,9 @@ import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.poc.alvachien.authserverdemo.model.Authorization;
@Repository
public interface AuthorizationRepository extends JpaRepository<Authorization, String> {
Optional<Authorization> findByState(String state);
Optional<Authorization> findByAuthorizationCodeValue(String authorizationCode);
......
......@@ -3,11 +3,9 @@ package com.poc.alvachien.authserverdemo.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.poc.alvachien.authserverdemo.model.Client;
@Repository
public interface ClientRepository extends JpaRepository<Client, String> {
Optional<Client> findByClientId(String clientId);
}
......@@ -59,8 +59,7 @@ public class JpaOAuth2AuthorizationConsentService implements OAuth2Authorization
"The RegisteredClient with id '" + registeredClientId + "' was not found in the RegisteredClientRepository.");
}
OAuth2AuthorizationConsent.Builder builder = OAuth2AuthorizationConsent.withId(
registeredClientId, authorizationConsent.getPrincipalName());
OAuth2AuthorizationConsent.Builder builder = OAuth2AuthorizationConsent.withId(registeredClientId, authorizationConsent.getPrincipalName());
if (authorizationConsent.getAuthorities() != null) {
for (String authority : StringUtils.commaDelimitedListToSet(authorizationConsent.getAuthorities())) {
builder.authority(new SimpleGrantedAuthority(authority));
......
server.port:9600
server.port=9600
spring.mvc.static-path-pattern: /static/**
spring.mvc.static-path-pattern=/static/**
#thymeleaf
spring.thymeleaf.cache=false
......@@ -11,4 +11,4 @@ spring.datasource.url=jdbc:sqlserver://localhost;encrypt=true;database=authdemo;
#spring.datasource.username=springuser
#spring.datasource.password=ThePassword
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql: true
spring.jpa.show-sql=true
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
<footer class="pt-4 my-md-5 pt-md-5 border-top" th:fragment="footer">
<div class="row">
<div class="col-12 col-md">
<img class="mb-2" th:src="@{/static/img/logo.svg}" alt="" width="24" height="19">
<small class="d-block mb-3 text-muted">© 2017–2023</small>
</div>
<div class="col-6 col-md">
<h5>Features</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Cool stuff</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Random feature</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Team feature</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Stuff for developers</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Another one</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Last time</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>Resources</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Resource</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Resource name</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Another resource</a>
</li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Final resource</a></li>
</ul>
</div>
</div>
</footer>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
<header th:fragment="header">
<div class="d-flex flex-column flex-md-row align-items-center pb-3 mb-4 border-bottom">
<a href="/" class="d-flex align-items-center text-dark text-decoration-none">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="32" class="me-2" viewBox="0 0 118 94"
role="img">
<title>AC Auth. Server</title>
<path fill-rule="evenodd" clip-rule="evenodd"
d="M24.509 0c-6.733 0-11.715 5.893-11.492 12.284.214 6.14-.064 14.092-2.066 20.577C8.943 39.365 5.547 43.485 0 44.014v5.972c5.547.529 8.943 4.649 10.951 11.153 2.002 6.485 2.28 14.437 2.066 20.577C12.794 88.106 17.776 94 24.51 94H93.5c6.733 0 11.714-5.893 11.491-12.284-.214-6.14.064-14.092 2.066-20.577 2.009-6.504 5.396-10.624 10.943-11.153v-5.972c-5.547-.529-8.934-4.649-10.943-11.153-2.002-6.484-2.28-14.437-2.066-20.577C105.214 5.894 100.233 0 93.5 0H24.508zM80 57.863C80 66.663 73.436 72 62.543 72H44a2 2 0 01-2-2V24a2 2 0 012-2h18.437c9.083 0 15.044 4.92 15.044 12.474 0 5.302-4.01 10.049-9.119 10.88v.277C75.317 46.394 80 51.21 80 57.863zM60.521 28.34H49.948v14.934h8.905c6.884 0 10.68-2.772 10.68-7.727 0-4.643-3.264-7.207-9.012-7.207zM49.948 49.2v16.458H60.91c7.167 0 10.964-2.876 10.964-8.281 0-5.406-3.903-8.178-11.425-8.178H49.948z"
fill="currentColor"></path>
</svg>
<span class="fs-4">AC Auth. Server</span>
</a>
<nav class="d-inline-flex mt-2 mt-md-0 ms-md-auto">
<a class="me-3 py-2 text-dark text-decoration-none" href="/login">Login</a>
<a class="me-3 py-2 text-dark text-decoration-none" href="/register">Register</a>
<a class="py-2 text-dark text-decoration-none" href="/about">About</a>
</nav>
</div>
</header>
</body>
</html>
\ No newline at end of file
......@@ -63,33 +63,19 @@
<body>
<div class="container py-3">
<header>
<div class="d-flex flex-column flex-md-row align-items-center pb-3 mb-4 border-bottom">
<a href="/" class="d-flex align-items-center text-dark text-decoration-none">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="32" class="me-2" viewBox="0 0 118 94"
role="img">
<title>AC Auth. Server</title>
<path fill-rule="evenodd" clip-rule="evenodd"
d="M24.509 0c-6.733 0-11.715 5.893-11.492 12.284.214 6.14-.064 14.092-2.066 20.577C8.943 39.365 5.547 43.485 0 44.014v5.972c5.547.529 8.943 4.649 10.951 11.153 2.002 6.485 2.28 14.437 2.066 20.577C12.794 88.106 17.776 94 24.51 94H93.5c6.733 0 11.714-5.893 11.491-12.284-.214-6.14.064-14.092 2.066-20.577 2.009-6.504 5.396-10.624 10.943-11.153v-5.972c-5.547-.529-8.934-4.649-10.943-11.153-2.002-6.484-2.28-14.437-2.066-20.577C105.214 5.894 100.233 0 93.5 0H24.508zM80 57.863C80 66.663 73.436 72 62.543 72H44a2 2 0 01-2-2V24a2 2 0 012-2h18.437c9.083 0 15.044 4.92 15.044 12.474 0 5.302-4.01 10.049-9.119 10.88v.277C75.317 46.394 80 51.21 80 57.863zM60.521 28.34H49.948v14.934h8.905c6.884 0 10.68-2.772 10.68-7.727 0-4.643-3.264-7.207-9.012-7.207zM49.948 49.2v16.458H60.91c7.167 0 10.964-2.876 10.964-8.281 0-5.406-3.903-8.178-11.425-8.178H49.948z"
fill="currentColor"></path>
</svg>
<span class="fs-4">AC Auth. Server</span>
</a>
<nav class="d-inline-flex mt-2 mt-md-0 ms-md-auto">
<a class="me-3 py-2 text-dark text-decoration-none" href="/login">Login</a>
<a class="me-3 py-2 text-dark text-decoration-none" href="/register">Register</a>
<a class="py-2 text-dark text-decoration-none" href="/about">About</a>
</nav>
</div>
<div th:replace="~{fragments/header :: header}">
Header
</div>
<main>
<div class="website-header p-3 pb-md-4 mx-auto text-center">
<h1 class="display-4 fw-normal">AC Auth. Server</h1>
<p class="fs-5 text-muted">AC Auth. Server is an authorization server, including authentication server. It is used to for authorization server for apps.</p>
<p class="fs-5 text-muted">AC Auth. Server is an authorization server, including authentication part.
It is used to for authorization server for apps based on OIDC.
It also provides the registeration, user Management support.
</p>
</div>
</header>
<main>
<div class="row row-cols-1 row-cols-md-3 mb-3 text-center">
<div class="col">
<div class="card mb-4 rounded-3 shadow-sm">
......@@ -102,6 +88,7 @@
<li>Knowledge Management</li>
<li>Exercise Bank</li>
<li>Learning history</li>
<li>Puzzle games</li>
</ul>
<button type="button" class="w-100 btn btn-lg btn-outline-primary">Launch</button>
</div>
......@@ -144,45 +131,7 @@
</div>
</main>
<footer class="pt-4 my-md-5 pt-md-5 border-top">
<div class="row">
<div class="col-12 col-md">
<img class="mb-2" th:src="@{/static/img/log.svg}" alt="" width="24" height="19">
<small class="d-block mb-3 text-muted">© 2017–2023</small>
</div>
<div class="col-6 col-md">
<h5>Features</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Cool stuff</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Random feature</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Team feature</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Stuff for
developers</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Another one</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Last time</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>Resources</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Resource</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Resource name</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Another resource</a>
</li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Final resource</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>About</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Team</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Locations</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Privacy</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Terms</a></li>
</ul>
</div>
</div>
</footer>
<div th:replace="~{fragments/footer :: footer}">&copy; 2022 - 2023</div>
</div>
</body>
......
......@@ -12,30 +12,13 @@
<body>
<div class="container py-3">
<header>
<div class="d-flex flex-column flex-md-row align-items-center pb-3 mb-4 border-bottom">
<a href="/" class="d-flex align-items-center text-dark text-decoration-none">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="32" class="me-2" viewBox="0 0 118 94"
role="img">
<title>AC Auth. Server</title>
<path fill-rule="evenodd" clip-rule="evenodd"
d="M24.509 0c-6.733 0-11.715 5.893-11.492 12.284.214 6.14-.064 14.092-2.066 20.577C8.943 39.365 5.547 43.485 0 44.014v5.972c5.547.529 8.943 4.649 10.951 11.153 2.002 6.485 2.28 14.437 2.066 20.577C12.794 88.106 17.776 94 24.51 94H93.5c6.733 0 11.714-5.893 11.491-12.284-.214-6.14.064-14.092 2.066-20.577 2.009-6.504 5.396-10.624 10.943-11.153v-5.972c-5.547-.529-8.934-4.649-10.943-11.153-2.002-6.484-2.28-14.437-2.066-20.577C105.214 5.894 100.233 0 93.5 0H24.508zM80 57.863C80 66.663 73.436 72 62.543 72H44a2 2 0 01-2-2V24a2 2 0 012-2h18.437c9.083 0 15.044 4.92 15.044 12.474 0 5.302-4.01 10.049-9.119 10.88v.277C75.317 46.394 80 51.21 80 57.863zM60.521 28.34H49.948v14.934h8.905c6.884 0 10.68-2.772 10.68-7.727 0-4.643-3.264-7.207-9.012-7.207zM49.948 49.2v16.458H60.91c7.167 0 10.964-2.876 10.964-8.281 0-5.406-3.903-8.178-11.425-8.178H49.948z"
fill="currentColor"></path>
</svg>
<span class="fs-4">AC Auth. Server</span>
</a>
<nav class="d-inline-flex mt-2 mt-md-0 ms-md-auto">
<a class="me-3 py-2 text-dark text-decoration-none" href="/login">Login</a>
<a class="me-3 py-2 text-dark text-decoration-none" href="/register">Register</a>
<a class="py-2 text-dark text-decoration-none" href="/about">About</a>
</nav>
</div>
</header>
<div th:replace="~{fragments/header :: header}">
Header
</div>
<main class="form-signin w-100 m-auto">
<form>
<img class="mb-4" th:src="@{img/log.svg}" alt="" width="72" height="57">
<img class="mb-4" th:src="@{/static/img/logo.svg}" alt="" width="72" height="57">
<h1 class="h3 mb-3 fw-normal">Please sign in</h1>
<div class="form-floating">
......@@ -55,48 +38,9 @@
</form>
</main>
<footer class="pt-4 my-md-5 pt-md-5 border-top">
<div class="row">
<div class="col-12 col-md">
<img class="mb-2" th:src="@{/static/img/log.svg}" alt="" width="24" height="19">
<small class="d-block mb-3 text-muted">© 2017–2023</small>
</div>
<div class="col-6 col-md">
<h5>Features</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Cool stuff</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Random feature</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Team feature</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Stuff for
developers</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Another one</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Last time</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>Resources</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Resource</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Resource name</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Another resource</a>
</li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Final resource</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>About</h5>
<ul class="list-unstyled text-small">
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Team</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Locations</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Privacy</a></li>
<li class="mb-1"><a class="link-secondary text-decoration-none" href="#">Terms</a></li>
</ul>
</div>
</div>
</footer>
<div th:replace="~{fragments/footer :: footer}">&copy; 2022 - 2023</div>
</div>
</body>
</html>
\ No newline at end of file
</html>
......@@ -33,44 +33,6 @@
<h2 class="text-center">Registration</h2>
</div>
<div class="card-body">
<form method="post" role="form" th:action="@{/register/save}" th:object="${user}">
<div class="form-group mb-3">
<label class="form-label">First Name</label>
<input class="form-control" id="firstName" name="firstName" placeholder="Enter first name"
th:field="*{firstName}" type="text" />
<p th:errors="*{firstName}" class="text-danger" th:if="${#fields.hasErrors('firstName')}">
</p>
</div>
<div class="form-group mb-3">
<label class="form-label">Last Name</label>
<input class="form-control" id="lastName" name="lastName" placeholder="Enter last name"
th:field="*{lastName}" type="text" />
<p th:errors="*{lastName}" class="text-danger" th:if="${#fields.hasErrors('lastName')}">
</p>
</div>
<div class="form-group mb-3">
<label class="form-label">Email</label>
<input class="form-control" id="email" name="email" placeholder="Enter email address"
th:field="*{email}" type="email" />
<p th:errors="*{email}" class="text-danger" th:if="${#fields.hasErrors('email')}">
</p>
</div>
<div class="form-group mb-3">
<label class="form-label">Password</label>
<input class="form-control" id="password" name="password" placeholder="Enter password"
th:field="*{password}" type="password" />
<p th:errors="*{password}" class="text-danger" th:if="${#fields.hasErrors('password')}">
</p>
</div>
<div class="form-group mb-3">
<button class="btn btn-primary" type="submit">Register</button>
<span>Already registered? <a href="/" th:href="@{/login}">Login
here</a></span>
</div>
</form>
</div>
</div>
</div>
......
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>AC Auth. System</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" th:href="@{/static/css/login.css}" />
</head>
<body>
<div class="container py-3">
<div th:replace="~{fragments/header :: header}">
Header
</div>
<main class="form-signin w-100 m-auto">
<!-- <form>
<img class="mb-4" th:src="@{img/log.svg}" alt="" width="72" height="57">
<h1 class="h3 mb-3 fw-normal">Please sign in</h1>
<div class="form-floating">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Password">
<label for="floatingPassword">Password</label>
</div>
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> Remember me </label>
</div>
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
</form> -->
<form method="post" role="form" th:action="@{/register/save}" th:object="${user}">
<img class="mb-4" th:src="@{/static/img/logo.svg}" alt="" width="72" height="57">
<h1 class="h3 mb-3 fw-normal">Please register with following</h1>
<div class="form-group mb-3">
<label class="form-label">First Name</label>
<input class="form-control" id="firstName" name="firstName" placeholder="Enter first name"
th:field="*{firstName}" type="text" />
<p th:errors="*{firstName}" class="text-danger" th:if="${#fields.hasErrors('firstName')}">
</p>
</div>
<div class="form-group mb-3">
<label class="form-label">Last Name</label>
<input class="form-control" id="lastName" name="lastName" placeholder="Enter last name"
th:field="*{lastName}" type="text" />
<p th:errors="*{lastName}" class="text-danger" th:if="${#fields.hasErrors('lastName')}">
</p>
</div>
<div class="form-group mb-3">
<label class="form-label">Email</label>
<input class="form-control" id="email" name="email" placeholder="Enter email address"
th:field="*{email}" type="email" />
<p th:errors="*{email}" class="text-danger" th:if="${#fields.hasErrors('email')}">
</p>
</div>
<div class="form-group mb-3">
<label class="form-label">Password</label>
<input class="form-control" id="password" name="password" placeholder="Enter password"
th:field="*{password}" type="password" />
<p th:errors="*{password}" class="text-danger" th:if="${#fields.hasErrors('password')}">
</p>
</div>
<div class="form-group mb-3">
<button class="btn btn-primary" type="submit">Register</button>
<span>Already registered? <a href="/" th:href="@{/login}">Login
here</a></span>
</div>
</form>
</main>
<div th:replace="~{fragments/footer :: footer}">&copy; 2022 - 2023</div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>AC Auth. System</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" th:href="@{/static/css/login.css}"/>
</head>
<body>
<div class="container py-3">
<div th:replace="~{fragments/header :: header}">
Header
</div>
<div>
Current User
</div>
<div th:replace="~{fragments/footer :: footer}">&copy; 2022 - 2023</div>
</div>
</body>
</html>
......@@ -14,6 +14,7 @@ This article adds the JPA implementations to client/authorization/authorization-
- [How-to: Customize the OpenID Connect 1.0 UserInfo response](https://docs.spring.io/spring-authorization-server/docs/current/reference/html/guides/how-to-userinfo.html)
- [OidcUserInfo](https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/oauth2/core/oidc/OidcUserInfo.html)
- [OidcUserInfo.Builder](https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/oauth2/core/oidc/OidcUserInfo.Builder.html)
- [Spring Security: Authentication - JDBC Authentication](https://docs.spring.io/spring-security/reference/servlet/authentication/passwords/jdbc.html#servlet-authentication-jdbc-schema)
- [Spring Authorization Server Tutorial](https://www.appsdeveloperblog.com/spring-authorization-server-tutorial/)
- [Add Roles to JWT Issued by Spring Authorization Server](https://www.appsdeveloperblog.com/add-roles-to-jwt-issued-by-new-spring-authorization-server/)
- [Role-based Access Control in Spring Authorization Server](https://www.appsdeveloperblog.com/role-based-access-control-in-spring-authorization-server/)
......
......@@ -11,9 +11,10 @@ public class ResourceServerConfig {
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.requestMatchers("/api/protected/**").authenticated()
.requestMatchers("/").permitAll();
.authorizeHttpRequests((authorize) -> authorize
.requestMatchers("/").permitAll()
.anyRequest().authenticated()
);
return http.build();
}
}
......@@ -3,8 +3,6 @@ package com.poc.alvachien.resourceserverdemo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
@RequestMapping("/api/protected")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册