├── .github └── workflows │ ├── deploy-auth.yml │ ├── deploy-cars.yml │ ├── deploy-config.yml │ ├── deploy-discovery.yml │ ├── deploy-gateway.yml │ ├── verify-auth.yml │ ├── verify-cars.yml │ ├── verify-cdk.yml │ ├── verify-config.yml │ ├── verify-discovery.yml │ └── verify-gateway.yml ├── .gitignore ├── DEPLOY.md ├── LICENSE ├── README.md ├── auth-service ├── Dockerfile ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ ├── java │ └── com │ │ └── rd │ │ └── spring │ │ └── auth │ │ ├── AuthApplication.java │ │ ├── controller │ │ └── AuthController.java │ │ ├── model │ │ ├── AuthRequest.java │ │ └── AuthResponse.java │ │ └── service │ │ ├── AuthService.java │ │ └── JwtService.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts └── src │ └── main │ └── kotlin │ └── com │ └── rd │ └── spring │ └── dependencies │ └── Dependencies.kt ├── cars-service ├── Dockerfile ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ ├── java │ └── com │ │ └── rd │ │ └── spring │ │ └── cars │ │ ├── CarServiceApplication.java │ │ ├── controllers │ │ └── CarController.java │ │ └── model │ │ └── CarResponse.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── cdk ├── .gitignore ├── .npmignore ├── README.md ├── bin │ ├── cdk.ts │ └── ecr-cdk.ts ├── build.gradle.kts ├── cdk.json ├── jest.config.js ├── lib │ ├── cdk-stack.ts │ └── ecr-stack.ts ├── package-lock.json ├── package.json ├── settings.gradle.kts ├── test │ └── cdk.test.ts └── tsconfig.json ├── config-service ├── Dockerfile ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ ├── java │ └── com │ │ └── rd │ │ └── spring │ │ └── config │ │ └── ConfigApplication.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── discovery-service ├── Dockerfile ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ ├── java │ └── com │ │ └── rd │ │ └── spring │ │ └── discovery │ │ └── DiscoveryApplication.java │ └── resources │ └── application.yml ├── docker-compose.yml ├── docs └── images │ └── microservices-architecture.png ├── gateway-service ├── Dockerfile ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ ├── java │ └── com │ │ └── rd │ │ └── spring │ │ └── gateway │ │ ├── GatewayApplication.java │ │ └── config │ │ ├── AuthenticationFilter.java │ │ ├── GatewayConfig.java │ │ ├── JwtUtil.java │ │ └── RouterValidator.java │ └── resources │ ├── application.yml │ └── bootstrap.yml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle.kts /.github/workflows/deploy-auth.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Auth Service 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "auth-service/**" 9 | 10 | jobs: 11 | build: 12 | name: Deploy Auth Service 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: [ '17' ] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 0 22 | 23 | - name: Configure AWS credentials 24 | uses: aws-actions/configure-aws-credentials@v2 25 | with: 26 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 27 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 28 | aws-region: us-east-1 29 | 30 | - name: Setup Java 31 | uses: actions/setup-java@v1 32 | with: 33 | java-version: 17 34 | 35 | - name: Login to Amazon ECR 36 | id: login-ecr 37 | uses: aws-actions/amazon-ecr-login@v1 38 | 39 | - name: Build 40 | run: ./gradlew :auth-service:build 41 | 42 | - name: Build, Tag and Push Docker Image 43 | env: 44 | REGISTRY: ${{ steps.login-ecr.outputs.registry }} 45 | REPOSITORY: spring-cloud-security-jwt-auth-service 46 | IMAGE_TAG: latest 47 | working-directory: auth-service 48 | run: | 49 | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . 50 | docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG 51 | -------------------------------------------------------------------------------- /.github/workflows/deploy-cars.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Cars Service 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "cars-service/**" 9 | 10 | jobs: 11 | build: 12 | name: Deploy Cars Service 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: [ '17' ] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 0 22 | 23 | - name: Configure AWS credentials 24 | uses: aws-actions/configure-aws-credentials@v2 25 | with: 26 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 27 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 28 | aws-region: us-east-1 29 | 30 | - name: Setup Java 31 | uses: actions/setup-java@v1 32 | with: 33 | java-version: 17 34 | 35 | - name: Login to Amazon ECR 36 | id: login-ecr 37 | uses: aws-actions/amazon-ecr-login@v1 38 | 39 | - name: Build 40 | run: ./gradlew :cars-service:build 41 | 42 | - name: Build, Tag and Push Docker Image 43 | env: 44 | REGISTRY: ${{ steps.login-ecr.outputs.registry }} 45 | REPOSITORY: spring-cloud-security-jwt-cars-service 46 | IMAGE_TAG: latest 47 | working-directory: cars-service 48 | run: | 49 | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . 50 | docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG 51 | -------------------------------------------------------------------------------- /.github/workflows/deploy-config.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Config Service 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "config-service/**" 9 | 10 | jobs: 11 | build: 12 | name: Deploy Config Service 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: [ '17' ] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 0 22 | 23 | - name: Configure AWS credentials 24 | uses: aws-actions/configure-aws-credentials@v2 25 | with: 26 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 27 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 28 | aws-region: us-east-1 29 | 30 | - name: Setup Java 31 | uses: actions/setup-java@v1 32 | with: 33 | java-version: 17 34 | 35 | - name: Login to Amazon ECR 36 | id: login-ecr 37 | uses: aws-actions/amazon-ecr-login@v1 38 | 39 | - name: Build 40 | run: ./gradlew :config-service:build 41 | 42 | - name: Build, Tag and Push Docker Image 43 | env: 44 | REGISTRY: ${{ steps.login-ecr.outputs.registry }} 45 | REPOSITORY: spring-cloud-security-jwt-config-service 46 | IMAGE_TAG: latest 47 | working-directory: config-service 48 | run: | 49 | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . 50 | docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG 51 | -------------------------------------------------------------------------------- /.github/workflows/deploy-discovery.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Disconvery Service 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "discovery-service/**" 9 | 10 | jobs: 11 | build: 12 | name: Deploy Disconvery Service 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: [ '17' ] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 0 22 | 23 | - name: Configure AWS credentials 24 | uses: aws-actions/configure-aws-credentials@v2 25 | with: 26 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 27 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 28 | aws-region: us-east-1 29 | 30 | - name: Setup Java 31 | uses: actions/setup-java@v1 32 | with: 33 | java-version: 17 34 | 35 | - name: Login to Amazon ECR 36 | id: login-ecr 37 | uses: aws-actions/amazon-ecr-login@v1 38 | 39 | - name: Build 40 | run: ./gradlew :discovery-service:build 41 | 42 | - name: Build, Tag and Push Docker Image 43 | env: 44 | REGISTRY: ${{ steps.login-ecr.outputs.registry }} 45 | REPOSITORY: spring-cloud-security-jwt-discovery-service 46 | IMAGE_TAG: latest 47 | working-directory: discovery-service 48 | run: | 49 | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . 50 | docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG 51 | -------------------------------------------------------------------------------- /.github/workflows/deploy-gateway.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Gateway Service 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "gateway-service/**" 9 | 10 | jobs: 11 | build: 12 | name: Deploy Gateway Service 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: [ '17' ] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: 0 22 | 23 | - name: Configure AWS credentials 24 | uses: aws-actions/configure-aws-credentials@v2 25 | with: 26 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 27 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 28 | aws-region: us-east-1 29 | 30 | - name: Setup Java 31 | uses: actions/setup-java@v1 32 | with: 33 | java-version: 17 34 | 35 | - name: Login to Amazon ECR 36 | id: login-ecr 37 | uses: aws-actions/amazon-ecr-login@v1 38 | 39 | - name: Build 40 | run: ./gradlew :gateway-service:build 41 | 42 | - name: Build, Tag and Push Docker Image 43 | env: 44 | REGISTRY: ${{ steps.login-ecr.outputs.registry }} 45 | REPOSITORY: spring-cloud-security-jwt-discovery-service 46 | IMAGE_TAG: latest 47 | working-directory: gateway-service 48 | run: | 49 | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . 50 | docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG 51 | -------------------------------------------------------------------------------- /.github/workflows/verify-auth.yml: -------------------------------------------------------------------------------- 1 | name: Verify Auth Service 2 | 3 | on: 4 | pull_request: 5 | types: [ opened, synchronize, reopened ] 6 | paths: 7 | - "auth-service/**" 8 | 9 | jobs: 10 | build: 11 | name: Verify Auth Service 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | java: [ '17' ] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Setup Java 23 | uses: actions/setup-java@v1 24 | with: 25 | java-version: 17 26 | 27 | - name: Build 28 | run: ./gradlew :auth-service:build 29 | 30 | - name: Build Docker Image 31 | run: ./gradlew :auth-service:docker 32 | 33 | -------------------------------------------------------------------------------- /.github/workflows/verify-cars.yml: -------------------------------------------------------------------------------- 1 | name: Verify Cars Service 2 | 3 | on: 4 | pull_request: 5 | types: [ opened, synchronize, reopened ] 6 | paths: 7 | - "cars-service/**" 8 | 9 | jobs: 10 | build: 11 | name: Verify Cars Service 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | java: [ '17' ] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Setup Java 23 | uses: actions/setup-java@v1 24 | with: 25 | java-version: 17 26 | 27 | - name: Build 28 | run: ./gradlew :cars-service:build 29 | 30 | -------------------------------------------------------------------------------- /.github/workflows/verify-cdk.yml: -------------------------------------------------------------------------------- 1 | name: Verify CDK 2 | 3 | on: 4 | pull_request: 5 | types: [ opened, synchronize, reopened ] 6 | paths: 7 | - "cdk/**" 8 | 9 | jobs: 10 | build: 11 | name: Verify CDK 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | java: [ '17' ] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Setup Java 23 | uses: actions/setup-java@v1 24 | with: 25 | java-version: 17 26 | 27 | - name: Build 28 | run: ./gradlew :cdk:build 29 | 30 | -------------------------------------------------------------------------------- /.github/workflows/verify-config.yml: -------------------------------------------------------------------------------- 1 | name: Verify Config Service 2 | 3 | on: 4 | pull_request: 5 | types: [ opened, synchronize, reopened ] 6 | paths: 7 | - "config-service/**" 8 | 9 | jobs: 10 | build: 11 | name: Verify Config Service 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | java: [ '17' ] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Setup Java 23 | uses: actions/setup-java@v1 24 | with: 25 | java-version: 17 26 | 27 | - name: Build 28 | run: ./gradlew :config-service:build 29 | 30 | -------------------------------------------------------------------------------- /.github/workflows/verify-discovery.yml: -------------------------------------------------------------------------------- 1 | name: Verify Discovery Service 2 | 3 | on: 4 | pull_request: 5 | types: [ opened, synchronize, reopened ] 6 | paths: 7 | - "discovery-service/**" 8 | 9 | jobs: 10 | build: 11 | name: Verify Disocvery Service 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | java: [ '17' ] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Setup Java 23 | uses: actions/setup-java@v1 24 | with: 25 | java-version: 17 26 | 27 | - name: Build 28 | run: ./gradlew :discovery-service:build 29 | 30 | -------------------------------------------------------------------------------- /.github/workflows/verify-gateway.yml: -------------------------------------------------------------------------------- 1 | name: Verify Gateway Service 2 | 3 | on: 4 | pull_request: 5 | types: [ opened, synchronize, reopened ] 6 | paths: 7 | - "gateway-service/**" 8 | 9 | jobs: 10 | build: 11 | name: Verify Gateway Service 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | java: [ '17' ] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Setup Java 23 | uses: actions/setup-java@v1 24 | with: 25 | java-version: 17 26 | 27 | - name: Build 28 | run: ./gradlew :gateway-service:build 29 | 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.war 15 | *.nar 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | .gradle 21 | build 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | # IDE specific 27 | .idea 28 | 29 | # OS Specific 30 | .DS_Store 31 | -------------------------------------------------------------------------------- /DEPLOY.md: -------------------------------------------------------------------------------- 1 | ./gradlew :cdk:deployEcr 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Rajith Delantha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud Security JWT 2 | Spring Cloud Security JWT is Simple MicroServices project to demonstrate Spring Cloud Components and how it interacts with Config server, Discovery Server and how its performing security validation. 3 | 4 | ## Architecture 5 | ![My Image](docs/images/microservices-architecture.png) 6 | 7 | ## Prerequisites 8 | * Java 17 9 | 10 | ## Build all projects 11 | ```shell 12 | ./gradlew clean build 13 | ``` 14 | 15 | ## Run Config Service 16 | ```shell 17 | java -jar config-service/build/libs/config-service-0.0.1.jar 18 | ``` 19 | 20 | ## Run Discovery Service 21 | ```shell 22 | java -jar discovery-service/build/libs/discovery-service-0.0.1.jar 23 | ``` 24 | 25 | ## Run Gateway Service 26 | ```shell 27 | java -jar gateway-service/build/libs/gateway-service-0.0.1.jar 28 | ``` 29 | 30 | ## Run Auth Service 31 | ```shell 32 | java -jar auth-service/build/libs/auth-service-0.0.1.jar 33 | ``` 34 | 35 | ## Run Cars Service 36 | ```shell 37 | java -jar cars-service/build/libs/cars-service-0.0.1.jar 38 | ``` 39 | 40 | ## Testing Scenarios 41 | ### Execute auth register REST call 42 | ```shell 43 | curl --location --request POST 'http://localhost:8080/auth/register' \ 44 | --header 'Content-Type: application/json' \ 45 | --data-raw '{ 46 | "email": "a@a.com", 47 | "password": "password", 48 | "name": "name" 49 | }' 50 | ``` 51 | 52 | ```shell 53 | { 54 | "accessToken": "", 55 | "refreshToken": "" 56 | } 57 | ``` 58 | 59 | ### Execute Get Cars REST call without Authorization header 60 | ```shell 61 | curl --location --request GET 'http://localhost:8080/cars' 62 | ``` 63 | 64 | ```shell 65 | 401 66 | ``` 67 | 68 | ### Execute Get Card REST call with Authorization header from step 1 69 | ```shell 70 | curl --location --request GET 'http://localhost:8080/cars' \ 71 | --header 'Authorization: ' 72 | ``` 73 | 74 | ```shell 75 | [ 76 | { 77 | "carId": "1", 78 | "carName": "Audi" 79 | } 80 | ] 81 | ``` 82 | 83 | -------------------------------------------------------------------------------- /auth-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17 2 | 3 | MAINTAINER Rajith Delantha 4 | 5 | COPY build/libs/auth-service-0.0.1.jar /app/ 6 | CMD ["java", "-Xmx200m", "-jar", "/app/auth-service-0.0.1.jar"] 7 | 8 | EXPOSE 9004 9 | -------------------------------------------------------------------------------- /auth-service/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.rd.spring.dependencies.Dependencies.gson 2 | import com.rd.spring.dependencies.Dependencies.javaxAnnotation 3 | import com.rd.spring.dependencies.Dependencies.jwtApi 4 | import com.rd.spring.dependencies.Dependencies.jwtImpl 5 | import com.rd.spring.dependencies.Dependencies.jwtJackson 6 | import com.rd.spring.dependencies.Dependencies.lombok 7 | import com.bmuschko.gradle.docker.tasks.image.* 8 | 9 | plugins { 10 | java 11 | id("org.springframework.boot") version "3.0.5" 12 | id("io.spring.dependency-management") version "1.1.0" 13 | id("com.bmuschko.docker-remote-api") version "9.3.0" 14 | id("com.patdouble.awsecr") version "0.7.0" 15 | } 16 | 17 | group = "com.rd.spring" 18 | version = "0.0.1" 19 | java.sourceCompatibility = JavaVersion.VERSION_17 20 | java.targetCompatibility = JavaVersion.VERSION_17 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | extra["springCloudVersion"] = "2022.0.1" 27 | 28 | dependencies { 29 | implementation("org.springframework.boot:spring-boot-starter-web") 30 | implementation("org.springframework.cloud:spring-cloud-starter-config") 31 | implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client") 32 | implementation("org.springframework.cloud:spring-cloud-starter-bootstrap") 33 | 34 | implementation(javaxAnnotation) 35 | 36 | compileOnly(lombok) 37 | annotationProcessor(lombok) 38 | 39 | implementation(gson) 40 | implementation(jwtApi) 41 | implementation(jwtImpl) 42 | implementation(jwtJackson) 43 | } 44 | 45 | dependencyManagement { 46 | imports { 47 | mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}") 48 | } 49 | } 50 | 51 | tasks.create("dockerBuild", DockerBuildImage::class) { 52 | inputDir.set(file(".")) 53 | images.add("spring-cloud-security-jwt/auth-service") 54 | } 55 | -------------------------------------------------------------------------------- /auth-service/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "auth-service" 2 | -------------------------------------------------------------------------------- /auth-service/src/main/java/com/rd/spring/auth/AuthApplication.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.auth; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class AuthApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(AuthApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /auth-service/src/main/java/com/rd/spring/auth/controller/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.auth.controller; 2 | 3 | import com.rd.spring.auth.model.AuthRequest; 4 | import com.rd.spring.auth.model.AuthResponse; 5 | import com.rd.spring.auth.service.AuthService; 6 | import lombok.RequiredArgsConstructor; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestBody; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | @RequestMapping(value = "/auth") 15 | @RequiredArgsConstructor 16 | public class AuthController { 17 | 18 | private final AuthService authService; 19 | 20 | @PostMapping(value = "/register") 21 | public ResponseEntity register(@RequestBody AuthRequest authRequest) { 22 | return ResponseEntity.ok(authService.register(authRequest)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /auth-service/src/main/java/com/rd/spring/auth/model/AuthRequest.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.auth.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Builder 12 | public class AuthRequest { 13 | 14 | private String email; 15 | private String password; 16 | private String name; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /auth-service/src/main/java/com/rd/spring/auth/model/AuthResponse.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.auth.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Builder 12 | public class AuthResponse { 13 | 14 | private String accessToken; 15 | private String refreshToken; 16 | } 17 | -------------------------------------------------------------------------------- /auth-service/src/main/java/com/rd/spring/auth/service/AuthService.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.auth.service; 2 | 3 | import com.rd.spring.auth.model.AuthRequest; 4 | import com.rd.spring.auth.model.AuthResponse; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | @RequiredArgsConstructor 10 | public class AuthService { 11 | 12 | private final JwtService jwtService; 13 | 14 | public AuthResponse register(AuthRequest authRequest) { 15 | String accessToken = jwtService.generate(authRequest.getEmail(), "ACCESS"); 16 | String refreshToken = jwtService.generate(authRequest.getEmail(), "REFRESH"); 17 | 18 | return new AuthResponse(accessToken, refreshToken); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /auth-service/src/main/java/com/rd/spring/auth/service/JwtService.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.auth.service; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import io.jsonwebtoken.Jwts; 5 | import io.jsonwebtoken.security.Keys; 6 | import java.security.Key; 7 | import java.util.Date; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | import javax.annotation.PostConstruct; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.stereotype.Service; 13 | 14 | @Service 15 | public class JwtService { 16 | 17 | @Value("${jwt.secret}") 18 | private String secret; 19 | 20 | @Value("${jwt.expiration}") 21 | private String expirationTime; 22 | 23 | private Key key; 24 | 25 | @PostConstruct 26 | public void init() { 27 | this.key = Keys.hmacShaKeyFor(secret.getBytes()); 28 | } 29 | 30 | public Claims getAllClaimsFromToken(String token) { 31 | return Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token).getBody(); 32 | } 33 | 34 | 35 | public Date getExpirationDateFromToken(String token) { 36 | return getAllClaimsFromToken(token).getExpiration(); 37 | } 38 | 39 | private Boolean isTokenExpired(String token) { 40 | final Date expiration = getExpirationDateFromToken(token); 41 | return expiration.before(new Date()); 42 | } 43 | 44 | public String generate(String email, String type) { 45 | Map claims = new HashMap<>(); 46 | claims.put("email", email); 47 | claims.put("type", type); 48 | return doGenerateToken(claims, email, type); 49 | } 50 | 51 | private String doGenerateToken(Map claims, String username, String type) { 52 | long expirationTimeLong; 53 | if ("ACCESS".equals(type)) { 54 | expirationTimeLong = Long.parseLong(expirationTime) * 1000; 55 | } else { 56 | expirationTimeLong = Long.parseLong(expirationTime) * 1000 * 5; 57 | } 58 | final Date createdDate = new Date(); 59 | final Date expirationDate = new Date(createdDate.getTime() + expirationTimeLong); 60 | 61 | return Jwts.builder() 62 | .setClaims(claims) 63 | .setSubject(username) 64 | .setIssuedAt(createdDate) 65 | .setExpiration(expirationDate) 66 | .signWith(key) 67 | .compact(); 68 | } 69 | 70 | public Boolean validateToken(String token) { 71 | return !isTokenExpired(token); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /auth-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9004 3 | 4 | spring: 5 | application: 6 | name: auth-service 7 | 8 | jwt: 9 | secret: AvHGRK8C0ia4uOuxxqPD5DTbWC9F9TWvPStp3pb7ARo0oK2mJ3pd3YG4lxA9i8bj6OTbadweheufHNyG 10 | expiration: 20400 11 | -------------------------------------------------------------------------------- /auth-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | enabled: true 5 | uri: http://localhost:9296 6 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.spring.dependency-management") version "1.1.0" 3 | } 4 | 5 | group = "com.rd.spring" 6 | version = "1.0-SNAPSHOT" 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `java-gradle-plugin` 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/com/rd/spring/dependencies/Dependencies.kt: -------------------------------------------------------------------------------- 1 | package com.rd.spring.dependencies 2 | 3 | import com.rd.spring.dependencies.Versions.springBootVersion 4 | import com.rd.spring.dependencies.Versions.springCloudVersion 5 | import com.rd.spring.dependencies.Versions.lombokVersion 6 | import com.rd.spring.dependencies.Versions.jwtVersion 7 | 8 | object Versions { 9 | const val springBootVersion = "3.0.5" 10 | const val springCloudVersion = "2022.0.1" 11 | const val lombokVersion = "1.18.22" 12 | const val jwtVersion = "0.11.1" 13 | } 14 | 15 | object Dependencies { 16 | // Spring 17 | const val springBootStarter = "org.springframework.boot:spring-boot-starter:$springBootVersion" 18 | const val springBootWeb = "org.springframework.boot:spring-boot-starter-web:$springBootVersion" 19 | 20 | // Spring Cloud 21 | const val springBootConfigServer = "org.springframework.cloud:spring-cloud-config-server:$springBootVersion" 22 | const val springWebflux = "org.springframework.cloud:spring-cloud-starter-gateway:$springBootVersion" 23 | const val eurekaClient = "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:$springBootVersion" 24 | const val hystrix = "org.springframework.cloud:spring-cloud-starter-netflix-hystrix:$springBootVersion" 25 | const val eurekaServer = "org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:$springBootVersion" 26 | 27 | // Other 28 | const val lombok = "org.projectlombok:lombok:$lombokVersion" 29 | const val gson = "com.google.code.gson:gson:2.8.2" 30 | const val jwtApi = "io.jsonwebtoken:jjwt-api:$jwtVersion" 31 | const val jwtImpl = "io.jsonwebtoken:jjwt-impl:$jwtVersion" 32 | const val jwtJackson = "io.jsonwebtoken:jjwt-jackson:$jwtVersion" 33 | const val javaxAnnotation = "javax.annotation:javax.annotation-api:1.3.2" 34 | const val javaxServlet = "javax.servlet:javax.servlet-api:3.1.0" 35 | 36 | } 37 | -------------------------------------------------------------------------------- /cars-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17 2 | MAINTAINER Rajith Delantha 3 | 4 | COPY build/libs/cars-service-0.0.1.jar /app/ 5 | CMD ["java", "-Xmx200m", "-jar", "/app/cars-service-0.0.1.jar"] 6 | 7 | EXPOSE 9001 8 | -------------------------------------------------------------------------------- /cars-service/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.rd.spring.dependencies.Dependencies.lombok 2 | 3 | plugins { 4 | java 5 | id("org.springframework.boot") version "3.0.5" 6 | id("io.spring.dependency-management") version "1.1.0" 7 | } 8 | 9 | group = "com.rd.spring" 10 | version = "0.0.1" 11 | java.sourceCompatibility = JavaVersion.VERSION_17 12 | java.targetCompatibility = JavaVersion.VERSION_17 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | extra["springCloudVersion"] = "2022.0.1" 19 | 20 | dependencies { 21 | implementation("org.springframework.boot:spring-boot-starter-web") 22 | implementation("org.springframework.cloud:spring-cloud-starter-config") 23 | implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client") 24 | implementation("org.springframework.cloud:spring-cloud-starter-bootstrap") 25 | 26 | compileOnly(lombok) 27 | annotationProcessor(lombok) 28 | } 29 | 30 | dependencyManagement { 31 | imports { 32 | mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}") 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cars-service/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "cars-service" 2 | -------------------------------------------------------------------------------- /cars-service/src/main/java/com/rd/spring/cars/CarServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.cars; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CarServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CarServiceApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /cars-service/src/main/java/com/rd/spring/cars/controllers/CarController.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.cars.controllers; 2 | 3 | import com.rd.spring.cars.model.CarResponse; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @RestController 12 | @RequestMapping(value = "/cars") 13 | public class CarController { 14 | 15 | @GetMapping 16 | public ResponseEntity> getCars() { 17 | List cars = new ArrayList<>(); 18 | cars.add(new CarResponse("1", "Audi")); 19 | return ResponseEntity.ok(cars); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /cars-service/src/main/java/com/rd/spring/cars/model/CarResponse.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.cars.model; 2 | 3 | import lombok.Getter; 4 | import lombok.RequiredArgsConstructor; 5 | 6 | @Getter 7 | @RequiredArgsConstructor 8 | public class CarResponse { 9 | 10 | private final String carId; 11 | private final String carName; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /cars-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9001 3 | 4 | spring: 5 | application: 6 | name: cars-service 7 | -------------------------------------------------------------------------------- /cars-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | enabled: true 5 | uri: http://localhost:9296 6 | -------------------------------------------------------------------------------- /cdk/.gitignore: -------------------------------------------------------------------------------- 1 | *.js 2 | !jest.config.js 3 | *.d.ts 4 | node_modules 5 | 6 | # CDK asset staging directory 7 | .cdk.staging 8 | cdk.out 9 | -------------------------------------------------------------------------------- /cdk/.npmignore: -------------------------------------------------------------------------------- 1 | *.ts 2 | !*.d.ts 3 | 4 | # CDK asset staging directory 5 | .cdk.staging 6 | cdk.out 7 | -------------------------------------------------------------------------------- /cdk/README.md: -------------------------------------------------------------------------------- 1 | # Welcome to your CDK TypeScript project 2 | 3 | This is a blank project for CDK development with TypeScript. 4 | 5 | The `cdk.json` file tells the CDK Toolkit how to execute your app. 6 | 7 | ## Useful commands 8 | 9 | * `npm run build` compile typescript to js 10 | * `npm run watch` watch for changes and compile 11 | * `npm run test` perform the jest unit tests 12 | * `cdk deploy` deploy this stack to your default AWS account/region 13 | * `cdk diff` compare deployed stack with current state 14 | * `cdk synth` emits the synthesized CloudFormation template 15 | -------------------------------------------------------------------------------- /cdk/bin/cdk.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import 'source-map-support/register'; 3 | import * as cdk from 'aws-cdk-lib'; 4 | import { CdkStack } from '../lib/cdk-stack'; 5 | 6 | const app = new cdk.App(); 7 | new CdkStack(app, 'CdkStack', { 8 | /* If you don't specify 'env', this stack will be environment-agnostic. 9 | * Account/Region-dependent features and context lookups will not work, 10 | * but a single synthesized template can be deployed anywhere. */ 11 | 12 | /* Uncomment the next line to specialize this stack for the AWS Account 13 | * and Region that are implied by the current CLI configuration. */ 14 | // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }, 15 | 16 | /* Uncomment the next line if you know exactly what Account and Region you 17 | * want to deploy the stack to. */ 18 | // env: { account: '123456789012', region: 'us-east-1' }, 19 | 20 | /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ 21 | }); -------------------------------------------------------------------------------- /cdk/bin/ecr-cdk.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import * as cdk from 'aws-cdk-lib'; 3 | import 'source-map-support/register'; 4 | import { EcrStack } from '../lib/ecr-stack'; 5 | 6 | const app = new cdk.App(); 7 | new EcrStack(app, 'ecr-stack', {}); 8 | -------------------------------------------------------------------------------- /cdk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.gradle.node.npm.task.NpxTask 2 | 3 | plugins { 4 | id("com.github.node-gradle.node") version "3.1.1" 5 | } 6 | 7 | group = "com.rd.spring" 8 | version = "1.0-SNAPSHOT" 9 | 10 | node { 11 | version.set("16.17.0") 12 | npmVersion.set("8.15.0") 13 | download.set(true) 14 | npmInstallCommand.set("ci") 15 | } 16 | 17 | task("build") { 18 | dependsOn("npmInstall") 19 | description = "Build CDK" 20 | command.set("npm") 21 | args.set(listOf("run", "build")) 22 | } 23 | 24 | task("deployEcr") { 25 | dependsOn("npmInstall") 26 | description = "Deploy ECR Repositories" 27 | command.set("npm") 28 | args.set(listOf("run", "cdk", "--", "--app", "npx ts-node --prefer-ts-exts bin/ecr-cdk.ts", "deploy", "ecr-stack")) 29 | } 30 | 31 | task("destroyEcr") { 32 | dependsOn("npmInstall") 33 | description = "Destroy ECR Repositories" 34 | command.set("npm") 35 | args.set(listOf("run", "cdk", "--", "--app", "npx ts-node --prefer-ts-exts bin/ecr-cdk.ts", "destroy", "ecr-stack")) 36 | } 37 | -------------------------------------------------------------------------------- /cdk/cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "npx ts-node --prefer-ts-exts bin/cdk.ts", 3 | "requireApproval": "never", 4 | "watch": { 5 | "include": [ 6 | "**" 7 | ], 8 | "exclude": [ 9 | "README.md", 10 | "cdk*.json", 11 | "**/*.d.ts", 12 | "**/*.js", 13 | "tsconfig.json", 14 | "package*.json", 15 | "yarn.lock", 16 | "node_modules", 17 | "test" 18 | ] 19 | }, 20 | "context": { 21 | "@aws-cdk/aws-lambda:recognizeLayerVersion": true, 22 | "@aws-cdk/core:checkSecretUsage": true, 23 | "@aws-cdk/core:target-partitions": [ 24 | "aws", 25 | "aws-cn" 26 | ], 27 | "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, 28 | "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, 29 | "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, 30 | "@aws-cdk/aws-iam:minimizePolicies": true, 31 | "@aws-cdk/core:validateSnapshotRemovalPolicy": true, 32 | "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, 33 | "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, 34 | "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, 35 | "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, 36 | "@aws-cdk/core:enablePartitionLiterals": true, 37 | "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, 38 | "@aws-cdk/aws-iam:standardizedServicePrincipals": true, 39 | "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, 40 | "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, 41 | "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, 42 | "@aws-cdk/aws-route53-patters:useCertificate": true, 43 | "@aws-cdk/customresources:installLatestAwsSdkDefault": false, 44 | "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, 45 | "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, 46 | "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, 47 | "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, 48 | "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true, 49 | "@aws-cdk/aws-redshift:columnId": true 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cdk/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: 'node', 3 | roots: ['/test'], 4 | testMatch: ['**/*.test.ts'], 5 | transform: { 6 | '^.+\\.tsx?$': 'ts-jest' 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /cdk/lib/cdk-stack.ts: -------------------------------------------------------------------------------- 1 | import * as cdk from 'aws-cdk-lib'; 2 | import { Construct } from 'constructs'; 3 | // import * as sqs from 'aws-cdk-lib/aws-sqs'; 4 | 5 | export class CdkStack extends cdk.Stack { 6 | constructor(scope: Construct, id: string, props?: cdk.StackProps) { 7 | super(scope, id, props); 8 | 9 | // The code that defines your stack goes here 10 | 11 | // example resource 12 | // const queue = new sqs.Queue(this, 'CdkQueue', { 13 | // visibilityTimeout: cdk.Duration.seconds(300) 14 | // }); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cdk/lib/ecr-stack.ts: -------------------------------------------------------------------------------- 1 | import * as cdk from 'aws-cdk-lib'; 2 | import { Repository } from 'aws-cdk-lib/aws-ecr'; 3 | import { Construct } from 'constructs'; 4 | 5 | export class EcrStack extends cdk.Stack { 6 | constructor(scope: Construct, id: string, props?: cdk.StackProps) { 7 | super(scope, id, props); 8 | 9 | new Repository(this, 'gateway-service', { 10 | repositoryName: 'spring-cloud-security-jwt-gateway-service' 11 | }); 12 | 13 | new Repository(this, 'config-service', { 14 | repositoryName: 'spring-cloud-security-jwt-config-service' 15 | }); 16 | 17 | new Repository(this, 'discovery-service', { 18 | repositoryName: 'spring-cloud-security-jwt-discovery-service' 19 | }); 20 | 21 | new Repository(this, 'cars-service', { 22 | repositoryName: 'spring-cloud-security-jwt-cars-service' 23 | }); 24 | 25 | new Repository(this, 'auth-service', { 26 | repositoryName: 'spring-cloud-security-jwt-auth-service' 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cdk/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cdk", 3 | "version": "0.1.0", 4 | "bin": { 5 | "cdk": "bin/cdk.js" 6 | }, 7 | "scripts": { 8 | "build": "tsc", 9 | "watch": "tsc -w", 10 | "test": "jest", 11 | "cdk": "cdk" 12 | }, 13 | "devDependencies": { 14 | "@types/jest": "^29.4.0", 15 | "@types/node": "18.14.6", 16 | "jest": "^29.5.0", 17 | "ts-jest": "^29.0.5", 18 | "aws-cdk": "2.69.0", 19 | "ts-node": "^10.9.1", 20 | "typescript": "~4.9.5" 21 | }, 22 | "dependencies": { 23 | "aws-cdk-lib": "2.69.0", 24 | "constructs": "^10.0.0", 25 | "source-map-support": "^0.5.21" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cdk/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "cdk" 2 | -------------------------------------------------------------------------------- /cdk/test/cdk.test.ts: -------------------------------------------------------------------------------- 1 | // import * as cdk from 'aws-cdk-lib'; 2 | // import { Template } from 'aws-cdk-lib/assertions'; 3 | // import * as Cdk from '../lib/cdk-stack'; 4 | 5 | // example test. To run these tests, uncomment this file along with the 6 | // example resource in lib/cdk-stack.ts 7 | test('SQS Queue Created', () => { 8 | // const app = new cdk.App(); 9 | // // WHEN 10 | // const stack = new Cdk.CdkStack(app, 'MyTestStack'); 11 | // // THEN 12 | // const template = Template.fromStack(stack); 13 | 14 | // template.hasResourceProperties('AWS::SQS::Queue', { 15 | // VisibilityTimeout: 300 16 | // }); 17 | }); 18 | -------------------------------------------------------------------------------- /cdk/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "module": "commonjs", 5 | "lib": [ 6 | "es2020" 7 | ], 8 | "declaration": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "noImplicitThis": true, 13 | "alwaysStrict": true, 14 | "noUnusedLocals": false, 15 | "noUnusedParameters": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": false, 18 | "inlineSourceMap": true, 19 | "inlineSources": true, 20 | "experimentalDecorators": true, 21 | "strictPropertyInitialization": false, 22 | "typeRoots": [ 23 | "./node_modules/@types" 24 | ] 25 | }, 26 | "exclude": [ 27 | "node_modules", 28 | "cdk.out" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /config-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17 2 | MAINTAINER Rajith Delantha 3 | 4 | COPY build/libs/config-service-0.0.1.jar /app/ 5 | CMD ["java", "-Xmx200m", "-jar", "/app/config-service-0.0.1.jar"] 6 | 7 | EXPOSE 9297 8 | -------------------------------------------------------------------------------- /config-service/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.rd.spring.dependencies.Dependencies.eurekaClient 2 | import com.rd.spring.dependencies.Dependencies.gson 3 | import com.rd.spring.dependencies.Dependencies.springBootConfigServer 4 | 5 | plugins { 6 | java 7 | id("org.springframework.boot") version "3.0.5" 8 | } 9 | 10 | group = "com.rd.spring" 11 | version = "0.0.1" 12 | java.sourceCompatibility = JavaVersion.VERSION_17 13 | java.targetCompatibility = JavaVersion.VERSION_17 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | implementation(springBootConfigServer) 21 | implementation(eurekaClient) 22 | 23 | implementation(gson) 24 | } 25 | -------------------------------------------------------------------------------- /config-service/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "discovery-service" 2 | -------------------------------------------------------------------------------- /config-service/src/main/java/com/rd/spring/config/ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | @EnableConfigServer 11 | public class ConfigApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ConfigApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /config-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9297 3 | 4 | spring: 5 | application: 6 | name: config-server 7 | cloud: 8 | config: 9 | server: 10 | git: 11 | uri: https://github.com/rajithd/spring-cloud-security-config-server.git 12 | clone-on-start: true 13 | default-label: main 14 | -------------------------------------------------------------------------------- /config-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | enabled: true 5 | uri: http://localhost:9296 6 | -------------------------------------------------------------------------------- /discovery-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17 2 | MAINTAINER Rajith Delantha 3 | 4 | COPY build/libs/discovery-service-0.0.1.jar /app/ 5 | CMD ["java", "-Xmx200m", "-jar", "/app/discovery-service-0.0.1.jar"] 6 | 7 | EXPOSE 8761 8 | -------------------------------------------------------------------------------- /discovery-service/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.rd.spring.dependencies.Dependencies.eurekaServer 2 | import com.rd.spring.dependencies.Dependencies.gson 3 | import com.rd.spring.dependencies.Dependencies.javaxServlet 4 | 5 | plugins { 6 | java 7 | id("org.springframework.boot") version "3.0.5" 8 | } 9 | 10 | group = "com.rd.spring" 11 | version = "0.0.1" 12 | java.sourceCompatibility = JavaVersion.VERSION_17 13 | java.targetCompatibility = JavaVersion.VERSION_17 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | implementation(eurekaServer) 21 | implementation(javaxServlet) 22 | implementation(gson) 23 | } 24 | -------------------------------------------------------------------------------- /discovery-service/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "discovery-service" 2 | -------------------------------------------------------------------------------- /discovery-service/src/main/java/com/rd/spring/discovery/DiscoveryApplication.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.discovery; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class DiscoveryApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DiscoveryApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /discovery-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | client: 6 | register-with-eureka: false 7 | fetch-registry: false 8 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajithd/spring-cloud-security-jwt/b4c1c2ac98d7b6c7a3fdbbb388888c89784811c3/docker-compose.yml -------------------------------------------------------------------------------- /docs/images/microservices-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajithd/spring-cloud-security-jwt/b4c1c2ac98d7b6c7a3fdbbb388888c89784811c3/docs/images/microservices-architecture.png -------------------------------------------------------------------------------- /gateway-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17 2 | MAINTAINER Rajith Delantha 3 | 4 | COPY build/libs/gateway-service-0.0.1.jar /app/ 5 | CMD ["java", "-Xmx200m", "-jar", "/app/gateway-service-0.0.1.jar"] 6 | 7 | EXPOSE 8080 8 | -------------------------------------------------------------------------------- /gateway-service/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.rd.spring.dependencies.Dependencies.eurekaClient 2 | import com.rd.spring.dependencies.Dependencies.lombok 3 | 4 | plugins { 5 | java 6 | id("org.springframework.boot") version "3.0.5" 7 | } 8 | 9 | group = "com.rd.spring" 10 | version = "0.0.1" 11 | java.sourceCompatibility = JavaVersion.VERSION_17 12 | java.targetCompatibility = JavaVersion.VERSION_17 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | implementation("org.springframework.cloud:spring-cloud-starter-gateway:3.0.5") 20 | implementation("org.springframework.cloud:spring-cloud-starter-netflix-hystrix:2.2.10.RELEASE") 21 | implementation(eurekaClient) 22 | 23 | implementation("com.google.code.gson:gson:2.8.2") 24 | implementation("io.jsonwebtoken:jjwt-api:0.11.1") 25 | implementation("io.jsonwebtoken:jjwt-impl:0.11.1") 26 | implementation("io.jsonwebtoken:jjwt-jackson:0.11.1") 27 | 28 | compileOnly(lombok) 29 | annotationProcessor(lombok) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /gateway-service/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "gateway-service" 2 | -------------------------------------------------------------------------------- /gateway-service/src/main/java/com/rd/spring/gateway/GatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class GatewayApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(GatewayApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /gateway-service/src/main/java/com/rd/spring/gateway/config/AuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.gateway.config; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.cloud.gateway.filter.GatewayFilter; 7 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.server.reactive.ServerHttpRequest; 10 | import org.springframework.http.server.reactive.ServerHttpResponse; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.web.server.ServerWebExchange; 13 | import reactor.core.publisher.Mono; 14 | 15 | @RefreshScope 16 | @Component 17 | public class AuthenticationFilter implements GatewayFilter { 18 | 19 | private final RouterValidator routerValidator; 20 | private final JwtUtil jwtUtil; 21 | 22 | @Autowired 23 | public AuthenticationFilter(RouterValidator routerValidator, JwtUtil jwtUtil) { 24 | this.routerValidator = routerValidator; 25 | this.jwtUtil = jwtUtil; 26 | } 27 | 28 | @Override 29 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 30 | ServerHttpRequest request = exchange.getRequest(); 31 | 32 | if (routerValidator.isSecured.test(request)) { 33 | if (this.isAuthMissing(request)) { 34 | return this.onError(exchange, HttpStatus.UNAUTHORIZED); 35 | } 36 | 37 | final String token = this.getAuthHeader(request); 38 | 39 | if (jwtUtil.isInvalid(token)) { 40 | return this.onError(exchange, HttpStatus.FORBIDDEN); 41 | } 42 | 43 | this.updateRequest(exchange, token); 44 | } 45 | return chain.filter(exchange); 46 | } 47 | 48 | private Mono onError(ServerWebExchange exchange, HttpStatus httpStatus) { 49 | ServerHttpResponse response = exchange.getResponse(); 50 | response.setStatusCode(httpStatus); 51 | return response.setComplete(); 52 | } 53 | 54 | private String getAuthHeader(ServerHttpRequest request) { 55 | return request.getHeaders().getOrEmpty("Authorization").get(0); 56 | } 57 | 58 | private boolean isAuthMissing(ServerHttpRequest request) { 59 | return !request.getHeaders().containsKey("Authorization"); 60 | } 61 | 62 | private void updateRequest(ServerWebExchange exchange, String token) { 63 | Claims claims = jwtUtil.getAllClaimsFromToken(token); 64 | exchange.getRequest().mutate() 65 | .header("email", String.valueOf(claims.get("email"))) 66 | .build(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /gateway-service/src/main/java/com/rd/spring/gateway/config/GatewayConfig.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.gateway.config; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import org.springframework.cloud.gateway.route.RouteLocator; 5 | import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; 6 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | @EnableHystrix 12 | @RequiredArgsConstructor 13 | public class GatewayConfig { 14 | 15 | private final AuthenticationFilter filter; 16 | 17 | @Bean 18 | public RouteLocator routes(RouteLocatorBuilder builder) { 19 | return builder.routes() 20 | .route("cars-service", r -> r.path("/cars/**") 21 | .filters(f -> f.filter(filter)) 22 | .uri("lb://cars-service")) 23 | 24 | .route("auth-service", r -> r.path("/auth/**") 25 | .filters(f -> f.filter(filter)) 26 | .uri("lb://auth-service")) 27 | .build(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /gateway-service/src/main/java/com/rd/spring/gateway/config/JwtUtil.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.gateway.config; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import io.jsonwebtoken.Jwts; 5 | import io.jsonwebtoken.security.Keys; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.PostConstruct; 10 | import java.security.Key; 11 | import java.util.Date; 12 | 13 | @Component 14 | public class JwtUtil { 15 | 16 | @Value("${jwt.secret}") 17 | private String secret; 18 | 19 | private Key key; 20 | 21 | @PostConstruct 22 | public void init(){ 23 | this.key = Keys.hmacShaKeyFor(secret.getBytes()); 24 | } 25 | 26 | public Claims getAllClaimsFromToken(String token) { 27 | return Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token).getBody(); 28 | } 29 | 30 | private boolean isTokenExpired(String token) { 31 | return this.getAllClaimsFromToken(token).getExpiration().before(new Date()); 32 | } 33 | 34 | public boolean isInvalid(String token) { 35 | return this.isTokenExpired(token); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /gateway-service/src/main/java/com/rd/spring/gateway/config/RouterValidator.java: -------------------------------------------------------------------------------- 1 | package com.rd.spring.gateway.config; 2 | 3 | import org.springframework.http.server.reactive.ServerHttpRequest; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.List; 7 | import java.util.function.Predicate; 8 | 9 | @Component 10 | public class RouterValidator { 11 | 12 | public static final List openApiEndpoints = List.of( 13 | "/auth/register" 14 | ); 15 | 16 | public Predicate isSecured = 17 | request -> openApiEndpoints 18 | .stream() 19 | .noneMatch(uri -> request.getURI().getPath().contains(uri)); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /gateway-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | spring: 5 | application: 6 | name: api-gateway 7 | cloud: 8 | gateway: 9 | discovery: 10 | locator: 11 | enabled: true 12 | 13 | jwt: 14 | secret: AvHGRK8C0ia4uOuxxqPD5DTbWC9F9TWvPStp3pb7ARo0oK2mJ3pd3YG4lxA9i8bj6OTbadweheufHNyG 15 | -------------------------------------------------------------------------------- /gateway-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | enabled: true 5 | uri: http://localhost:9296 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajithd/spring-cloud-security-jwt/b4c1c2ac98d7b6c7a3fdbbb388888c89784811c3/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "spring-cloud-security-jwt" 2 | include(":config-service") 3 | include(":auth-service") 4 | include(":gateway-service") 5 | include(":discovery-service") 6 | include(":cars-service") 7 | include(":cdk") 8 | 9 | project(":auth-service").projectDir = file("auth-service") 10 | project(":config-service").projectDir = file("config-service") 11 | project(":gateway-service").projectDir = file("gateway-service") 12 | project(":discovery-service").projectDir = file("discovery-service") 13 | project(":cars-service").projectDir = file("cars-service") 14 | project(":cdk").projectDir = file("cdk") 15 | 16 | pluginManagement { 17 | repositories { 18 | mavenCentral() 19 | gradlePluginPortal() 20 | maven { url = uri("https://repo.spring.io/release") } 21 | maven { url = uri("https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates") } 22 | } 23 | } 24 | --------------------------------------------------------------------------------