https://github.com/shimbhu77/greenstitch_assignment
This backend project implements a secure login and signup REST API using Java, Spring Boot, and H2 database. It includes endpoints for user registration, authentication, and retrieving user details with JWT tokens.
https://github.com/shimbhu77/greenstitch_assignment
h2-database hibernate java jwt-token lombok maven spring-boot spring-security springdata-jpa swagger-ui
Last synced: about 1 month ago
JSON representation
This backend project implements a secure login and signup REST API using Java, Spring Boot, and H2 database. It includes endpoints for user registration, authentication, and retrieving user details with JWT tokens.
- Host: GitHub
- URL: https://github.com/shimbhu77/greenstitch_assignment
- Owner: Shimbhu77
- Created: 2023-07-06T12:26:28.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-06T15:13:47.000Z (almost 3 years ago)
- Last Synced: 2025-07-04T17:48:42.933Z (12 months ago)
- Topics: h2-database, hibernate, java, jwt-token, lombok, maven, spring-boot, spring-security, springdata-jpa, swagger-ui
- Language: Java
- Homepage: http://localhost:8888/
- Size: 71.3 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GreenStitch Assignment
# Login and Signup Backend API with Spring Security and JWT Tokens
This project is a backend implementation of a login and signup REST API with security and JWT tokens. It is built using Java, and Spring Boot, and utilizes the H2 database for data storage. The API endpoints provided below demonstrate the functionality of the application.
## Installation and Setup
```
### Prerequisites
- Java Development Kit (JDK) 8 or later
- Maven
- Postman (for testing the API)
```
### 1. Clone the Repository
```
git clone https://github.com/Shimbhu77/GreenStitch_Assignment.git
```
### 2. Go the Project
```
cd GreenStitch_Assignment/GreenStitch_Assignment
```
### 3. Run the Application
- For GitBash
```
./mvnw spring-boot:run
```
**The application will start running on [http://localhost:8888](http://localhost:8888)**
### **API Endpoints**
### User Signup
- Method: POST
- Path: `http://localhost:8888/app/sign-up`
- Description: Register a new user.
- Request Body: User data in the JSON format (e.g., name, email, password).
```
{
"fullName": "Shimbhu Kumawat",
"password": "Shimbhu@123",
"email": "sk@gmail.com"
}
```
- Response:
```
{
"id": 1,
"fullName": "Shimbhu Kumawat",
"password": "$2a$10$KVzpEHKFpX2ephA7RXLgqumnZKFy3bT8wdJMW3tYH2yqUJcpZPGSG",
"email": "sk@gmail.com",
"role": "ROLE_USER"
}
```
### User Login
- Method: GET
- Path: `http://localhost:8888/app/sign-in`
- Description: Authenticate a user and retrieve their details and JWT token.
- Authentication: Basic Authentication (Username and Password)
- Username: [sk@gmail.com](mailto:sk@gmail.com)
- Password: Shimbhu@123
- Response:
```
{
"id": 1,
"fullName": "Shimbhu Kumawat",
"password": "$2a$10$KVzpEHKFpX2ephA7RXLgqumnZKFy3bT8wdJMW3tYH2yqUJcpZPGSG",
"email": "sk@gmail.com",
"role": "ROLE_USER"
}
```
### Welcome Endpoint (Requires Authentication)
- Method: GET
- Path: `http://localhost:8888/app/logged-in/user`
- Description: A protected endpoint that requires authentication to access.
- Authentication: Bearer Token
- Request Header:
- Authorization: Bearer
- Response: A welcome message string.
- Example:
- Bearer Token: eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJTaGltYmh1Iiwic3ViIjoiSldUIFRva2VuIiwidXNlcm5hbWUiOiJza0BnbWFpbC5jb20iLCJyb2xlIjoiUk9MRV9VU0VSIiwiaWF0IjoxNjg1Njc3Mzg3LCJleHAiOjE2ODU3MDczODd9.VwM2IGD1fABjEcnNoMb4uIyBnYe3_BmZGx33dElaD-E
- Response: Welcome to Shimbhu's Website: Shimbhu Kumawat
### Tech Stack
- Java
- Spring Boot
- H2 Database
- Spring Security
- JWT Token
- Lombok
- Maven
- Swagger-UI
### Validation Rules
The following validation rules are applied to the user entity:
- Full Name:
- Minimum length: 3 characters
- Maximum length: 20 characters
- Password:
- At least 8 characters
- Contains at least one digit
- Contains at least one lowercase letter
- Contains at least one uppercase letter
- Contains at least one special character
- Email:
- Valid email format
### Development
The project can be imported and run using an IDE like Eclipse.
### Test API
You can use Postman and Swagger-UI to test the API endpoints.
## H2 Database Configuration
The project uses the H2 in-memory database by default.
The application is configured to use the H2 database. The configuration can be found in the `application.properties` file:
```
# Server Port Configuration
server.port=8888
# H2 Database Configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
```
## **Contributors**
- **[Shimbhu Kumawat](https://github.com/Shimbhu77)**