- Добавил аутентификацию с помощью 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:
@@ -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
|
||||
|
||||
|
||||
@@ -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>
|
||||
16
src/main/resources/templates/login.mustache
Normal file
16
src/main/resources/templates/login.mustache
Normal 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>
|
||||
@@ -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>
|
||||
20
src/main/resources/templates/registration.mustache
Normal file
20
src/main/resources/templates/registration.mustache
Normal 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>
|
||||
Reference in New Issue
Block a user