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

https://github.com/devang-sharma609/spring_security

Spring security using JWT Tokens, with Google and GitHub Authentication
https://github.com/devang-sharma609/spring_security

java spring spring-security springboot

Last synced: 11 months ago
JSON representation

Spring security using JWT Tokens, with Google and GitHub Authentication

Awesome Lists containing this project

README

          

# Spring Security Project 🚀

Welcome to the **Spring Security Project**! This repository demonstrates the implementation of **Spring Security** for securing Java-based applications. It shows how to configure authentication, authorization, and other security measures to protect web applications from unauthorized access.

## Table of Contents 🗂️
- [Introduction](#introduction)
- [Features](#features)
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Contributing](#contributing)
- [License](#license)

## Introduction 🎯
Spring Security is a powerful and customizable authentication and access control framework for Java applications. This project serves as a guide to help developers integrate **Spring Security** into their applications with a focus on security best practices, such as:
- Authentication (basic and JWT token-based)
- Authorization (role-based access control)
- CSRF protection
- Session management
- Secure password hashing

The goal of this project is to provide developers with a **working example** of how to integrate Spring Security with their own applications and enable strong security measures.

## Features ✨
- **Authentication**: Secure login and token-based authentication (JWT).
- **Authorization**: Role-based access control with custom permission rules.
- **CSRF Protection**: Built-in CSRF (Cross-Site Request Forgery) prevention.
- **Password Encoding**: Secure password storage with BCrypt.
- **Custom Security Configurations**: Flexibility to configure your own authentication mechanisms.
- **Session Management**: Secure handling of user sessions and logout functionality.

## Getting Started 🚀

To get started with this project, clone this repository to your local machine and follow the steps to set up the Spring Security configuration.

### Prerequisites 🔧
- Java 11 or higher
- Maven or Gradle
- A database (optional, depending on your setup)

### Installation ⚙️
1. Clone the repository:
```bash
git clone https://github.com/Devang-sharma609/Spring_Security.git
```

2. Navigate into the project directory:
```bash
cd Spring_Security
```

3. Build the project using Maven or Gradle:
- Maven:
```bash
mvn clean install
```
- Gradle:
```bash
gradle build
```

4. Run the application:
```bash
mvn spring-boot:run
```
or
```bash
gradle bootRun
```

Now, your application should be up and running locally!

## Usage ⚡
After setting up the project, you can test authentication and authorization functionality using the following API endpoints:

- **POST** `/login`: Log in with user credentials (returns JWT token).
- **GET** `/user`: Get user info (accessible only if authenticated).
- **GET** `/admin`: Admin page (accessible only for users with `ROLE_ADMIN`).

You can customize these endpoints or add more depending on your application’s needs.

## Configuration ⚙️

This repository provides a flexible configuration file (`application.properties` or `application.yml`) for managing different Spring Security properties. You can configure:

- JWT token secret and expiration time.
- Roles and access rules.
- Login and logout behavior.
- Session settings and CSRF configurations.

### Example `application.properties`:

```properties
# JWT Configuration
jwt.secret=your_jwt_secret_key
jwt.expiration=3600000

# Spring Security Settings
spring.security.user.name=user
spring.security.user.password=secretpassword
spring.security.roles=USER,ADMIN
```

Make sure to modify the configuration according to your environment.

## Contributing 🤝
We welcome contributions to this project! If you’d like to contribute, please follow these steps:

1. Fork the repository.
2. Create a feature branch.
3. Commit your changes.
4. Open a pull request with a description of what you’ve implemented or changed.

We encourage you to follow the guidelines for coding style and commit messages.

## License 📝
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Credits
I made this Spring Security Component for NavGo Project by Abhyudaya Coding Club™

## Contact
For any queries feel free to mail me at: [Email](https://mailto:devang122indmp@gmail.com)