Skip to content

Commit e81569f

Browse files
Production deployment (#1)
* Change packaging type from WAR to JAR and add TiDB Driver dependency in pom.xml * Update email configuration in MailConfig.java and application.properties with new credentials * Update email configuration and enhance test data initialization * Add JAVA_OPTS for production profile and enhance transaction management in UserServiceImpl * Add fake data section to README.md and enhance email configuration in MailConfig.java and application properties * Refactor README.md for role descriptions and enhance user creation forms in AuthController, EntrantController, StudentController, UserController * Refactor error logging in StudentController to improve clarity of error messages during student creation and update failures * Refactor error handling in StudentController to enhance logging and clarity of error messages during student creation and update processes * Update README.md for improved role formatting and enhance regex validation for email and username in Login.html * Enhance README.md with user data and Ethereal credentials sections; update regex for username validation in registration and user forms * Update user data in dump_with_db.sql with new hashed passwords for improved security
1 parent 0fc5f7e commit e81569f

File tree

24 files changed

+341
-107
lines changed

24 files changed

+341
-107
lines changed

README.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
- [Prerequisites](#prerequisites)
3737
- [Steps](#steps)
3838
- [Testing](#testing)
39+
- [Fake data](#fake-data)
40+
- [User data](#user-data)
41+
- [Ethereal credentials](#ethereal-credentials)
3942
- [Usage](#usage)
4043
- [Web Application Results](#web-application-results)
4144
- [1 Registering a New User and Displaying Available Functionality for a Student Viewer](#1-registering-a-new-user-and-displaying-available-functionality-for-a-student-viewer)
@@ -112,19 +115,20 @@ The project is structured as a series of incremental laboratory works (labs), ea
112115

113116
1. **User Authentication & Registration**: Secure login form with password hashing (BCrypt). Admin-only user creation; self-registration assigns "STUDENT_VIEWER" role.
114117
2. **Role-Based Authorization**:
115-
* `ADMIN`: Full CRUD on all entities (users, entrants, students).
116-
* `ENTRANT_MANAGER`: Full CRUD on entrants; read-only on students.
117-
* `STUDENT_MANAGER`: Full CRUD on students; read-only on entrants.
118-
* `ENTRANT_VIEWER`: Read-only on entrants.
119-
* `STUDENT_VIEWER`: Read-only on students.
120-
3. **CRUD Operations**: Create, read, update, delete for entrants, students, and users (with foreign key constraints).
121-
4. **Data Management**: Filtering, sorting, searching, and pagination for entity tables.
122-
5. **Session Handling**: Display logged-in user name/role; automatic logout after inactivity.
123-
6. **Validation**: Custom validators for fields (e.g., IDs, birthdays, usernames, emails).
124-
7. **Frontend**: Responsive UI with Bootstrap; Thymeleaf templates for dynamic content.
125-
8. **Database Integration**: MySQL schema with tables for entrants, students, and users (one-to-one relationship between entrants and students).
126-
9. **Testing**: JUnit tests for services and application functionality.
127-
10. **Logging**: Configured via Logback.
118+
* <span style="color: #fd7e14;">**ADMIN**</span>: Full CRUD on all entities (users, entrants, students).
119+
* <span style="color: #198754;">**ENTRANT_MANAGER**</span>: Full CRUD on entrants; read-only on students.
120+
* <span style="color: #6f42c1;">**STUDENT_MANAGER**</span>: Full CRUD on students; read-only on entrants.
121+
* <span style="color: #20c997;">**ENTRANT_VIEWER**</span>: Read-only on entrants.
122+
* <span style="color: #6610f2;">**STUDENT_VIEWER**</span>: Read-only on students.
123+
3. **Email notification**: Automatic sending of an email with a link to reset the password to newly created users by the administrator. Sending an email to reset the password at the user's request.
124+
4. **CRUD Operations**: Create, read, update, delete for entrants, students, and users (with foreign key constraints).
125+
5. **Data Management**: Filtering, sorting, searching, and pagination for entity tables.
126+
6. **Session Handling**: Display logged-in user name/role; automatic logout after inactivity.
127+
7. **Validation**: Custom validators for fields (e.g., IDs, birthdays, usernames, emails).
128+
8. **Frontend**: Responsive UI with Bootstrap; Thymeleaf templates for dynamic content.
129+
9. **Database Integration**: MySQL schema with tables for entrants, students, and users (one-to-one relationship between entrants and students).
130+
10. **Testing**: JUnit tests for services and application functionality.
131+
11. **Logging**: Configured via Logback.
128132

129133

130134

@@ -229,6 +233,34 @@ The structure of the test sets is shown below.
229233

230234

231235

236+
## Fake data
237+
238+
### User data
239+
240+
Here is the fake user data for demo.
241+
242+
| Role | Username | Password | Email |
243+
|:-:|:-|:-|-:|
244+
|<span style="color: #fd7e14;">**ADMIN**</span>|```shavlii_oleksii```|```Password123!$```|```shavlii.oleksii@ntu.khpi.edu.ua```|
245+
|<span style="color: #198754;">**ENTRANT_MANAGER**</span>|```burulka-liudmyla```|```Password123!$```|```burulka.liudmyla@ntu.khpi.edu.ua```|
246+
|<span style="color: #6f42c1;">**STUDENT_MANAGER**</span>|```voloshkov-tymur```|```Password123!$```|```voloshkov.tymur@ntu.khpi.edu.ua```|
247+
|<span style="color: #20c997;">**ENTRANT_VIEWER**</span>|```kulish.volodymyr```|```Password123!$```|```kulish.volodymyr@cs.khpi.edu.ua```|
248+
|<span style="color: #6610f2;">**STUDENT_VIEWER**</span>|```stepova.alina```|```Password123!$```|```stepova.alina@cs.khpi.edu.ua```|
249+
250+
### Ethereal credentials
251+
252+
[Ethereal](https://ethereal.email/) credentials for viewing sent emails:
253+
* login:
254+
```
255+
wilmer.ankunding@ethereal.email
256+
```
257+
* password:
258+
```
259+
GVDW5ZTPSSXuAnRh1y
260+
```
261+
262+
263+
232264
## Usage
233265
234266
1. Login/Register:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
target/
2+
*.jar
3+
*.war
4+
.git
5+
.gitignore
6+
README.md
7+
Dockerfile
8+
.dockerignore
9+
.mvn/wrapper/maven-wrapper.jar
10+
node_modules/
11+
.env
12+
.env.*
13+
*.log

lab4-5/WebAppsRIVLab4/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Використовуємо офіційний OpenJDK 17 образ
2+
FROM openjdk:17-jdk-slim
3+
4+
# Встановлюємо робочу директорію
5+
WORKDIR /app
6+
7+
# Копіюємо Maven wrapper та pom.xml
8+
COPY mvnw .
9+
COPY mvnw.cmd .
10+
COPY .mvn .mvn
11+
COPY pom.xml .
12+
13+
# Робимо mvnw виконуваним
14+
RUN chmod +x ./mvnw
15+
16+
# Завантажуємо залежності (для кешування)
17+
RUN ./mvnw dependency:go-offline -B
18+
19+
# Копіюємо вихідний код
20+
COPY src ./src
21+
22+
# Збираємо додаток
23+
RUN ./mvnw clean package -DskipTests
24+
25+
# Запускаємо додаток
26+
EXPOSE 8080
27+
CMD ["java", "-Dspring.profiles.active=prod", "-jar", "target/WebAppsRIVLab4-0.0.1-SNAPSHOT.jar"]

lab4-5/WebAppsRIVLab4/dump_with_db.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ CREATE TABLE `users` (
156156

157157
LOCK TABLES `users` WRITE;
158158
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
159-
INSERT INTO `users` (`id`, `username`, `name`, `patronymic`, `surname`, `corporate_email`, `password`, `role`) VALUES (1,'shavlii_oleksii','Олексій','Олександрович','Шавлій','shavlii.oleksii@ntu.khpi.edu.ua','$2a$10$rw2shX0X8op96Ln/In95UuHeOCrB2hhE1sG0kqEtvPzCwqMp9cBWi','ADMIN'),(2,'burulka-liudmyla','Людмила','Ярославівна','Бурулька','burulka.liudmyla@ntu.khpi.edu.ua','$2a$10$0jgn1uma0CEVUvVDoSqCFu4S803IxlaCOadlaKQKmdsnf40cvHJN6','ENTRANT_MANAGER'),(3,'voloshkov-tymur','Тимур','Сергійович','Волошков','voloshkov.tymur@ntu.khpi.edu.ua','$2a$10$JSrcpKeZJwXllB1oFNrZY.HFE53Ymd1QgYE9qLc7kl22t9AEBs7PG','STUDENT_MANAGER'),(4,'kulish.volodymyr','Володимир','Анатолійович','Куліш','kulish.volodymyr@cs.khpi.edu.ua','$2a$10$XeOn76jnGsvCDUSrJW3JE.XJE8c0iRVLeJLTWYBCLjPJJoYFN3YYe','ENTRANT_VIEWER'),(5,'stepova.alina','Аліна','Трофимівна','Степова','stepova.alina@cs.khpi.edu.ua','$2a$10$V1.ZIdiEhADsFF3IyYt1YOFwfxDDd13IEpoS0e.HB/oSrCgMMTTrW','STUDENT_VIEWER'),(6,'ivanenko_anna','Анна','Петрівна','Іваненко','ivanenko.anna@ntu.khpi.edu.ua','$2a$10$2WFLmreMo6jQEVY5j.9HPurdIZNsK/ojPhXRPLYeYxE22ZTil2PRK','ADMIN'),(7,'tarasenko-oleh','Олег','Іванович','Тарасенко','tarasenko.oleh@ntu.khpi.edu.ua','$2a$10$Fv..mVUJB3bbWwjzGx6/0.pa6viejweZAOwOPFL63NxvPhHC26ygO','ENTRANT_MANAGER'),(8,'melnyk_daryna','Дарина','Анатоліївна','Мельник','melnyk.daryna@ntu.khpi.edu.ua','$2a$10$skyG3TKSSD2j2Dfd381AKe7LTPu9Itds4VYFpY1cOyw6loVGHJt1u','STUDENT_MANAGER'),(9,'horbunov.vladyslav','Владислав','Михайлович','Горбунов','horbunov.vladyslav@cs.khpi.edu.ua','$2a$10$VHwQVn17o7/aSBPa8dxu9evkKVrbRYvWXBJ.CG5.yDwa/zPL6k6wq','ENTRANT_VIEWER'),(10,'romanova-olena','Олена','Олексіївна','Романова','romanova.olena@cs.khpi.edu.ua','$2a$10$dvoPA.RTXaKbCQ3Imv6lfeRM/zFOu.bYgt12U4C26Aa9zbKPkhT4e','STUDENT_VIEWER'),(11,'vasylchenko.mykhailo','Михайло','Олександрович','Васильченко','vasylchenko.mykhailo@ntu.khpi.edu.ua','$2a$10$vguSRdQ08PlP16fQCmAj/uMohKX2KdWMe/Qu3mh6QPShoSSs7sD9G','ADMIN'),(12,'shapoval-kseniia','Ксенія','Василівна','Шаповал','shapoval.kseniia@ntu.khpi.edu.ua','$2a$10$fzEmxaBKskooEnuKMbxYHeHmpfgMbwJ5VXMnpiXr1QsNYd/s1ItvG','ENTRANT_MANAGER'),(13,'kozak.yevhenii','Євгеній','Олегович','Козак','kozak.yevhenii@ntu.khpi.edu.ua','$2a$10$Pbti3NgX5/46PS/hCL2ccevHFQ2iqYR0hZo4TcxjG2BRYhFO2NBXG','STUDENT_MANAGER'),(14,'bondar.inna','Інна','Ігорівна','Бондар','bondar.inna@cs.khpi.edu.ua','$2a$10$NwNzFn/H9/srWhfX9e.xXOadkByGeFrRRdyBq.VxFlOdpB2uEc3QO','ENTRANT_VIEWER'),(15,'kravchenko-artem','Артем','Богданович','Кравченко','kravchenko.artem@cs.khpi.edu.ua','$2a$10$knc9FdCAvRD6Bc1bvtGOmeVPJcR06U83CFo4lLYkL3hVfnqwet6.S','STUDENT_VIEWER');
159+
INSERT INTO `users` (`id`, `username`, `name`, `patronymic`, `surname`, `corporate_email`, `password`, `role`) VALUES (1,'shavlii_oleksii','Олексій','Олександрович','Шавлій','shavlii.oleksii@ntu.khpi.edu.ua','$2a$10$g339G09X1wZ2IagQEFkVPOAUITzkqcphZ7PLZ.96G6sEl.VTapvGy','ADMIN'),(2,'burulka-liudmyla','Людмила','Ярославівна','Бурулька','burulka.liudmyla@ntu.khpi.edu.ua','$2a$10$6uDQYopubymX/5jIF0ujHeOjVy5g9ktSc9H1tFNDfFwOiBhe8MhEe','ENTRANT_MANAGER'),(3,'voloshkov-tymur','Тимур','Сергійович','Волошков','voloshkov.tymur@ntu.khpi.edu.ua','$2a$10$K/43agqBt5dEgtffgApgY.BIxi8JkoepLnf9Y7zjqXBQkspOfW72O','STUDENT_MANAGER'),(4,'kulish.volodymyr','Володимир','Анатолійович','Куліш','kulish.volodymyr@cs.khpi.edu.ua','$2a$10$EeqF328sey1/DioGL7A/k.sFaY4tTVa8m7sbYFQJd7dNJQ3Fn3./S','ENTRANT_VIEWER'),(5,'stepova.alina','Аліна','Трофимівна','Степова','stepova.alina@cs.khpi.edu.ua','$2a$10$Drh0BecUkQWbtcbG8VYFvu1aAS5FHTNxyV.LlpcBvTmUDBOaifx/u','STUDENT_VIEWER'),(6,'ivanenko_anna','Анна','Петрівна','Іваненко','ivanenko.anna@ntu.khpi.edu.ua','$2a$10$2WFLmreMo6jQEVY5j.9HPurdIZNsK/ojPhXRPLYeYxE22ZTil2PRK','ADMIN'),(7,'tarasenko-oleh','Олег','Іванович','Тарасенко','tarasenko.oleh@ntu.khpi.edu.ua','$2a$10$Fv..mVUJB3bbWwjzGx6/0.pa6viejweZAOwOPFL63NxvPhHC26ygO','ENTRANT_MANAGER'),(8,'melnyk_daryna','Дарина','Анатоліївна','Мельник','melnyk.daryna@ntu.khpi.edu.ua','$2a$10$skyG3TKSSD2j2Dfd381AKe7LTPu9Itds4VYFpY1cOyw6loVGHJt1u','STUDENT_MANAGER'),(9,'horbunov.vladyslav','Владислав','Михайлович','Горбунов','horbunov.vladyslav@cs.khpi.edu.ua','$2a$10$VHwQVn17o7/aSBPa8dxu9evkKVrbRYvWXBJ.CG5.yDwa/zPL6k6wq','ENTRANT_VIEWER'),(10,'romanova-olena','Олена','Олексіївна','Романова','romanova.olena@cs.khpi.edu.ua','$2a$10$dvoPA.RTXaKbCQ3Imv6lfeRM/zFOu.bYgt12U4C26Aa9zbKPkhT4e','STUDENT_VIEWER'),(11,'vasylchenko.mykhailo','Михайло','Олександрович','Васильченко','vasylchenko.mykhailo@ntu.khpi.edu.ua','$2a$10$vguSRdQ08PlP16fQCmAj/uMohKX2KdWMe/Qu3mh6QPShoSSs7sD9G','ADMIN'),(12,'shapoval-kseniia','Ксенія','Василівна','Шаповал','shapoval.kseniia@ntu.khpi.edu.ua','$2a$10$fzEmxaBKskooEnuKMbxYHeHmpfgMbwJ5VXMnpiXr1QsNYd/s1ItvG','ENTRANT_MANAGER'),(13,'kozak.yevhenii','Євгеній','Олегович','Козак','kozak.yevhenii@ntu.khpi.edu.ua','$2a$10$Pbti3NgX5/46PS/hCL2ccevHFQ2iqYR0hZo4TcxjG2BRYhFO2NBXG','STUDENT_MANAGER'),(14,'bondar.inna','Інна','Ігорівна','Бондар','bondar.inna@cs.khpi.edu.ua','$2a$10$NwNzFn/H9/srWhfX9e.xXOadkByGeFrRRdyBq.VxFlOdpB2uEc3QO','ENTRANT_VIEWER'),(15,'kravchenko-artem','Артем','Богданович','Кравченко','kravchenko.artem@cs.khpi.edu.ua','$2a$10$knc9FdCAvRD6Bc1bvtGOmeVPJcR06U83CFo4lLYkL3hVfnqwet6.S','STUDENT_VIEWER');
160160
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
161161
UNLOCK TABLES;
162162
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

lab4-5/WebAppsRIVLab4/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<groupId>ntukhpi.csit.semit.riv</groupId>
1212
<artifactId>WebAppsRIVLab4</artifactId>
1313
<version>0.0.1-SNAPSHOT</version>
14-
<packaging>war</packaging>
14+
<packaging>jar</packaging>
1515
<name>WebAppsRIVLab4</name>
1616
<description>WebAppsRIVLab4</description>
1717
<url/>
@@ -83,6 +83,12 @@
8383
<artifactId>mysql-connector-j</artifactId>
8484
<scope>runtime</scope>
8585
</dependency>
86+
<!-- TiDB Driver (compatible with MySQL) -->
87+
<dependency>
88+
<groupId>mysql</groupId>
89+
<artifactId>mysql-connector-java</artifactId>
90+
<version>8.0.33</version>
91+
</dependency>
8692
<dependency>
8793
<groupId>org.projectlombok</groupId>
8894
<artifactId>lombok</artifactId>
@@ -91,7 +97,6 @@
9197
<dependency>
9298
<groupId>org.springframework.boot</groupId>
9399
<artifactId>spring-boot-starter-tomcat</artifactId>
94-
<scope>provided</scope>
95100
</dependency>
96101
<dependency>
97102
<groupId>org.springframework.security</groupId>

lab4-5/WebAppsRIVLab4/render.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
services:
2+
- type: web
3+
name: webapps-lab4
4+
env: docker
5+
dockerfilePath: ./Dockerfile
6+
scaling:
7+
minInstances: 1
8+
maxInstances: 1
9+
envVars:
10+
- key: SPRING_PROFILES_ACTIVE
11+
value: prod
12+
- key: TIDB_URL
13+
sync: false
14+
- key: TIDB_USERNAME
15+
sync: false
16+
- key: TIDB_PASSWORD
17+
sync: false
18+
- key: JAVA_OPTS
19+
value: "-Dspring.profiles.active=prod -Duser.timezone=UTC"
20+
- key: MAIL_HOST
21+
value: smtp.ethereal.email
22+
- key: MAIL_PORT
23+
value: 587
24+
- key: MAIL_USERNAME
25+
value: wilmer.ankunding@ethereal.email
26+
- key: MAIL_PASSWORD
27+
value: GVDW5ZTPSSXuAnRh1y
28+
- key: MAIL_DEBUG
29+
value: true

lab4-5/WebAppsRIVLab4/src/main/java/ntukhpi/csit/semit/riv/webappsrivlab4/WebAppsRivLab4Application.java

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.boot.CommandLineRunner;
1616
import org.springframework.boot.SpringApplication;
1717
import org.springframework.boot.autoconfigure.SpringBootApplication;
18+
import org.springframework.core.env.Environment;
1819

1920
import java.util.List;
2021

@@ -51,31 +52,72 @@ public class WebAppsRivLab4Application implements CommandLineRunner {
5152
private final EntrantService entrantService;
5253
private final StudentService studentService;
5354
private final UserService userService;
55+
private final Environment environment;
5456

5557
@Autowired
56-
public WebAppsRivLab4Application(EntrantService entrantService, StudentService studentService, UserService userService) {
58+
public WebAppsRivLab4Application(EntrantService entrantService, StudentService studentService, UserService userService, Environment environment) {
5759
this.entrantService = entrantService;
5860
this.studentService = studentService;
5961
this.userService = userService;
62+
this.environment = environment;
6063
}
6164

6265
@Override
6366
public void run(String... args) {
64-
List<UserEntity> userEntityList = UserList.INSTANCE.getUsers().stream()
65-
.map(UserEntity::getUserEntityFromUserTestData)
66-
.toList();
67-
userService.saveAllUsers(userEntityList);
67+
// Ініціалізація тестових даних тільки для development профілю
68+
String[] activeProfiles = environment.getActiveProfiles();
69+
boolean isProductionMode = false;
70+
71+
for (String profile : activeProfiles) {
72+
if ("prod".equals(profile)) {
73+
isProductionMode = true;
74+
break;
75+
}
76+
}
77+
78+
if (isProductionMode) {
79+
logger.info("Production mode detected. Skipping test data initialization.");
80+
return;
81+
}
82+
83+
// Перевіряємо, чи вже є дані в базі
84+
try {
85+
List<UserEntity> existingUsers = userService.getAllUsers();
86+
if (!existingUsers.isEmpty()) {
87+
logger.info("Database already contains user data. Skipping test data initialization.");
88+
return;
89+
}
90+
} catch (Exception e) {
91+
logger.warn("Could not check existing users, proceeding with initialization: " + e.getMessage());
92+
}
93+
94+
logger.info("Initializing test data...");
95+
96+
try {
97+
List<UserEntity> userEntityList = UserList.INSTANCE.getUsers().stream()
98+
.map(UserEntity::getUserEntityFromUserTestData)
99+
.toList();
100+
userService.saveAllUsers(userEntityList);
101+
logger.info("User test data saved successfully.");
68102

69-
List<Entrant> entrantList = EntrantList.INSTANCE.getEntrants();
70-
entrantService.saveAllEntrants(entrantList);
103+
List<Entrant> entrantList = EntrantList.INSTANCE.getEntrants();
104+
entrantService.saveAllEntrants(entrantList);
105+
logger.info("Entrant test data saved successfully.");
71106

72-
studentService.saveAllStudents(StudentList.INSTANCE.getStudents());
107+
studentService.saveAllStudents(StudentList.INSTANCE.getStudents());
108+
logger.info("Student test data saved successfully.");
73109

74-
entrantList.forEach(entrant -> {
75-
entrant.setStudentId(
76-
entrantService.findStudentIdForEntrant(entrant.getId()));
77-
entrantService.updateEntrant(entrant);
78-
});
110+
entrantList.forEach(entrant -> {
111+
entrant.setStudentId(
112+
entrantService.findStudentIdForEntrant(entrant.getId()));
113+
entrantService.updateEntrant(entrant);
114+
});
115+
logger.info("Test data initialization completed successfully.");
116+
117+
} catch (Exception e) {
118+
logger.error("Error during test data initialization: " + e.getMessage());
119+
// У production режимі не падаємо, просто логуємо помилку
120+
}
79121
}
80122

81123
public static void main(String[] args) {

lab4-5/WebAppsRIVLab4/src/main/java/ntukhpi/csit/semit/riv/webappsrivlab4/config/MailConfig.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ntukhpi.csit.semit.riv.webappsrivlab4.config;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.Configuration;
56
import org.springframework.mail.javamail.JavaMailSender;
@@ -28,18 +29,40 @@
2829
*/
2930
@Configuration
3031
public class MailConfig {
32+
33+
@Value("${spring.mail.host:smtp.ethereal.email}")
34+
private String mailHost;
35+
36+
@Value("${spring.mail.port:587}")
37+
private int mailPort;
38+
39+
@Value("${spring.mail.username}")
40+
private String mailUsername;
41+
42+
@Value("${spring.mail.password}")
43+
private String mailPassword;
44+
45+
@Value("${spring.mail.properties.mail.debug:false}")
46+
private boolean mailDebug;
47+
3148
@Bean
32-
JavaMailSender createMailSender() {
49+
public JavaMailSender javaMailSender() {
3350
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
34-
mailSender.setHost("smtp.ethereal.email");
35-
mailSender.setPort(587);
36-
mailSender.setUsername("claire.mraz76@ethereal.email");
37-
mailSender.setPassword("3NtfRMmpaDnAxaWkUE");
51+
mailSender.setHost(mailHost);
52+
mailSender.setPort(mailPort);
53+
mailSender.setUsername(mailUsername);
54+
mailSender.setPassword(mailPassword);
3855

3956
Properties properties = mailSender.getJavaMailProperties();
40-
properties.put("mail.debug", true);
41-
properties.put("mail.smtp.DTO", true);
42-
properties.put("mail.smtp.starttls.enable", true);
57+
properties.put("mail.transport.protocol", "smtp");
58+
properties.put("mail.smtp.auth", "true");
59+
properties.put("mail.smtp.starttls.enable", "true");
60+
properties.put("mail.smtp.starttls.required", "true");
61+
properties.put("mail.debug", String.valueOf(mailDebug));
62+
properties.put("mail.smtp.ssl.trust", mailHost);
63+
properties.put("mail.smtp.timeout", "5000");
64+
properties.put("mail.smtp.connectiontimeout", "5000");
65+
properties.put("mail.smtp.writetimeout", "5000");
4366

4467
return mailSender;
4568
}

0 commit comments

Comments
 (0)