Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade boot to 3.2 from 2.7 #57

Merged
merged 53 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f5e465b
first steps of migratiofirst steps of migrationn
Dec 18, 2023
2780d6e
javax -> jakarta
Dec 18, 2023
0db2e50
java 21
Dec 20, 2023
4fdba63
Merge branch 'master' into upgrade-boot
Dec 21, 2023
e95644a
test a working...
Dec 23, 2023
2f6ede8
unused import
Dec 23, 2023
ee51157
removed unused primary annotation
Dec 23, 2023
05c8149
no custom objectmapper
Dec 23, 2023
1f3b711
timezone
Dec 23, 2023
d076e36
format
Dec 23, 2023
dc38a23
more datetime
Dec 23, 2023
a934500
better format
Dec 23, 2023
170d3ad
foo
Dec 23, 2023
9665ff5
return token on login-as-human
Dec 24, 2023
bf9304a
debug
Dec 24, 2023
a37dd75
carve out eventlog
Dec 25, 2023
bdc46c8
send out dummy events
Dec 25, 2023
569ea0e
kafka listens on localhost as default
Dec 26, 2023
2f35937
no cloud events
Dec 26, 2023
552b485
debug
Dec 26, 2023
171a0d5
version
Dec 26, 2023
d7ce94f
without @version
Dec 26, 2023
268957f
debug
Dec 26, 2023
f5d24ec
debug
Dec 26, 2023
360ea3e
debug
Dec 26, 2023
3cc5788
unequals
Dec 26, 2023
1d04e18
with version
Dec 26, 2023
fc7d4d7
schedule first send second
Dec 26, 2023
5246671
flush
Dec 26, 2023
1b95ec9
without flush
Dec 26, 2023
ec2315c
hack
Dec 26, 2023
8e52c2d
better hack
Dec 26, 2023
d6a360f
bla
Dec 26, 2023
befbdc9
schedule
Dec 27, 2023
19004e3
reworked exception handling
Dec 27, 2023
e3ed39c
schedule als eventlog events
Dec 27, 2023
bf4cfaa
debug
Dec 27, 2023
50417c2
fix
Dec 27, 2023
599d1fa
rewrite old event format
Dec 27, 2023
4da38fa
send now from the outbox
Dec 27, 2023
80225fe
new topics
Dec 27, 2023
dfe0889
app instance is now a topic
Dec 27, 2023
571c502
all topics
Dec 27, 2023
3021b10
profile updated now not through eventlog anymore
Dec 27, 2023
e323caa
refactored
Dec 27, 2023
2d3b4b5
mail is send via kafka
Dec 27, 2023
76b2f14
getmail endpoint
Dec 27, 2023
266b3c1
removed the wrapper arround simplemailmessage
Dec 27, 2023
81d9c5e
logout besser
Dec 28, 2023
d68b92b
removed old mail handling code
Dec 29, 2023
822d01b
bug
Dec 29, 2023
03f0e86
contact controller improved
Jan 14, 2024
09a8608
new api
Jan 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Set up JDK 1.17
uses: actions/setup-java@v3
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17.0.4+1
java-version: 21
distribution: zulu
- name: Build the project with Maven
run: ./mvnw --batch-mode -update-snapshots package
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM openjdk:17-slim
FROM openjdk:21-slim

ADD target/dancer.jar /dancer.jar
CMD ["java", "--enable-preview", "-jar", "/dancer.jar"]
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Here you can configure the connection to the postgres instance:
# stopping dancer in docker-compose
docker-compose stop dancer;
# running the boot app with overwriting the needed host
./mvnw spring-boot:run -Dspring-boot.run.arguments="--spring.datasource.url=jdbc:postgresql://localhost:5432/dancer --spring.kafka.bootstrap-servers=localhost:9092"
./mvnw spring-boot:run -Dspring-boot.run.arguments="--spring.datasource.url=jdbc:postgresql://localhost:5432/dancer
````

#### checking test-coverage
Expand Down
4 changes: 3 additions & 1 deletion swagger.yaml → api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ paths:
tags:
- Contacts
requestBody:
description: the mail will end up in dev@dancier.net
description: >
The mail will end up in dev@dancier.net, the sender will also get a copy of the mail.
When the user of this endpoint is logged in, the senders email-address will be the one from the user. In this case the provided value in this payload will be ignored.
required: true
content:
application/json:
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- dancer-db
environment:
# https://ckinan.com/blog/remote-debug-spring-boot-docker-intellij/:
- SPRING_DATASOURCE_URL=jdbc:postgresql://dancer-db:5432/dancer
- SPRING_PROFILES_ACTIVE="dev"
- JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
dancer-db:
Expand All @@ -27,7 +28,7 @@ services:
- ./volumes/dancer-data:/var/lib/postgresql/data

