api-gateway-service
project established by combination of the following services and features.
* api-gateway
* payment-service
* student-service
* swagger-application
* openai-service
* Spring Cloud Gateway
* SpringDoc Swagger
* Event Driven Architecture with RabbitMQ
* micrometer-tracing dependencies to track the logs
* Postman collection to test by using Postman
* Keycloak integration is completed under the payment-service
* Feign Client secure call with Keycloak integration is completed under the student-service
* MDC was added to improve logging between microservices
* Google reCAPTCHA was added to secure endpoint calls
* HCaptcha repo migration is completed under the student-service
* openai-service repo migration is completed
To get a local copy up and running please follow these simple steps.
Followings should be installed and links for how to install them.
-
Java 21 or higher How to install Java
- Set
JAVA_HOME
to 21 ->export JAVA_HOME=$(/usr/libexec/java_home -v 21)
- Set
-
Maven How to install Maven
-
Docker How to install Docker
-
Run
docker-compose up -d
command in the docker-compose.yml directory or enable spring.docker.compose property and just run ApiGatewayApplication.java to install RabbitMQ, PostgreSQL and Keycloak -
Log in to http://localhost:9090/admin with
username: admin
andpassword: admin
Create realm
-> Import payment-service-realm-export.jsonClients
->payment-service
->Credentials
->Regenerate
copy the value and use this value in Postman environment variable.Users
->Add user
->Username
->payment-service-user
Users
->payment-service-user
->Credentials
->Set password
totest
and turn offTemporary
toggle.Users
->payment-service-user
->Role Mapping
->Assign role
addadmin
role- Postman should be installed, follow How to import postman collection to import files that are under the postman_collection folder
-
Google reCAPTCHA installation (OPTIONAL)
- Log in to the https://www.google.com/recaptcha/admin/create
- Fill the necessary fields.
- This url can guide you
- Copy SITE KEY and SECRET KEY and add them into related fields that are in the application.yml
- HCaptcha integration was implemented in 4 different ways in HCaptchaController.java ( OPTIONAL)
-
Create new secret key and replace all YOUR_API_KEY_HERE in code with this new key -> https://platform.openai.com/account/api-keys
-
Clone the repo
git clone https://github.com/musabbozkurt/api-gateway-service.git
-
Run Spring Boot applications
mvn clean install
ormvn clean package
mvn spring-boot:run
-
Additional information to access endpoints, swagger and actuator
-
How to run in Docker
1 - Open Docker Quickstart Terminal 2 - Go to the project directory from Docker Quickstart Terminal 3 - Create Docker image by typing the following command -> docker build -t api-gateway-service-project.jar 4 - Type the following command to make sure docker image has been created -> docker image ls 5 - Type the following command to run docker image -> docker run -p 9090:8080 api-gateway-service-project.jar
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/amazing-feature
) - Commit your Changes (
git commit -m 'Add some amazing features'
) - Push to the Branch (
git push origin feature/amazing-feature
) - Open a Pull Request
-
Musab Bozkurt - Linkedin
-
Project Link: https://github.com/musabbozkurt/api-gateway-service.git
-
Keycloak integration with Spring Boot Project
- https://www.keycloak.org/getting-started/getting-started-docker
- https://www.keycloak.org/docs/latest/securing_apps/#_spring_boot_adapter
- https://www.keycloak.org/docs/latest/server_admin/#_service_accounts
- https://huongdanjava.com/get-access-token-using-the-grant-type-resource-owner-password-credentials-of-oauth-2-0-from-keycloak.html
- https://developers.redhat.com/blog/2020/11/24/authentication-and-authorization-using-the-keycloak-rest-api#
- https://www.baeldung.com/postman-keycloak-endpoints
- https://www.programcreek.com/java-api-examples/?api=org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
- https://github.com/edwin/java-keycloak-integration
- Spring boot 3 Keycloak integration for beginners | The complete Guide
- OAuth 2.0 client credentials and JWT explained along with keycloak demo
- Secure Spring Boot Microservices with Keycloak
- Keycloak installation with docker-compose
- spring-boot-swagger-ui-keycloak
-
https://www.baeldung.com/spring-security-registration-captcha
-
https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
-
https://examples.javacodegeeks.com/using-google-captcha-with-spring-boot-application/
-
HCaptcha integration with Spring Boot Project
-
OpenAI integration with Spring Boot Project
-
API Gateway with Spring Cloud Gateway in Java
-
Swagger(OpenAPI Specification 3) Integration with Spring Cloud Gateway