Skip to content

Commit 671a4bd

Browse files
authored
Merge pull request #20 from Halbes-Byte/chore/centralize-used-metadata
chore: centralize used metadata
2 parents ce13e13 + 56804d2 commit 671a4bd

File tree

10 files changed

+69
-30
lines changed

10 files changed

+69
-30
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ start_vpn.sh
66
server/generated-sources/
77
data/
88
.env
9+
.javaversion.sh
10+
./server/data/

docker-compose.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ services:
3737
POSTGRES_USER: ${KC_DB_USERNAME}
3838
POSTGRES_PASSWORD: ${KC_DB_PASSWORD}
3939
ports:
40-
- '5432:5432'
41-
#spring:
42-
# build:
43-
# context: .
44-
# dockerfile: Dockerfile
45-
# # image: panderu/study-buddies-backend:latest
46-
# container_name: spring-backend
47-
# ports:
48-
# - "1516:8080"
49-
# depends_on:
50-
# - keycloak_web
5140
######################################################
5241
volumes:
5342
postgres_data:

javaversion.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
sdk use java 17.0.12-zulu
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.studybuddies.server.configuration;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.web.cors.CorsConfiguration;
8+
import org.springframework.web.cors.CorsConfigurationSource;
9+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
10+
11+
@Configuration
12+
public class CORS {
13+
@Bean
14+
public CorsConfigurationSource cors() {
15+
CorsConfiguration conf = new CorsConfiguration();
16+
conf.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:7070"));
17+
conf.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
18+
conf.setAllowedHeaders(List.of("*"));
19+
conf.setAllowCredentials(true);
20+
conf.setMaxAge(3600L);
21+
22+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
23+
source.registerCorsConfiguration("/**", conf);
24+
return source;
25+
}
26+
}
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
package com.studybuddies.server.configuration;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.beans.factory.annotation.Qualifier;
5+
import org.springframework.context.annotation.Bean;
36
import org.springframework.context.annotation.Configuration;
47
import org.springframework.context.annotation.Profile;
8+
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
59
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
610
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7-
import org.springframework.security.config.annotation.web.configurers.CorsConfigurer;
811
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
912
import org.springframework.security.web.SecurityFilterChain;
13+
import org.springframework.web.cors.CorsConfigurationSource;
1014

1115
@Profile("dev")
1216
@Configuration
17+
@Slf4j
1318
@EnableWebSecurity
19+
@EnableMethodSecurity(securedEnabled = true)
1420
public class DevConfig {
15-
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
16-
http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll());
21+
22+
@Qualifier("cors")
23+
private CorsConfigurationSource corsConfigurationSource;
24+
25+
@Bean
26+
public SecurityFilterChain devChain(HttpSecurity http) throws Exception {
27+
log.info("Dev configuring SecurityFilterChain");
28+
http.cors(c -> c.configurationSource(corsConfigurationSource));
29+
http.securityMatcher("/**");
1730
http.csrf(CsrfConfigurer::disable);
18-
http.cors(CorsConfigurer::disable);
31+
http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll());
1932
return http.build();
2033
}
2134
}

server/src/main/java/com/studybuddies/server/configuration/SecurityConfig.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
77
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
89
import org.springframework.security.web.SecurityFilterChain;
10+
import org.springframework.web.cors.CorsConfigurationSource;
911

1012
@Configuration
11-
@EnableMethodSecurity
13+
@EnableWebSecurity
1214
@RequiredArgsConstructor
15+
@EnableMethodSecurity(securedEnabled = true)
1316
public class SecurityConfig {
1417

15-
JwtAuthConverter jwtAuthConverter;
18+
private JwtAuthConverter jwtAuthConverter;
19+
private CorsConfigurationSource corsConfigurationSource;
1620

1721
@Bean
1822
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
23+
http.securityMatcher("/**");
24+
http.cors(c -> c.configurationSource(corsConfigurationSource));
1925
http.
2026
authorizeHttpRequests(auth ->
2127
auth.requestMatchers("/swagger-ui/**", "/h2-console/**", "/api-docs/**", "/v3/**").permitAll()

server/src/main/java/com/studybuddies/server/domain/MeetingEntity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import jakarta.persistence.GeneratedValue;
66
import jakarta.persistence.GenerationType;
77
import jakarta.persistence.Id;
8-
import jakarta.persistence.ManyToOne;
98
import jakarta.persistence.Table;
10-
import java.time.LocalDate;
119
import java.time.LocalDateTime;
1210
import lombok.AllArgsConstructor;
1311
import lombok.Builder;

server/src/main/java/com/studybuddies/server/web/MeetingController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.springframework.http.HttpHeaders;
1010
import org.springframework.http.HttpStatus;
1111
import org.springframework.http.ResponseEntity;
12-
import org.springframework.security.access.prepost.PreAuthorize;
1312
import org.springframework.web.bind.annotation.*;
1413

1514
@AllArgsConstructor
@@ -33,7 +32,7 @@ public ResponseEntity<?> changeMeeting(@RequestParam Long id, @Valid @RequestBod
3332
}
3433

3534
@GetMapping
36-
@PreAuthorize("hasRole('ADMIN')")
35+
//@PreAuthorize("hasRole('ADMIN')")
3736
public ResponseEntity<?> getMeeting(@RequestParam(required = false) Long id) {
3837
String response = meetingService.retrieveMeetingFromDatabase(id);
3938
return ResponseEntity.status(HttpStatus.OK).body(response);

server/src/main/resources/application-dev.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ spring:
44
application:
55
name: server
66
datasource:
7-
url: jdbc:h2:file:./data/demo
8-
username: sa
9-
password: password
7+
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
8+
username: ${H2_USERNAME:user}
9+
password: ${H2_PASSWORD:password}
1010
driverClassName: org.h2.Driver
1111
jpa:
1212
database-platform: org.hibernate.dialect.H2Dialect
1313
show-sql: true
1414
hibernate:
15-
ddl-auto: update
15+
ddl-auto: create-drop
1616
h2:
1717
console.enabled: true
1818
springdoc:
19-
swagger-ui.path: /api-docs
19+
swagger-ui.path: /api-docs
20+
logging:
21+
level:
22+
org.springframework.jdbc.core: DEBUG
23+
com.zaxxer.hikari: DEBUG

server/src/main/resources/application.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ spring:
44
application:
55
name: server
66
datasource:
7-
url: jdbc:h2:file:./data/demo
8-
username: sa #TODO: Extract this into a dev config application-dev.yml
9-
password: password
7+
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
8+
username: ${H2_USERNAME:user}
9+
password: ${H2_PASSWORD:password}
1010
driverClassName: org.h2.Driver
1111
jpa:
1212
database-platform: org.hibernate.dialect.H2Dialect
1313
show-sql: true
1414
hibernate:
15-
ddl-auto: update
15+
ddl-auto: create
1616
h2:
1717
console.enabled: true
1818
security:

0 commit comments

Comments
 (0)