Skip to content

Keploy Integration - Added sample Java application using JWT Token #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@

This repo contains the sample for [Keploy's](https://keploy.io) Java Application. Please feel free to contribute if you'd like submit a sample for another use-case or library.

>**Note** :- Issue Creation is disabled on this Repository, please visit [here](https://github.com/keploy/keploy/issues/new/choose) to submit Issue.
> **Note** :- Issue Creation is disabled on this Repository, please visit [here](https://github.com/keploy/keploy/issues/new/choose) to submit Issue.

## Java Sample Apps with Keploy

## Sample Apps with Keploy

1. [employee-manager](https://github.com/keploy/samples-java/tree/main/employee-manager)
2. [spring-boot-mongo](https://github.com/keploy/samples-java/tree/main/spring-boot-mongo)
3. [user-manager](https://github.com/keploy/samples-java/tree/main/user-manager)
4. [spring-boot-postgres-graphql](https://github.com/keploy/samples-java/tree/main/spring-boot-postgres-graphql)
1. [Employee Manager](https://github.com/keploy/samples-java/tree/main/employee-manager) - A sample Employee-Manager app to test Keploy integration capabilities using SpringBoot and PostgreSQL.
2. [Springboot MongoDB](https://github.com/keploy/samples-java/tree/main/spring-boot-mongo) - The application is built purely with Java Spring-Boot that does the complete CRUD in the MongoDB database. This CRUD Application is about managing the data of Magical Potions in the Keploy inventory.
3. [User Manager](https://github.com/keploy/samples-java/tree/main/user-manager) - A sample User-Manager app to test Keploy integration capabilities using SpringBoot and MongoDB.
4. [Springboot Postgres GraphQL](https://github.com/keploy/samples-java/tree/main/spring-boot-postgres-graphql) - This is a Spring Boot application implementing a GraphQL service to handle requests related to books and authors.
5. [Springboot PetClinic](https://github.com/keploy/samples-java/tree/main/spring-petclinic) - This is a Pet Clinic app where you can record testcases and mocks by interacting with the UI, and then test them using Keploy.

## Community Support ❤️

### 🤔 Questions?

Reach out to us. We're here to help!

[![Slack](https://img.shields.io/badge/Slack-4A154B?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/keploy/shared_invite/zt-12rfbvc01-o54cOG0X1G6eVJTuI_orSA)
[![Slack](https://img.shields.io/badge/Slack-4A154B?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/keploy/shared_invite/zt-2dno1yetd-Ec3el~tTwHYIHgGI0jPe7A)
[![LinkedIn](https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/company/keploy/)
[![YouTube](https://img.shields.io/badge/YouTube-%23FF0000.svg?style=for-the-badge&logo=YouTube&logoColor=white)](https://www.youtube.com/channel/UC6OTg7F4o0WkmNtSoob34lg)
[![Twitter](https://img.shields.io/badge/Twitter-%231DA1F2.svg?style=for-the-badge&logo=Twitter&logoColor=white)](https://twitter.com/Keployio)

### 💖 Let's Build Together!

Whether you're a newbie coder or a wizard 🧙‍♀️, your perspective is golden. Take a peek at our:

📜 [Contribution Guidelines](https://github.com/keploy/keploy/blob/main/CONTRIBUTING.md)
Expand Down
Binary file added spring-boot-jwt/.DS_Store
Binary file not shown.
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
Loading