Skip to content

Commit 3f2bbde

Browse files
committed
feat: added docker file and docs
1 parent e9c94ae commit 3f2bbde

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

spring-boot-jwt/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use an official OpenJDK runtime as a parent image
2+
FROM openjdk:22-bookworm
3+
4+
# Set the working directory to /app
5+
WORKDIR /app
6+
7+
# Install Maven
8+
RUN apt-get update && apt-get install -y maven
9+
10+
# Copy the current directory contents into the container at /app
11+
COPY . /app/
12+
13+
# Expose the port the app runs on
14+
EXPOSE 8080
15+
16+
# Run the application when the container launches
17+
CMD ["/usr/share/maven/bin/mvn", "spring-boot:run"]

spring-boot-jwt/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Keploy Sample Java - JWT Token Verification and Spring Boot
2+
3+
This repository contains a sample project that demonstrates the integration of Keploy with JWT (JSON Web Token) authentication in a Spring Boot application.
4+
5+
## Prerequisites
6+
7+
Before getting started, make sure you have the following installed:
8+
9+
- Latest version of JDK
10+
- Install [Keploy](https://keploy.io/docs/server/installation/)
11+
- Postman for testing APIs
12+
13+
## Getting Started
14+
15+
To get started, clone the repository:
16+
17+
```bash
18+
git clone https://github.com/jaiakash/samples-java.git
19+
cd spring-boot-jwt
20+
```
21+
22+
## API Endpoints
23+
24+
The following API endpoints are available:
25+
26+
#### Login
27+
28+
- POST `/users/login`
29+
30+
Authenticate a user and receive a JWT token.
31+
32+
Request Body:
33+
34+
```json
35+
{
36+
"username": "your_username",
37+
"password": "your_password"
38+
}
39+
```
40+
41+
Response:
42+
43+
```json
44+
{
45+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
46+
}
47+
```
48+
49+
#### Token Verification
50+
51+
- POST `/users/tokenVerification`
52+
53+
Verify the validity of a JWT token.
54+
55+
Request Body:
56+
57+
```json
58+
{
59+
"token": "your_jwt_token_here"
60+
}
61+
```
62+
63+
Response:
64+
65+
```json
66+
{
67+
"isValid": true
68+
}
69+
```
70+
71+
## Integration with Keploy
72+
73+
#### RECORD Mode
74+
75+
1. To run the application, run
76+
77+
```
78+
keploy run -c "./mvnw spring-boot:run" --delay 240
79+
```
80+
81+
2. To generate testcases, you can make API calls using Postman or `curl`:
82+
83+
- Login
84+
85+
```bash
86+
curl --location --request POST 'http://localhost:8080/users/login' \
87+
--header 'Content-Type: application/json' \
88+
--data-raw '{
89+
"username": "[email protected]",
90+
"password": "password"
91+
}'
92+
```
93+
94+
- Verify
95+
96+
```bash
97+
curl --location --request POST 'http://localhost:8080/users/verify' \
98+
--header 'Content-Type: application/json' \
99+
--data-raw '{
100+
"token": "your_jwt_token_here"
101+
}'
102+
```
103+
104+
#### TEST mode
105+
106+
To test the application, start Keploy in test mode. In the root directory, run the following command:
107+
108+
```bash
109+
keploy test -c "./mvnw spring-boot:run" --delay 240
110+
```
111+
112+
This command will run the tests and generate the report in the `Keploy/reports` directory in the current working directory.

0 commit comments

Comments
 (0)