From db0f540077b3e5a8ee9cce5eb8621d221201c1df Mon Sep 17 00:00:00 2001 From: Sukh <6563909+sukhpalp@users.noreply.github.com> Date: Wed, 1 May 2024 16:46:18 -0700 Subject: [PATCH] Fix typos (#1880) * Fix typo * Fix typo * Add applicationInitializer --- .../v1/spring/ApplicationInitializer.java | 3 +++ .../rest/v1/spring/SecuritySpringConfig.java | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/ApplicationInitializer.java b/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/ApplicationInitializer.java index 3262f58620..3bedd9bae5 100644 --- a/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/ApplicationInitializer.java +++ b/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/ApplicationInitializer.java @@ -49,6 +49,9 @@ protected void beforeSpringSecurityFilterChain(ServletContext servletContext) { versionForwardingFilter.setInitParameter(VersionForwardingFilter.RESPONSE_VERSION_PARAM, "1"); versionForwardingFilter.setInitParameter(VersionForwardingFilter.DEFAULT_REQUEST_VERSION_PARAM, "1"); versionForwardingFilter.addMappingForUrlPatterns(null, false, "/*"); + + FilterRegistration.Dynamic corsFilter = servletContext.addFilter("CORS Filter", CorsFilter.class); + corsFilter.addMappingForUrlPatterns(null, false, "/*"); LOGGER.info(">beforeSpringSecurityFilterChain"); } diff --git a/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/SecuritySpringConfig.java b/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/SecuritySpringConfig.java index c85443a175..45d675ac10 100644 --- a/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/SecuritySpringConfig.java +++ b/server/wfnews-api/wfnews-api-rest-endpoints/src/main/java/ca/bc/gov/nrs/wfnews/api/rest/v1/spring/SecuritySpringConfig.java @@ -122,7 +122,7 @@ public Authentication authenticate(Authentication authentication) throws Authent @Override protected void configure(HttpSecurity http) throws Exception { - http.cors().and().csrf().disable(); + http.cors().and().csrf().disable() .oauth2ResourceServer(oauth2 -> oauth2 .authenticationManagerResolver(authenticationManagerResolver()) ) @@ -139,15 +139,16 @@ protected void configure(HttpSecurity http) throws Exception { @Bean public CorsConfigurationSource corsConfigurationSource() { - final CorsConfiguration configuration = new CorsConfiguration(); + final CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(Collections.unmodifiableList(Arrays.asList("*"))); - configuration.setAllowedMethods( - Collections.unmodifiableList(Arrays.asList("HEAD", "GET", "POST", "DELETE", "PUT", "OPTIONS"))); - configuration.setAllowedHeaders(Collections.unmodifiableList(Arrays.asList("apikey"))); + configuration.setAllowedOrigins(Collections.unmodifiableList(Arrays.asList("*"))); + configuration.setAllowedMethods( + Collections.unmodifiableList(Arrays.asList("HEAD", "GET", "POST", "DELETE", "PUT", "OPTIONS"))); + configuration.setAllowedHeaders(Collections.unmodifiableList(Arrays.asList("apikey"))); - final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", configuration); + final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); - return source; + return source; + } }