Skip to content

Commit

Permalink
Chore: Get CORS configuration from application.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
binarycoded committed Aug 27, 2024
1 parent 089780c commit 9a4a641
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* (C) 2024 */
package rocks.inspectit.gepard.agentmanager.application.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -9,15 +10,22 @@
@Configuration
public class CorsConfiguration implements WebMvcConfigurer {

// TODO: Get CORS config from application.yaml
@Value("${inspectit.gepard.security.cors.path-pattern}")
private String pathPattern;

@Value("${inspectit.gepard.security.cors.allowed-origins}")
private String allowedOrigins;

@Value("${inspectit.gepard.security.cors.allowed-methods}")
private String allowedMethods;

/**
* Adds CORS mappings to the registry. Allow all origins and methods.
*
* @param registry
* @param registry The CorsRegistry to add mappings and allowed headers, methods and origins to.
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*");
registry.addMapping(pathPattern).allowedOrigins(allowedOrigins).allowedMethods(allowedMethods);
}
}
11 changes: 10 additions & 1 deletion backend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ spring:
location: "classpath:ssl/igc-dev.p12"
password: "password"
type: "PKCS12"

server:
port: 8080
ssl:
bundle: "server"
enabled-protocols: "TLSv1.3"
enabled-protocols: "TLSv1.3"

inspectit:
gepard:
security:
cors:
path-pattern: "/**"
allowed-origins: "*"
allowed-methods: "*"

0 comments on commit 9a4a641

Please sign in to comment.