- Добавил аутентификацию с помощью Spring Security.

- Реализовал кастомные  CustomUserDetails и CustomUserDetailsService

https://www.youtube.com/watch?v=WDlifgLS8iQ&list=PLU2ftbIeotGoGSEUf54LQH-DgiQPF2XRO&index=3
https://spring.io/guides/gs/securing-web
https://medium.com/@CodeWithTech/spring-security-with-jdbcuserdetailsmanager-and-custom-userdetailsservice-a-complete-guide-248ddce0196c
This commit is contained in:
Leonid
2025-02-06 23:11:24 +03:00
parent 7583c00749
commit 42a1b7466b
17 changed files with 358 additions and 24 deletions

View File

@@ -3,4 +3,5 @@ spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/sweater_db
spring.datasource.username=user
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.mustache.servlet.expose-request-attributes=true

View File

@@ -5,6 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>Hello {{name}}!!!</div>
<div>Hello there</div>
<a href="/main">Main page</a>
</body>
</html>

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Spring Security Example </title>
</head>
<body>
Login page
<form action="/login" method="post">
<div><label> User Name : <input type="text" name="username"/> </label></div>
<div><label> Password: <input type="password" name="password"/> </label></div>
<div><input type="submit" value="Sign In"/></div>
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
</form>
<a href="/registration">Add new user</a>
</body>
</html>

View File

@@ -1,19 +1,29 @@
<html>
<body>
<div>
<form method="post">
<input type="text" name="text" placeholder="Enter message"> </input>
<input type="text" name="tag" placeholder="tag"></input>
<button type="submit">Add message</button>
</form>
</div
<form action="/logout" method="post">
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
<input type="submit" value="Sign Out"/>
</form>
</div>
<div>
<form method="post" action="filter">
Tag to filer
<br>
<input type="text" name="tag">
<button>Find</button>
</form>
<form method="post">
<input type="text" name="text" placeholder="Enter message"> </input>
<input type="text" name="tag" placeholder="tag"></input>
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
<button type="submit">Add message</button>
</form>
</div>
<div>
<form method="post" action="filter">
Tag to filer
<br>
<input type="text" name="tag">
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
<button>Find</button>
</form>
</div>
<div>Messages list</div>
@@ -24,6 +34,5 @@ Tag to filer
<i>{{tag}}</i>
</div>
{{/messages}}
</body>
</html>

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Spring Security Example </title>
</head>
<body>
Registration page
<br>
{{#message}}
{{message}}
{{/message}}
<form action="/registration" method="post">
<div><label> User Name : <input type="text" name="username"/> </label></div>
<div><label> Password: <input type="password" name="password"/> </label></div>
<div><input type="submit" value="Add user"/></div>
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
</form>
</body>
</html>