Skip to content

Commit 4b8d6ca

Browse files
committed
git: to new branch
Signed-off-by: Akash Jaiswal <akashjaiswal3846@gmail.com>
1 parent a908989 commit 4b8d6ca

12 files changed

Lines changed: 808 additions & 0 deletions

File tree

spring-boot-jwt/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip

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": "akash@example.com",
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)