-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- keycloak connected with API Gateway - keycloak JWT Tokens passed to services
- Loading branch information
Showing
15 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
ms-api-gateway/src/main/java/pl/mg/ms/gw/security/WebSecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pl.mg.ms.gw.security; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.Customizer; | ||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; | ||
import org.springframework.security.config.web.server.ServerHttpSecurity; | ||
import org.springframework.security.web.server.SecurityWebFilterChain; | ||
import org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher; | ||
|
||
@Configuration | ||
@EnableWebFluxSecurity | ||
public class WebSecurityConfiguration { | ||
|
||
@Order(1) | ||
@Bean | ||
SecurityWebFilterChain actuatorHttpSecurity(ServerHttpSecurity http) { | ||
http | ||
.securityMatcher(new PathPatternParserServerWebExchangeMatcher("/actuator/**")) | ||
.authorizeExchange((exchanges) -> exchanges | ||
.anyExchange().permitAll() | ||
); | ||
return http.build(); | ||
} | ||
|
||
@Bean | ||
SecurityWebFilterChain apiHttpSecurity(ServerHttpSecurity http) { | ||
http | ||
.securityMatcher(new PathPatternParserServerWebExchangeMatcher("/api/**")) | ||
.authorizeExchange((exchanges) -> exchanges | ||
.anyExchange().authenticated() | ||
) | ||
.oauth2ResourceServer(oAuth2ResourceServerSpec -> oAuth2ResourceServerSpec | ||
.jwt(Customizer.withDefaults())) | ||
.csrf(Customizer.withDefaults()); | ||
return http.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
ms-cms-service/src/main/java/pl/mg/search/cms/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pl.mg.search.cms.config; | ||
|
||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.Customizer; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@EnableWebSecurity | ||
@Configuration | ||
public class SecurityConfig { | ||
|
||
@Order(1) | ||
@Bean | ||
public SecurityFilterChain actuatorHttpSecurity(HttpSecurity http) throws Exception { | ||
http | ||
.securityMatcher(request -> request.getServletPath().startsWith("/actuator/")) | ||
.authorizeHttpRequests((requests) -> requests | ||
.anyRequest().permitAll() | ||
); | ||
return http.build(); | ||
} | ||
|
||
@Bean | ||
public SecurityFilterChain apiSecurity(HttpSecurity http) throws Exception { | ||
http | ||
.securityMatcher(request -> request.getServletPath().startsWith("/api/")) | ||
.authorizeHttpRequests((exchanges) -> exchanges | ||
.anyRequest().authenticated() | ||
) | ||
.oauth2ResourceServer(oAuth2ResourceServerSpec -> oAuth2ResourceServerSpec | ||
.jwt(Customizer.withDefaults())) | ||
.csrf(Customizer.withDefaults()); | ||
return http.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
ms-cms-service/src/main/resources/application-docker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8082/realms/ms/protocol/openid-connect/certs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8082/realms/ms/protocol/openid-connect/certs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
ms-stock-service/src/main/java/pl/mg/search/stock/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package pl.mg.search.stock.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.Customizer; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@EnableWebSecurity | ||
@Configuration | ||
public class SecurityConfig { | ||
@Order(1) | ||
@Bean | ||
public SecurityFilterChain actuatorHttpSecurity(HttpSecurity http) throws Exception { | ||
http | ||
.securityMatcher(request -> request.getServletPath().startsWith("/actuator/")) | ||
.authorizeHttpRequests((requests) -> requests | ||
.anyRequest().permitAll() | ||
); | ||
return http.build(); | ||
} | ||
|
||
@Bean | ||
public SecurityFilterChain apiSecurity(HttpSecurity http) throws Exception { | ||
http | ||
.securityMatcher(request -> request.getServletPath().startsWith("/api/")) | ||
.authorizeHttpRequests((exchanges) -> exchanges | ||
.anyRequest().authenticated() | ||
) | ||
.oauth2ResourceServer(oAuth2ResourceServerSpec -> oAuth2ResourceServerSpec | ||
.jwt(Customizer.withDefaults())) | ||
.csrf(Customizer.withDefaults()); | ||
return http.build(); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
ms-stock-service/src/main/resources/application-docker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8082/realms/ms/protocol/openid-connect/certs |
1 change: 1 addition & 0 deletions
1
ms-stock-service/src/main/resources/application-local.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8082/realms/ms/protocol/openid-connect/certs |