Skip to content

Commit

Permalink
git: to new branch
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Jaiswal <akashjaiswal3846@gmail.com>
  • Loading branch information
jaiakash committed Jul 26, 2024
1 parent a908989 commit 4b8d6ca
Show file tree
Hide file tree
Showing 12 changed files with 808 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spring-boot-jwt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
19 changes: 19 additions & 0 deletions spring-boot-jwt/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip
17 changes: 17 additions & 0 deletions spring-boot-jwt/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use an official OpenJDK runtime as a parent image
FROM openjdk:22-bookworm

# Set the working directory to /app
WORKDIR /app

# Install Maven
RUN apt-get update && apt-get install -y maven

# Copy the current directory contents into the container at /app
COPY . /app/

# Expose the port the app runs on
EXPOSE 8080

# Run the application when the container launches
CMD ["/usr/share/maven/bin/mvn", "spring-boot:run"]
112 changes: 112 additions & 0 deletions spring-boot-jwt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Keploy Sample Java - JWT Token Verification and Spring Boot

This repository contains a sample project that demonstrates the integration of Keploy with JWT (JSON Web Token) authentication in a Spring Boot application.

## Prerequisites

Before getting started, make sure you have the following installed:

- Latest version of JDK
- Install [Keploy](https://keploy.io/docs/server/installation/)
- Postman for testing APIs

## Getting Started

To get started, clone the repository:

```bash
git clone https://github.com/jaiakash/samples-java.git
cd spring-boot-jwt
```

## API Endpoints

The following API endpoints are available:

#### Login

- POST `/users/login`

Authenticate a user and receive a JWT token.

Request Body:

```json
{
"username": "your_username",
"password": "your_password"
}
```

Response:

```json
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
```

#### Token Verification

- POST `/users/tokenVerification`

Verify the validity of a JWT token.

Request Body:

```json
{
"token": "your_jwt_token_here"
}
```

Response:

```json
{
"isValid": true
}
```

## Integration with Keploy

#### RECORD Mode

1. To run the application, run

```
keploy run -c "./mvnw spring-boot:run" --delay 240
```

2. To generate testcases, you can make API calls using Postman or `curl`:

- Login

```bash
curl --location --request POST 'http://localhost:8080/users/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "akash@example.com",
"password": "password"
}'
```

- Verify

```bash
curl --location --request POST 'http://localhost:8080/users/verify' \
--header 'Content-Type: application/json' \
--data-raw '{
"token": "your_jwt_token_here"
}'
```

#### TEST mode

To test the application, start Keploy in test mode. In the root directory, run the following command:

```bash
keploy test -c "./mvnw spring-boot:run" --delay 240
```

This command will run the tests and generate the report in the `Keploy/reports` directory in the current working directory.
Loading

0 comments on commit 4b8d6ca

Please sign in to comment.