-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable native run, add WebFilter and request-logging
- Loading branch information
1 parent
6f5dafc
commit bebea3a
Showing
11 changed files
with
187 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/de/cofinpro/account/AccountReactiveApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/de/cofinpro/account/configuration/ObservabilityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package de.cofinpro.account.configuration; | ||
|
||
import org.slf4j.LoggerFactory; | ||
import org.slf4j.MDC; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.security.core.context.ReactiveSecurityContextHolder; | ||
import org.springframework.web.reactive.function.server.ServerRequest; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebFilter; | ||
import org.springframework.web.server.WebFilterChain; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Configuration | ||
public class ObservabilityConfiguration { | ||
|
||
public static <T> Mono<T> extractAndLog(ServerRequest request, Class<T> bodyClass) { | ||
var logger = LoggerFactory.getLogger(bodyClass); | ||
var user = MDC.get("user"); | ||
return request | ||
.bodyToMono(bodyClass) | ||
.doOnNext(body -> logger.info("{} {} {} with payload '{}'", | ||
user, | ||
request.method().name(), | ||
request.path(), | ||
body)); | ||
} | ||
|
||
@Bean | ||
ObservabilityFilter observabilityFilter() { | ||
return new ObservabilityFilter(); | ||
} | ||
|
||
static class ObservabilityFilter implements WebFilter { | ||
|
||
@Override | ||
@NonNull | ||
public Mono<Void> filter(@NonNull ServerWebExchange serverWebExchange, @NonNull WebFilterChain webFilterChain) { | ||
return ReactiveSecurityContextHolder.getContext().doOnNext(sc -> { | ||
if (sc.getAuthentication() != null) { | ||
MDC.put("user", "<" + sc.getAuthentication().getName() + ">"); | ||
} | ||
}).then(webFilterChain.filter(serverWebExchange)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<appender name="Console" | ||
class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern> | ||
%d{ISO8601} %highlight(%-5level) [%green(%t)] %magenta(%C{1}): %X{user} %msg%n%throwable | ||
</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<!-- LOG everything at INFO level --> | ||
<root level="info"> | ||
<appender-ref ref="Console"/> | ||
</root> | ||
|
||
</configuration> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
DROP TABLE IF EXISTS SALARY; | ||
DROP TABLE IF EXISTS LOGIN_ROLES; | ||
DROP TABLE IF EXISTS LOGIN; | ||
DROP TABLE IF EXISTS ROLES; | ||
DROP TABLE IF EXISTS AUDIT; | ||
CREATE TABLE IF NOT EXISTS LOGIN | ||
( | ||
id BIGSERIAL PRIMARY KEY NOT NULL, | ||
name VARCHAR(64), | ||
lastname VARCHAR(64), | ||
email VARCHAR(64) UNIQUE NOT NULL, | ||
password VARCHAR(128) NOT NULL, | ||
account_locked BOOL NOT NULL, | ||
failed_logins SMALLINT | ||
); | ||
CREATE TABLE IF NOT EXISTS SALARY | ||
( | ||
id BIGSERIAL PRIMARY KEY NOT NULL, | ||
email VARCHAR(64) NOT NULL, | ||
period VARCHAR(7) NOT NULL, | ||
salary BIGINT NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS ROLES | ||
( | ||
id BIGSERIAL PRIMARY KEY NOT NULL, | ||
user_role VARCHAR(20) UNIQUE NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS LOGIN_ROLES | ||
( | ||
id BIGSERIAL PRIMARY KEY NOT NULL, | ||
email VARCHAR(64) NOT NULL, | ||
user_role VARCHAR(20) NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS AUDIT | ||
( | ||
id BIGSERIAL PRIMARY KEY NOT NULL, | ||
date DATE NOT NULL, | ||
action VARCHAR(20) NOT NULL, | ||
subject VARCHAR(64), | ||
object VARCHAR(128), | ||
path VARCHAR(64) NOT NULL | ||
); |