diff --git a/src/main/java/com/example/template/ResourceServerConfiguration.java b/src/main/java/com/example/template/ResourceServerConfiguration.java index 8f6b598..15d09dc 100644 --- a/src/main/java/com/example/template/ResourceServerConfiguration.java +++ b/src/main/java/com/example/template/ResourceServerConfiguration.java @@ -1,4 +1,5 @@ package com.example.template; +import org.springframework.cloud.gateway.config.GlobalCorsProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; @@ -6,6 +7,8 @@ import org.springframework.security.config.annotation.web.reactive.EnableWebFlux import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory; import org.springframework.security.web.server.SecurityWebFilterChain; +import org.springframework.web.cors.reactive.CorsConfigurationSource; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; import java.security.KeyPair; @@ -20,7 +23,7 @@ public class ResourceServerConfiguration { .cors().and() .csrf().disable() .authorizeExchange() - .pathMatchers("/oauth/**","/login/**","/.well-known/jwks.json").permitAll() + .pathMatchers("/goods/**","/oauth/**","/login/**","/.well-known/jwks.json").permitAll() .anyExchange().authenticated() .and() .oauth2ResourceServer() @@ -30,6 +33,15 @@ public class ResourceServerConfiguration { return http.build(); } +// @Bean +// CorsConfigurationSource corsConfigurationSource( +// GlobalCorsProperties globalCorsProperties) { +// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); +// globalCorsProperties.getCorsConfigurations() +// .forEach(source::registerCorsConfiguration); +// return source; +// } + @Bean public KeyPair makeKeyPair(){ KeyPair keyPair = new KeyStoreKeyFactory( diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9b72eed..e68ce3a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,18 +9,14 @@ spring: oauth2: resourceserver: jwt: - jwk-set-uri: http://localhost:8080/.well-known/jwks.json + jwk-set-uri: http://localhost:8088/.well-known/jwks.json cloud: gateway: routes: - id: product uri: http://localhost:8085 predicates: - - Path=/product/** - - id: goods - uri: http://product:8085 - predicates: - - Path=/goods/** + - Path=/products/**,/goods/** - id: order uri: http://localhost:8081 predicates: @@ -71,11 +67,7 @@ spring: - id: product uri: http://product:8080 predicates: - - Path=/products/** - - id: goods - uri: http://product:8080 - predicates: - - Path=/goods/** + - Path=/products/**,/goods/** - id: order uri: http://order:8080 predicates: