fix(backend): fixed cors error on build dev environment
This commit is contained in:
parent
918249580b
commit
b856d5d105
1 changed files with 5 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ import jakarta.servlet.DispatcherType;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
|
|
@ -40,6 +41,9 @@ public class SecurityConfig {
|
|||
@Value("${jwt.secret}")
|
||||
private String jwtSecret;
|
||||
|
||||
@Value("${app.cors-origins:http://localhost:4200}")
|
||||
private String corsOrigins;
|
||||
|
||||
@Bean
|
||||
public JwtDecoder jwtDecoder() {
|
||||
SecretKeySpec secretKey = new SecretKeySpec(jwtSecret.getBytes(), "HmacSHA256");
|
||||
|
|
@ -54,6 +58,7 @@ public class SecurityConfig {
|
|||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll()
|
||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||
.requestMatchers("/", "/index.html", "/assets/**", "/static/**", "/*.js", "/*.css", "/*.ico").permitAll()
|
||||
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
|
||||
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
|
||||
|
|
@ -85,9 +90,6 @@ public class SecurityConfig {
|
|||
return jwtAuthenticationConverter;
|
||||
}
|
||||
|
||||
@Value("${app.cors-origins:http://localhost:4200}")
|
||||
private String corsOrigins;
|
||||
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
|
|
@ -111,7 +113,6 @@ public class SecurityConfig {
|
|||
return config.getAuthenticationManager();
|
||||
}
|
||||
|
||||
// Das Gegenstück zum Decoder: Hiermit erstellen wir die Token!
|
||||
@Bean
|
||||
public JwtEncoder jwtEncoder() {
|
||||
SecretKeySpec secretKey = new SecretKeySpec(jwtSecret.getBytes(), "HmacSHA256");
|
||||
|
|
|
|||
Loading…
Reference in a new issue