Merge pull request 'feat(security): add frontend host configuration property' (!146) from bugfix/backend-cors into main
All checks were successful
Release / Release (push) Successful in 58s
Release / Build Frontend Image (push) Successful in 24s
Release / Build Backend Image (push) Successful in 58s

Reviewed-on: #146
This commit is contained in:
Constantin Simonis 2025-04-24 13:13:28 +00:00
commit a22bfa4a60
Signed by:
GPG key ID: 944223E4D46B7412

View file

@ -1,5 +1,6 @@
package de.szut.casino.security;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
@ -17,6 +18,9 @@ import java.util.List;
@EnableWebSecurity
public class SecurityConfig {
@Value("${app.frontend-host}")
private String frontendHost;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
@ -36,7 +40,7 @@ public class SecurityConfig {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("http://localhost:4200"));
configuration.setAllowedOrigins(List.of(this.frontendHost));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token", "Access-Control-Allow-Origin"));
configuration.setExposedHeaders(List.of("x-auth-token"));