@@ -39,7 +39,117 @@ The brackets at the end of each step indicate the alias's or IntelliJ Live Templ
3939 <artifactId>jaxb-runtime</artifactId>
4040 </dependency>
4141
42- ... to be continued ...
42+ . Add `@EnableEurekaServer` and properties to set port and turn off discovery
43+
44+ server.port=8761
45+ eureka.client.register-with-eureka=false
46+
47+ . Add `@EnableDiscoveryClient` to main classes in `car-service` and `api-gateway`
48+
49+ . Configure `car-service` to run on `8090` and set its name
50+
51+ server.port=8090
52+ spring.application.name=car-service
53+
54+ . Add an application name to the `api-gateway` project
55+
56+ spring.application.name=api-gateway
57+
58+ . Create an API with Spring Boot and Spring Data [//todo]
59+
60+ . Configure gateway to enable resilient server-to-server communication
61+
62+ @EnableFeignClients
63+ @EnableCircuitBreaker
64+ @EnableZuulProxy
65+
66+ // feign client
67+ // cool car controller
68+ // hystrix
69+
70+ . Start all servers, view Eureka server, and /cool-cars endpoint
71+
72+ == Secure Java Microservices with OAuth 2.0 and OIDC
73+
74+ . Add Okta Spring Boot starter to `api-gateway` and `car-service`
75+
76+ <dependency>
77+ <groupId>com.okta.spring</groupId>
78+ <artifactId>okta-spring-boot-starter</artifactId>
79+ <version>1.2.1</version>
80+ </dependency>
81+
82+ . Create a web app on Okta, use `http://localhost:8080/login/oauth2/code/okta` for redirect URI
83+
84+ . Populate Okta properties in `application.properties`
85+
86+ okta.oauth2.issuer=$issuer
87+ okta.oauth2.client-id=$clientId
88+ okta.oauth2.client-secret=$clientSecret
89+
90+ . Enable OIDC Login and OAuth Resource Server in `ApiGatewayApplication.java`
91+
92+ @Configuration
93+ static class OktaOAuth2WebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
94+
95+ @Override
96+ protected void configure(HttpSecurity http) throws Exception {
97+ // @formatter:off
98+ http
99+ .authorizeRequests().anyRequest().authenticated()
100+ .and()
101+ .oauth2Login()
102+ .and()
103+ .oauth2ResourceServer().jwt();
104+ // @formatter:on
105+ }
106+ }
107+
108+ . Enable Resource Server in `CarServiceApplication.java`
109+
110+ @Configuration
111+ static class OktaOAuth2WebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
112+
113+ @Override
114+ protected void configure(HttpSecurity http) throws Exception {
115+ // @formatter:off
116+ http
117+ .authorizeRequests().anyRequest().authenticated()
118+ .and()
119+ .oauth2ResourceServer().jwt();
120+ // @formatter:on
121+ }
122+ }
123+
124+ . Create `UserFeignClientInterceptor` to add `Authorization` header in `api-gateway` and register as a bean
125+
126+ . Make Feign Spring Security-aware
127+
128+ feign.hystrix.enabled=true
129+ hystrix.shareSecurityContext=true
130+
131+ . Restart all apps and show with security enabled
132+
133+ == Use Netflix Zuul for Routing
134+
135+ . Add Zuul as a dependency and `@EnableZuulProxy`
136+
137+ <dependency>
138+ <groupId>org.springframework.cloud</groupId>
139+ <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
140+ </dependency>
141+
142+ . Create an `AuthorizationHeaderFilter` to pass the access token to proxied routes [//todo]
143+
144+ . Register `AuthorizationHeaderFilter` filter as a bean [//todo]
145+
146+ . Add Zuul routes for `/cars` and `/home` [//todo]
147+
148+ . Add `HomeController` to the `car-service`
149+
150+ . Restart and confirm your Zuul routes work
151+
152+ . Fin! 🏁
43153
44154== Learn More!
45155
0 commit comments