diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/config/ApplicationConfig.java b/src/main/java/fr/insee/survey/datacollectionmanagement/config/ApplicationConfig.java index 0738f24b..bbbac362 100644 --- a/src/main/java/fr/insee/survey/datacollectionmanagement/config/ApplicationConfig.java +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/config/ApplicationConfig.java @@ -6,7 +6,6 @@ import org.springframework.context.annotation.Configuration; import java.util.List; -import java.util.Optional; @Configuration @Getter @@ -35,8 +34,8 @@ public class ApplicationConfig { @Value("${fr.insee.datacollectionmanagement.auth.mode}") private String authType; - @Value("${fr.insee.datacollectionmanagement.cors.allowedOrigin}") - private Optional allowedOrigin; + @Value("${fr.insee.datacollectionmanagement.cors.allowedOrigins}") + private String[] allowedOrigins; @Value("${fr.insee.datacollectionmanagement.auth.realm}") private String keycloakRealm; diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/config/CorsGlobalConfig.java b/src/main/java/fr/insee/survey/datacollectionmanagement/config/CorsGlobalConfig.java index 5c387d8f..0c1cf9d2 100644 --- a/src/main/java/fr/insee/survey/datacollectionmanagement/config/CorsGlobalConfig.java +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/config/CorsGlobalConfig.java @@ -4,11 +4,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -@EnableWebMvc @RequiredArgsConstructor public class CorsGlobalConfig { @@ -19,7 +17,7 @@ public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override public void addCorsMappings(CorsRegistry registry) { - String ao = applicationConfig.getAllowedOrigin().orElse("*"); + String[] ao = applicationConfig.getAllowedOrigins(); registry.addMapping("/**") .allowedOrigins(ao) .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/exception/ExceptionControllerAdvice.java b/src/main/java/fr/insee/survey/datacollectionmanagement/exception/ExceptionControllerAdvice.java index f575dc57..6e11d77f 100644 --- a/src/main/java/fr/insee/survey/datacollectionmanagement/exception/ExceptionControllerAdvice.java +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/exception/ExceptionControllerAdvice.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import jakarta.persistence.EntityNotFoundException; import jakarta.validation.ConstraintViolationException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -121,6 +122,14 @@ public ResponseEntity notFoundException(NotFoundException e, WebReques return processException(e, HttpStatus.NOT_FOUND, request); } + @ExceptionHandler(EntityNotFoundException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public ResponseEntity entityNotFoundException(NotFoundException e, WebRequest request) { + log.error(e.getMessage(), e); + return processException(e, HttpStatus.NOT_FOUND, request); + } + + @ExceptionHandler(NotMatchException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ResponseEntity notMatchException(NotMatchException e, WebRequest request) {