spring-bootjpajwtmicroservicesaudit-logging

How to implement JPA Audit across different Spring Boot Microservices of a single project?


I have an AUTH_SERVICE which authenticates the user credentials and sends JWT token in response header. I also have GATEWAY_SERVICE which intercepts the request and validates the token and forwards the request to the controller of other microservices.

Now, in this process, I can't seem to figure out how to implement JPA Auditing just in case if any table data of targeted microservices is changed.

Any suggesstions?

Here's a Github link to my project

Below is a list of microservices in the project

- zuul-server (Port:8762)
- auth-server (Port: 9100)
- gallery-service (Port: 8100)
- image-service (Port: 8200)

āœ– - Now, I need to send username/token or say user_id from zuul-server to gallery-service for JPA audit purpose. Any recommendation on how do i do that?


Solution

  • As per spring docs you can send Headers from zuul to other services with the help of zuul configuration.

    Spring Docs:

    The sensitiveHeaders are a blacklist, and the default is not empty. Consequently, to make Zuul send all headers (except the ignored ones), you must explicitly set it to the empty list. Doing so is necessary if you want to pass cookie or authorization headers to your back end.

    Example:

    zuul:
      routes:
        users:
          path: /myusers/**
          sensitiveHeaders: