diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..2f9f1cb Binary files /dev/null and b/.DS_Store differ diff --git a/config-repo/auth-server.yml b/config-repo/auth-server.yml new file mode 100644 index 0000000..880529e --- /dev/null +++ b/config-repo/auth-server.yml @@ -0,0 +1,2 @@ +server.port: 9999 +server.forward-headers-strategy: framework \ No newline at end of file diff --git a/config-repo/eureka-server.yml b/config-repo/eureka-server.yml new file mode 100644 index 0000000..08ce63d --- /dev/null +++ b/config-repo/eureka-server.yml @@ -0,0 +1,17 @@ +server: + port: 8761 + +eureka: + instance: + hostname: localhost + client: + registerWithEureka: false + fetchRegistry: false + serviceUrl: + defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ + # from: https://github.com/spring-cloud-samples/eureka/blob/master/src/main/resources/application.yml + server: + waitTimeInMsWhenSyncEmpty: 0 + response-cache-update-interval-ms: 5000 + + diff --git a/config-repo/gateway.yml b/config-repo/gateway.yml new file mode 100644 index 0000000..cf2eb2b --- /dev/null +++ b/config-repo/gateway.yml @@ -0,0 +1,76 @@ +server.port: 8443 +test1.data: helloupdate +logging: + level: + root: INFO + org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator: INFO + org.springframework.cloud.gateway: TRACE + org.springframework.web.server.adapter.HttpWebHandlerAdapter: TRACE + +spring.cloud.gateway.routes: + - id: course-composite + uri: lb://course-composite + predicates: + - Path=/course-composite/** + + - id: oauth2-server + uri: lb://auth-server + predicates: + - Path=/oauth2/** + + - id: oauth2-login + uri: lb://auth-server + predicates: + - Path=/login/** + + - id: oauth2-error + uri: lb://auth-server + predicates: + - Path=/error/** + + - id: course-composite-swagger-ui + uri: lb://course-composite + predicates: + - Path=/openapi/** + + - id: course-composite-swagger-ui-webjars + uri: lb://course-composite + predicates: + - Path=/webjars/** + + - id: eureka-api + uri: http://${app.eureka-server}:8761 + predicates: + - Path=/eureka/api/{segment} + filters: + - SetPath=/eureka/{segment} + + - id: eureka-web-start + uri: http://${app.eureka-server}:8761 + predicates: + - Path=/eureka/web + filters: + - SetPath=/ + + - id: eureka-web-other + uri: http://${app.eureka-server}:8761 + predicates: + - Path=/eureka/** + - id: config-server + uri: ${spring.cloud.config.uri} + predicates: + - Path=/config/** + filters: + - RewritePath=/config/(?.*), /$\{segment} + +spring.security.oauth2.resourceserver.jwt.issuer-uri: http://${app.auth-server}:9999 + + +management.endpoint.gateway.enabled: true +management.endpoints.web.exposure.include: "*" + +#server.ssl: +# key-store-type: PKCS12 +# key-store: classpath:keystore/edge.p12 +# key-store-password: password +# key-alias: localhost \ No newline at end of file diff --git a/spring-cloud/.DS_Store b/spring-cloud/.DS_Store new file mode 100644 index 0000000..b9ffbe5 Binary files /dev/null and b/spring-cloud/.DS_Store differ diff --git a/spring-cloud/authorization-server/.gitignore b/spring-cloud/authorization-server/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/spring-cloud/authorization-server/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/spring-cloud/authorization-server/pom.xml b/spring-cloud/authorization-server/pom.xml new file mode 100644 index 0000000..e1d65f3 --- /dev/null +++ b/spring-cloud/authorization-server/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.4 + + + io.javatab + authorization-server + 1.0.0 + authorization-server + Demo project for Spring Boot + + 17 + 2022.0.1 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.security + spring-security-oauth2-authorization-server + 1.0.0 + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.retry + spring-retry + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-cloud/authorization-server/src/main/java/io/javatab/springcloud/auth/AuthorizationServerApplication.java b/spring-cloud/authorization-server/src/main/java/io/javatab/springcloud/auth/AuthorizationServerApplication.java new file mode 100644 index 0000000..4382221 --- /dev/null +++ b/spring-cloud/authorization-server/src/main/java/io/javatab/springcloud/auth/AuthorizationServerApplication.java @@ -0,0 +1,13 @@ +package io.javatab.springcloud.auth; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AuthorizationServerApplication { + + public static void main(String[] args) { + SpringApplication.run(AuthorizationServerApplication.class, args); + } + +} diff --git a/spring-cloud/config-server/.gitignore b/spring-cloud/config-server/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/spring-cloud/config-server/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/spring-cloud/config-server/pom.xml b/spring-cloud/config-server/pom.xml new file mode 100644 index 0000000..b9558a7 --- /dev/null +++ b/spring-cloud/config-server/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + + + io.javatab + config-server + 0.0.1-SNAPSHOT + config-server + Demo project for Spring Boot + + 17 + 2022.0.1 + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.cloud + spring-cloud-config-server + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-cloud/config-server/src/main/java/io/javatab/springcloud/configserver/ConfigServerApplication.java b/spring-cloud/config-server/src/main/java/io/javatab/springcloud/configserver/ConfigServerApplication.java new file mode 100644 index 0000000..cf64d47 --- /dev/null +++ b/spring-cloud/config-server/src/main/java/io/javatab/springcloud/configserver/ConfigServerApplication.java @@ -0,0 +1,23 @@ +package io.javatab.springcloud.configserver; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; +import org.springframework.context.ConfigurableApplicationContext; + +@SpringBootApplication +@EnableConfigServer +public class ConfigServerApplication { + + private static final Logger LOG = LoggerFactory.getLogger(ConfigServerApplication.class); + + public static void main(String[] args) { + ConfigurableApplicationContext ctx = SpringApplication.run(ConfigServerApplication.class, args); + + String repoLocation = ctx.getEnvironment().getProperty("spring.cloud.config.server.native.search-locations"); + LOG.info("Serving configurations from folder: " + repoLocation); + } + +} diff --git a/spring-cloud/config-server/src/main/resources/application.yml b/spring-cloud/config-server/src/main/resources/application.yml new file mode 100644 index 0000000..94b5f18 --- /dev/null +++ b/spring-cloud/config-server/src/main/resources/application.yml @@ -0,0 +1,14 @@ +server.port: 8888 + +spring.cloud.config.server.native.search-locations: file:${PWD}/config-repo + +# WARNING: Exposing all management endpoints over http should only be used during development, must be locked down in production! +management.endpoint.health.show-details: "ALWAYS" +management.endpoints.web.exposure.include: "*" + +logging: + level: + root: info +--- +spring.config.activate.on-profile: docker,native +spring.cloud.config.server.native.search-locations: file:/config-repo \ No newline at end of file diff --git a/spring-cloud/config-server/src/test/java/io/javatab/springcloud/configserver/ConfigServerApplicationTests.java b/spring-cloud/config-server/src/test/java/io/javatab/springcloud/configserver/ConfigServerApplicationTests.java new file mode 100644 index 0000000..72b1961 --- /dev/null +++ b/spring-cloud/config-server/src/test/java/io/javatab/springcloud/configserver/ConfigServerApplicationTests.java @@ -0,0 +1,10 @@ +package io.javatab.springcloud.configserver; + +import org.springframework.boot.test.context.SpringBootTest; + +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@SpringBootTest(webEnvironment = RANDOM_PORT, properties = {"spring.profiles.active=native"}) +class ConfigServerApplicationTests { + +} diff --git a/spring-cloud/eureka-server/.gitignore b/spring-cloud/eureka-server/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/spring-cloud/eureka-server/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/spring-cloud/eureka-server/pom.xml b/spring-cloud/eureka-server/pom.xml new file mode 100644 index 0000000..548ec64 --- /dev/null +++ b/spring-cloud/eureka-server/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + + + io.javatab + eureka-server + 0.0.1-SNAPSHOT + eureka-server + Demo project for Spring Boot + + 17 + 2022.0.1 + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.retry + spring-retry + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-cloud/eureka-server/src/main/java/io/javatab/springcloud/eurekaserver/EurekaServerApplication.java b/spring-cloud/eureka-server/src/main/java/io/javatab/springcloud/eurekaserver/EurekaServerApplication.java new file mode 100644 index 0000000..23556f0 --- /dev/null +++ b/spring-cloud/eureka-server/src/main/java/io/javatab/springcloud/eurekaserver/EurekaServerApplication.java @@ -0,0 +1,15 @@ +package io.javatab.springcloud.eurekaserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +@SpringBootApplication +@EnableEurekaServer +public class EurekaServerApplication { + + public static void main(String[] args) { + SpringApplication.run(EurekaServerApplication.class, args); + } + +} diff --git a/spring-cloud/eureka-server/src/test/java/io/javatab/springcloud/eurekaserver/EurekaServerApplicationTests.java b/spring-cloud/eureka-server/src/test/java/io/javatab/springcloud/eurekaserver/EurekaServerApplicationTests.java new file mode 100644 index 0000000..40220da --- /dev/null +++ b/spring-cloud/eureka-server/src/test/java/io/javatab/springcloud/eurekaserver/EurekaServerApplicationTests.java @@ -0,0 +1,11 @@ +package io.javatab.springcloud.eurekaserver; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@SpringBootTest(webEnvironment = RANDOM_PORT, properties = {"spring.cloud.config.enabled=false"}) +class EurekaServerApplicationTests { + +} diff --git a/spring-cloud/gateway/.gitignore b/spring-cloud/gateway/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/spring-cloud/gateway/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/spring-cloud/gateway/pom.xml b/spring-cloud/gateway/pom.xml new file mode 100644 index 0000000..e3ffffb --- /dev/null +++ b/spring-cloud/gateway/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + + + io.javatab + gateway + 1.0.0 + gateway + Demo project for Spring Boot + + 17 + 2022.0.1 + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + org.springframework.boot + spring-boot-starter-security + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.security + spring-security-oauth2-resource-server + + + org.springframework.security + spring-security-oauth2-jose + + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.retry + spring-retry + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-cloud/gateway/src/main/java/io/javatab/springcloud/gateway/GatewayApplication.java b/spring-cloud/gateway/src/main/java/io/javatab/springcloud/gateway/GatewayApplication.java new file mode 100644 index 0000000..c026ee0 --- /dev/null +++ b/spring-cloud/gateway/src/main/java/io/javatab/springcloud/gateway/GatewayApplication.java @@ -0,0 +1,29 @@ +package io.javatab.springcloud.gateway; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.web.reactive.function.client.WebClient; + +@SpringBootApplication +public class GatewayApplication { + + private static final Logger LOG = LoggerFactory.getLogger(GatewayApplication.class); + + @Bean + @LoadBalanced + public WebClient.Builder loadBalancedWebClientBuilder() { + return WebClient.builder(); + } + + public static void main(String[] args) { + ConfigurableApplicationContext ctx = SpringApplication.run(GatewayApplication.class, args); + + String testdata = ctx.getEnvironment().getProperty("test1.data"); + LOG.info("testdata ====> " + testdata); + } +} diff --git a/spring-cloud/gateway/src/test/java/io/javatab/springcloud/gateway/GatewayApplicationTests.java b/spring-cloud/gateway/src/test/java/io/javatab/springcloud/gateway/GatewayApplicationTests.java new file mode 100644 index 0000000..2506a72 --- /dev/null +++ b/spring-cloud/gateway/src/test/java/io/javatab/springcloud/gateway/GatewayApplicationTests.java @@ -0,0 +1,18 @@ +package io.javatab.springcloud.gateway; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@SpringBootTest( + webEnvironment = RANDOM_PORT, + properties = { + "spring.security.oauth2.resourceserver.jwt.issuer-uri=", + "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=some-url", + "spring.main.allow-bean-definition-overriding=true", + "eureka.client.enabled=false", + "spring.cloud.config.enabled=false"}) +class GatewayApplicationTests { + +}