Skip to content

Spring Boot Microservices with JWT (Eureka Server, API Gateway, Auth Service, User Service and Product Service, JUnit and Integration Tests, Docker, Github Actions)

Notifications You must be signed in to change notification settings

Rapter1990/springbootmicroserviceswithsecurity

Repository files navigation

Spring Boot Microservices with JWT Implementation

Main Information

📖 Information

  • This project demonstrates a Spring Boot microservices architecture with JWT-based authentication and role-based access control. The setup includes an API Gateway to manage routing and authentication.
  • Roles and Permissions:
    • Admin and User roles each have their own authentication and authorization mechanisms defined by their roles.
    • Admin can:
      • Create products
      • Retrieve all products
      • Retrieve products by ID
      • Update products by ID
      • Delete products by ID
    • User can:
      • Retrieve all products
      • Retrieve products by ID

Explore Rest APIs

Method Url Description Request Body Header Valid Path Variable No Path Variable
POST /api/v1/authentication/admin/register Admin Register AdminRegisterRequest
POST /api/v1/authentication/admin/login Admin Login LoginRequest
POST /api/v1/authentication/admin/refreshtoken Admin Refresh Token TokenRefreshRequest
POST /api/v1/authentication/admin/logout Admin Logout TokenInvalidateRequest
POST /api/v1/authentication/user/register User Register UserRegisterRequest
POST /api/v1/authentication/user/login User Login LoginRequest
POST /api/v1/authentication/user/refreshtoken User Refresh Token TokenRefreshRequest
POST /api/v1/authentication/user/logout User Logout TokenInvalidateRequest
POST /api/v1/products Create Product ProductCreateRequest
GET /api/v1/products/{productId} Get Product By Id ProductId
GET /api/v1/products Get Products ProductPagingRequest
PUT /api/v1/products/{productId} Update Product By Id ProductUpdateRequest ProductId
DELETE /api/v1/products/{productId} Delete Product By Id ProductId

Technologies


  • Java 21
  • Spring Boot 3.0
  • Restful API
  • Lombok
  • Maven
  • Junit5
  • Mockito
  • Integration Tests
  • Docker
  • Docker Compose
  • CI/CD (Github Actions)
  • Spring Cloud
  • Postman
  • Spring Security
  • JWT

Postman

Import postman collection under postman_collection folder

Prerequisites

Define Variable in .env file for product service and user service

DATABASE_USERNAME={DATABASE_USERNAME}
DATABASE_PASSWORD={DATABASE_PASSWORD}

  • Maven or Docker

Docker Run

The application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.

Please follow directions shown below in order to build and run the application with Docker Compose file;

$ cd springbootmicroserviceswithsecurity
$ docker-compose up -d

If you change anything in the project and run it on Docker, you can also use this command shown below

$ cd springbootmicroserviceswithsecurity
$ docker-compose up --build

Maven Run

To build and run the application with Maven, please follow the directions shown below;

$ cd springbootmicroserviceswithsecurity
$ cd eurekaserver
$ mvn clean install
$ mvn spring-boot:run
$ cd ..
$ cd apigateway
$ mvn clean install
$ mvn spring-boot:run
$ cd ..
$ cd authservice
$ mvn clean install
$ mvn spring-boot:run
$ cd ..
$ cd userservice
$ mvn clean install
$ mvn spring-boot:run
$ cd ..
$ cd productservice
$ mvn clean install
$ mvn spring-boot:run

Docker Image Location

https://hub.docker.com/repository/docker/noyandocker/springbootmicroserviceswithsecurityeurekaserver/general
https://hub.docker.com/repository/docker/noyandocker/springbootmicroserviceswithsecurityapigateway/general
https://hub.docker.com/repository/docker/noyandocker/springbootmicroserviceswithsecurityauthservice/general
https://hub.docker.com/repository/docker/noyandocker/springbootmicroserviceswithsecurityuserservice/general
https://hub.docker.com/repository/docker/noyandocker/springbootmicroserviceswithsecurityproductservice/general

Screenshots

Click here to show the screenshots of project

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

Figure 12

Figure 13

Figure 14

Figure 15

Figure 16

Contributors

Releases

No releases published

Packages

No packages published