Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 1 addition & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
"forwardPorts": [4200, 8080],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash -c 'echo \"Installing dependencies...\" && cd frontend/blog-angular-ui && npm config set legacy-peer-deps true && npm install && npm install -g @angular/cli && echo \"Verifying installations...\" && ng version && java -version'",

// Add mount for ~/.m2 to cache Maven dependencies
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.m2,target=/home/vscode/.m2,type=bind,consistency=cached"
],
"postCreateCommand": "bash -c 'echo \"Installing dependencies...\" && cd frontend/blog-angular-ui && npm install && npm install -g @angular/cli && echo \"Verifying installations...\" && ng version && java -version'",

// Configure tool-specific properties.
// "customizations": {},
Expand Down
2 changes: 1 addition & 1 deletion poc-algorithms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.8</version>
<version>4.0.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand Down
2 changes: 1 addition & 1 deletion poc-reactive-learning/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.8</version>
<version>4.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
4 changes: 2 additions & 2 deletions poc-rest-api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example.poc</groupId>
<artifactId>poc-spring-boot-rest</artifactId>
<packaging>pom</packaging>
<name>Spring Boot Rest Parent</name>
<version>0.4.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<url>https://maven.apache.org</url>

<modules>
<module>spring-boot-rest-webmvc</module>
Expand Down
56 changes: 13 additions & 43 deletions poc-rest-api/spring-boot-rest-webflux/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.8</version>
<version>4.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -37,12 +37,8 @@
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-liquibase</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand All @@ -59,24 +55,19 @@
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<artifactId>spring-boot-starter-webflux-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<artifactId>spring-boot-starter-data-r2dbc-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -86,17 +77,17 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<artifactId>testcontainers-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<artifactId>testcontainers-postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>r2dbc</artifactId>
<artifactId>testcontainers-r2dbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -116,14 +107,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
Expand All @@ -135,28 +118,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source> <!-- depending on your project -->
<target>${java.version}</target> <!-- depending on your project -->
<configuration> <!-- depending on your project --> <!-- depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<!-- other annotation processors -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<!-- This is needed when using Lombok 1.18.16 and above -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -194,7 +164,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.25.2</version>
<version>1.28.0</version>
<style>AOSP</style>
</googleJavaFormat>
<licenseHeader>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/* Licensed under Apache-2.0 2021-2023 */
package com.example.poc.reactive.config;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authorization.AuthorizationDecision;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.authorization.AuthorizationContext;
import org.springframework.security.web.server.context.NoOpServerSecurityContextRepository;
import reactor.core.publisher.Mono;

@Configuration
@Slf4j
@Configuration(proxyBeanMethods = false)
class SecurityConfig {

private static final Logger log = LoggerFactory.getLogger(SecurityConfig.class);

@Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
var postPath = "/posts/**";
Expand All @@ -39,19 +38,22 @@ SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
.pathMatchers(postPath)
.hasRole("USER")
.pathMatchers("/users/{user}/**")
.access(this::currentUserMatchesPath)
.access(
(authentication, context) ->
authentication
.map(
auth ->
context.getVariables()
.get("user")
.equals(
auth
.getName()))
.map(AuthorizationDecision::new))
.anyExchange()
.authenticated())
.build();
}

private Mono<AuthorizationDecision> currentUserMatchesPath(
Mono<Authentication> authentication, AuthorizationContext context) {
return authentication
.map(a -> context.getVariables().get("user").equals(a.getName()))
.map(AuthorizationDecision::new);
}

@Bean
PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.example.poc.reactive.entity.ReactivePost;
import com.example.poc.reactive.service.PostService;
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.reactivestreams.Publisher;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -20,11 +19,14 @@

@RestController
@RequestMapping("/posts")
@RequiredArgsConstructor
public class PostClassicController {

private final PostService postService;

public PostClassicController(PostService postService) {
this.postService = postService;
}

@GetMapping
public Publisher<ReactivePost> all() {
return this.postService.findAllPosts();
Expand Down
Loading