pg-admin:
image: dpage/pgadmin4:7
image: dpage/pgadmin4:8.1
restart: always
ports:
- "5050:80"
Expand Down
57 changes: 31 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.14</version>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>net.dancier</groupId>
Expand All @@ -14,8 +14,7 @@
<name>dancer</name>
<description>Demo project for Spring Boot</description>
<properties>
<spring-security.version>5.8.8</spring-security.version>
<java.version>17</java.version>
<java.version>21</java.version>
<testcontainers.version>1.15.1</testcontainers.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -51,15 +50,35 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-kafka</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-json-jackson</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
Expand Down Expand Up @@ -101,6 +120,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.minio</groupId>
Expand Down Expand Up @@ -151,37 +171,17 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<finalName>dancer</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.11</version>
<executions>
<execution>
<goals>
Expand All @@ -201,7 +201,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>--enable-preview</jvmArguments>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/dancier/dancer/DancerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import java.util.TimeZone;

@SpringBootApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.transaction.Transactional;
import jakarta.annotation.PostConstruct;
import jakarta.transaction.Transactional;
import java.util.Collection;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -64,6 +64,7 @@ public ResponseEntity<?> whoami() {
@Secured({ROLE_HUMAN})
@PostMapping("/registrations")
public ResponseEntity<?> register(@Valid @RequestBody RegisterRequestDto registerRequest) {
log.info("About to register user: " + registerRequest);
try {
authenticationService.registerUser(registerRequest);
} catch (UserOrEmailAlreadyExistsException userOrEmailAlreadyExistsException) {
Expand Down Expand Up @@ -107,19 +108,19 @@ public ResponseEntity<?> loginAsHuman(@RequestHeader(required = false, name = "X
HttpServletResponse httpServletResponse) {
log.info("Log in as human");
ResponseCookie cookie = null;
String jwt = null;
try {
captchaService.verifyToken(token);
jwt = authenticationService.generateJwtToken("HUMAN");
cookie = authenticationService
.generateCookie(
authenticationService.generateJwtToken("HUMAN")
);
.generateCookie(jwt);
httpServletResponse.addHeader(HttpHeaders.SET_COOKIE, cookie.toString());
} catch (CaptchaException captchaException) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(
new ApiResponse(false, "Not authorized as a human: " + captchaException.getMessage())
);
}
return ResponseEntity.ok().build();
return ResponseEntity.ok(new JwtAuthenticationResponse(jwt));
}

@GetMapping("/logout")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.*;
import jakarta.validation.constraints.*;

@Data
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

@Data
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import net.dancier.dancer.authentication.model.EmailValidationCode;
import net.dancier.dancer.authentication.repository.EmailValidationCodeRepository;
import net.dancier.dancer.mail.service.MailCreationService;
import net.dancier.dancer.mail.service.MailEnqueueService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Component;

import java.time.Instant;
Expand All @@ -23,7 +24,8 @@ public class NewUserCreatedEventListener {
private final static Logger log = LoggerFactory.getLogger(NewUserCreatedEventListener.class);

private final EmailValidationCodeRepository emailValidationCodeRepository;
private final MailEnqueueService mailEnqueueService;

private final ApplicationEventPublisher applicationEventPublisher;

private final MailCreationService mailCreationService;

Expand All @@ -41,20 +43,20 @@ void handle(NewUserCreatedEvent newUserCreatedEvent) {
emailValidationCode.setUserId(newUserCreatedEvent.getId());
emailValidationCode.setCode(UUID.randomUUID().toString());
emailValidationCodeRepository.save(emailValidationCode);
enqueueUserMail(newUserCreatedEvent, emailValidationCode.getCode());
applicationEventPublisher.publishEvent(
createMailMessage(newUserCreatedEvent, emailValidationCode.getCode())
);
log.debug("Created validation code: " + emailValidationCode.getCode() + " for user: " + newUserCreatedEvent);
}

private void enqueueUserMail(NewUserCreatedEvent newUserCreatedEvent, String code) {
mailEnqueueService.enqueueMail(
mailCreationService.createDancierMessageFromTemplate(
private SimpleMailMessage createMailMessage(NewUserCreatedEvent newUserCreatedEvent, String code) {
return mailCreationService.createDancierMessageFromTemplate(
newUserCreatedEvent.getEmail(),
MailCreationService.NO_REPLY_FROM,
"Dancier - bestätige Deine E-Mail-Adresse!",
MailCreationService.NEW_USER_VALIDATE_EMAIL,
Map.of( "validationLink", emailValidationLink(code)
))
);
));
}

private String emailValidationLink(String validationCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.time.Instant;
import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Data;

import javax.persistence.*;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package net.dancier.dancer.authentication.model;

import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.NaturalId;

import javax.persistence.*;
import java.util.UUID;

@Data
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/dancier/dancer/authentication/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.Collection;
import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.time.Instant;
import java.util.UUID;

Expand Down
Loading