-
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.
- Loading branch information
0 parents
commit f2da265
Showing
100 changed files
with
4,329 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
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,3 @@ | ||
FROM openjdk:17 | ||
COPY target/*.jar app.jar | ||
ENTRYPOINT ["java", "-jar", "/app.jar"] |
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,15 @@ | ||
FROM eclipse-temurin:17.0.4.1_1-jre as builder | ||
WORKDIR extracted | ||
ADD target/*.jar app.jar | ||
RUN java -Djarmode=layertools -jar app.jar extract | ||
|
||
|
||
|
||
FROM eclipse-temurin:17.0.4.1_1-jre | ||
WORKDIR application | ||
COPY --from=builder extracted/dependencies/ ./ | ||
COPY --from=builder extracted/spring-boot-loader/ ./ | ||
COPY --from=builder extracted/snapshot-dependencies/ ./ | ||
COPY --from=builder extracted/application/ ./ | ||
EXPOSE 8080 | ||
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] |
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,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.pcdev.shop</groupId> | ||
<artifactId>microservices</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>api-gateway</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-gateway</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-tracing-bridge-brave</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.zipkin.reporter2</groupId> | ||
<artifactId>zipkin-reporter-brave</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-registry-prometheus</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
|
||
|
||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
api-gateway/src/main/java/com/pcdev/apigateway/ApiGatewayApplication.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,13 @@ | ||
package com.pcdev.apigateway; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
public class ApiGatewayApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ApiGatewayApplication.class, args); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api-gateway/src/main/java/com/pcdev/apigateway/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,28 @@ | ||
package com.pcdev.apigateway.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; | ||
import org.springframework.security.config.web.server.ServerHttpSecurity; | ||
import org.springframework.security.web.server.SecurityWebFilterChain; | ||
|
||
@Configuration | ||
@EnableWebFluxSecurity //because we are using spring-cloud-starter-gateway for this api gateway. This is | ||
// a spring webflux project not spring mvc project. So we need to enable webflux security annotation | ||
public class SecurityConfig { | ||
|
||
|
||
@Bean | ||
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity serverHttpSecurity) { | ||
serverHttpSecurity | ||
.csrf(ServerHttpSecurity.CsrfSpec::disable) | ||
.authorizeExchange(exchange -> exchange | ||
.pathMatchers("/eureka/**") | ||
.permitAll() | ||
.anyExchange() | ||
.authenticated()) | ||
.oauth2ResourceServer(ServerHttpSecurity.OAuth2ResourceServerSpec::jwt); //to enable resource server capabilities as well as JWT security | ||
return serverHttpSecurity.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
server.port=8080 | ||
eureka.client.serviceUrl.defaultZone=http://eureka:password@discovery-server:8761/eureka | ||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://keycloak:8080/realms/online-shopping-app-realm | ||
spring.zipkin.base-url=http://zipkin:9411 |
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,35 @@ | ||
eureka.client.serviceUrl.defaultZone=http://eureka:password@localhost:8761/eureka | ||
spring.application.name=api-gateway | ||
logging.level.root=INFO | ||
logging.level.org.springframework.cloud.gateway.route.RouteDefinitionLocator=INFO | ||
logging.level.org.springframework.cloud.gateway=TRACE | ||
|
||
#Product Service Route | ||
spring.cloud.gateway.routes[0].id=product-service | ||
spring.cloud.gateway.routes[0].uri=lb://product-service | ||
spring.cloud.gateway.routes[0].predicates[0]=Path=/api/product | ||
|
||
#Order Service Route | ||
spring.cloud.gateway.routes[1].id=order-service | ||
spring.cloud.gateway.routes[1].uri=lb://order-service | ||
spring.cloud.gateway.routes[1].predicates[0]=Path=/api/order | ||
|
||
#Discovery Server Route | ||
spring.cloud.gateway.routes[2].id=discovery-server | ||
spring.cloud.gateway.routes[2].uri=http://localhost:8761 | ||
spring.cloud.gateway.routes[2].predicates[0]=Path=/eureka/web | ||
spring.cloud.gateway.routes[2].filters[0]=SetPath=/ | ||
|
||
#Discovery Server Static Resources Route | ||
spring.cloud.gateway.routes[3].id=discovery-server-static | ||
spring.cloud.gateway.routes[3].uri=http://localhost:8761 | ||
spring.cloud.gateway.routes[3].predicates[0]=Path=/eureka/** | ||
|
||
|
||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8181/realms/spring-boot-microservices-realm | ||
|
||
|
||
management.tracing.sampling.probability=1.0 | ||
|
||
#Actuator Prometheus Endpoint | ||
management.endpoints.web.exposure.include= prometheus |
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 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Oops, something went wrong.