Hello I am very new at this okta security thing and I am trying out some things.
I have server application:
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServiceApplication.class, args);
}
}
application.properties
server.port=8761
eureka.client.register-with-eureka=false
And then I have client application:
@SpringBootApplication
@EnableEurekaClient
public class SpringCloudGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudGatewayApplication.class, args);
}
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder,
TokenRelayGatewayFilterFactory filterFactory) {
return builder.routes()
.route("cart-service", r -> r.path("/cart")
.filters(f -> f.filter(filterFactory.apply()))
.uri("lb://cart-service"))
.build();
}
}
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
public class OktaOAuth2WebSecurity {
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
http.csrf().disable()
.authorizeExchange()
.anyExchange()
.authenticated()
.and().oauth2Login()
.and().oauth2ResourceServer().jwt();
return http.build();
}
}
application.properties:
spring.main.allow-bean-definition-overriding=true
okta.oauth2.issuer=https://****
okta.oauth2.client-id=0oa2fm***
okta.oauth2.client-secret=rkdzVcNsrDgt0****
spring.application.name=gateway
And also I have microservice:
@SpringBootApplication
@EnableEurekaClient
public class ServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}
}
@RestController
public class CartController {
@GetMapping("/cart")
@PreAuthorize("hasAnyRole('ADMIN', 'USER')")
public @ResponseBody Cart cartInfo() {
return new Cart("abir", "Dhaka");
}
}
application properties:
spring.application.name=cart-service
server.port=8081
okta.oauth2.issuer=https://***
okta.oauth2.client-id=0oa2fm****
okta.oauth2.client-secret=rkdzVcNsr*****
But when I launch all these 3 applications I dont get the microservice result…
When I go to localhost:8080/cart I get whitelabel error page. and errors are: failed to resolve 'DESKTOP-1RUFLM8' after 2 queries, 500 Server Error for HTTP GET "/cart"
.
And I just cant find solution how to fix this… I would appreciate some help I can provide anything you need. Now I provided my three classes with application properties of these classes.