java database
-
Spring Boot, MVC, Security, Thymeleaf, H2, JSP
GitHub проекта: https://github.com/cherepakhin/springboot-thymeleaf-security-demo
Демонстрация SpringBoot WEB приложения с авторизацией и аутентификаци Spring Security.
Использованы следующие технологии:- Spring Boot
- Spring MVC
- Thymeleaf
- Spring Security
- Spring Data JPA
- MySQL
Запуск
Java 11
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 ./mvnw spring-boot:run
Открыть в браузере: http://localhost:8080/
Вход в программу по email- User:
Адрес электронной почты защищен от спам-ботов. Для просмотра адреса в браузере должен быть включен Javascript. Password: admin - User:
Адрес электронной почты защищен от спам-ботов. Для просмотра адреса в браузере должен быть включен Javascript. Password: user
Открыть домашнюю страницу пользователя: http://127.0.0.1:8080/home
Она будет разная для разных пользователей.Screens
__Not__ logged: 
Interface for Admin
View for admin: 
- Added menu "To Admin"
- you see message __"You will see this only if you are ADMIN"__): 
Interface for User
Result to admin page for user: For __user__ login:  Not access to __Admin page__ for user: ) [userhome.html](src/main/resources/templates/userhome.html) (line 20): ````html
You will see this only if you are ADMIN
```` __WebSecurityConfig.java defines the rules for accessing pages.__
Mobile screens

Link action form to java code
Form (html):
link: th:object="${content}" th:action="@{/new_message}" method="post"New Message
<div class="container" style="padding-left: 0px; margin-left: 0px;"> <form class="form-horizontal" th:object="${content}" th:action="@{/new_message}" name="new_form" id="edit_form" method="post" role="form"> // <--- POST!!! /new_message <div class="form-group" style="margin-left: 0px;"> <label for="message_content">Сообщение (max 100 символов):</label> <input class="form-control" id="content" maxlength="100" type="text" th:name="content"/> </div> <button type="submit" class="btn btn-primary" value="Save">Сохранить</button> <a class="btn btn-default" th:href="@{/home}">Отмена</a> </form> </div>Handler in Java code (@PostMapping("/new_message")):
- Method POST: @PostMapping(value = "/new_message")
- Value: th:object="${content}"
Обработка в Java-коде контроллера:
@Controller public class HomeController { @PostMapping(value = "/new_message") public String newMessage(@RequestParam(defaultValue = "----", value = "content") String newContent) { ... } }Покрытие тестами (test coverage)
./mvnw clean test ./mvnw jacoco:report
Open target/site/jacoco/index.html](target/site/jacoco/index.html
Links
- https://github.com/dkubrakov/spring-boot-thymeleaf-security
- https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
- https://www.javaguides.net/2018/09/spring-boot-spring-mvc-role-based-spring-security-jpa-thymeleaf-mysql-tutorial.html
Разное
Подключение к MySQL из shell:
mysql -u vasi -h v -p
database: thymeleaf_security_demo
TODO
- tests
- paging messages