Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sandundil2002/jwt-authentication

This project is demonstrates how to implement JWT (JSON Web Token) based authentication in springboot.
https://github.com/sandundil2002/jwt-authentication

ajax bootstrap css html java javascript jpa jquery jwt-authentication maven mysql spring-boot

Last synced: 2 days ago
JSON representation

This project is demonstrates how to implement JWT (JSON Web Token) based authentication in springboot.

Awesome Lists containing this project

README

        

Typing SVG

This project demonstrates a comprehensive implementation of JWT (JSON Web Token) based authentication in a Spring Boot application. The project is structured with multiple components to handle various aspects of the application, ensuring clean and maintainable code.

Project Structure

* Entity: Defines the data model and maps it to the database.
* DTO (Data Transfer Object): Facilitates the transfer of data between different layers of the application.
* Repository: Handles all database operations and data persistence.
* Service: Contains the business logic and interacts with the Repository layer.
* Config: Configures security settings, including JWT authentication and authorization.
* Controller: Manages incoming HTTP requests, processes them, and returns appropriate responses.
* Util: Contains utility classes for various operations, particularly for handling JWT tokens.

Features

* JWT Generation: Generates JWT tokens upon successful authentication, which are then used for securing subsequent requests.
* User Authentication: Validates user credentials and issues JWT tokens, ensuring secure access to protected resources.

Technologies Used

* Spring Boot: Framework to create standalone, production-grade Spring-based applications.
* Spring Security: Provides authentication and authorization support, securing the application.
* JSON Web Token (JWT): Mechanism for securely transmitting information between parties as a JSON object.
* JPA/Hibernate: ORM (Object Relational Mapping) framework to interact with the database.
* MySQL (or any other database): Relational database for storing application data.
* Maven: Build automation tool for managing project dependencies.

Getting Started


Prerequisites

* JDK 17 or later: Ensure that your system is running Java Development Kit 17 or a later version.
* Maven 3.6 or later: Maven is required to manage dependencies and build the project.
* MySQL (or any other database): A database to store application data.
* IDE: Use an Integrated Development Environment like IntelliJ IDEA or Eclipse for development.

Installation and Setup


Clone the Repository:

git clone https://github.com/sandundil2002/JWT-Authentication.git
cd JWT-Authentication

Configure the Database:

* Update the application.properties file with your database connection details.

spring.application.name=JWT-Authentication
spring.datasource.url = jdbc:mysql://localhost:3306/yourDatabaseName?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=yourDatabaseUsername
spring.datasource.password = yourDatabasePassword
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto = update
spring.datasource.driver-class-name =com.mysql.cj.jdbc.Driver
spring.jpa.open-in-view=false
spring.jpa.show-sql= true
jwt.secret=e#s$p%o$r^t9

Build the Project:

mvn clean install

Run the Application:

mvn spring-boot:run

Access the Application:

* The application will be available at http://localhost:8080.

API Documentation

You can view and interact with the API using Postman. Detailed documentation for all endpoints, including request formats and expected responses, is available via the following link:

Postman API Documentation