GitHunt
SH

Shubh2-0/Spring_Security

Welcome to the Spring Security RepositoryπŸ”, your comprehensive resource for mastering application security. Dive into a variety of projects, from traditional authentication to JWT-based role authorization. Explore CORS handling and custom authentication providers. Let's fortify your app's defenses together! πŸš€πŸ’ͺ

πŸ›‘οΈ Spring Security Learning Hub

GitHub stars
GitHub forks
GitHub issues

Spring Security

Master Application Security with Spring Security

Complete collection of authentication and authorization implementations - from basic to JWT

Explore Projects Β· Get Started Β· Learn Security


πŸ“– Table of Contents


🎯 About

This repository is your one-stop destination for mastering Spring Security. It contains multiple projects demonstrating various authentication and authorization techniques, from basic form login to JWT-based stateless authentication with role-based access control.

What You'll Master

  • πŸ” Authentication - Form login, HTTP Basic, JWT tokens
  • 🎫 Authorization - Role-based access control (RBAC)
  • πŸ”‘ JWT Integration - Stateless authentication
  • 🌐 CORS Handling - Cross-Origin Resource Sharing
  • βš™οΈ Custom Providers - Build your own authentication logic

πŸ“ Projects

Project Description Key Concepts
Spring_Security_1 Foundation project Basic security configuration
SpringSecurityAuthProviderWithoutJwt Authentication without JWT Custom auth providers
SpringSecurityJwtWithRole JWT + Role Authorization Token-based RBAC
Spring_Security_With_CustomAuthProvider Custom authentication Provider customization
SpringSecurityWithJwt JWT implementation Token generation & validation
SpringSecurityWithJwt2 Alternative JWT approach Different JWT strategies
Spring_Security_With_JWT2_And_Role JWT + Extended roles Fine-grained access
SpringSecurityWithJwtCors JWT + CORS handling Cross-domain security
SpringSecurityWithSimpleRoleJwt2 Simplified role-JWT Streamlined implementation
SpringSecurityWithoutJwt Traditional security Session-based auth
SpringSecurityWithoutJwt2 Alternative non-JWT Different session approaches

πŸ”’ Security Concepts

Authentication Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    Credentials    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Client      β”‚ ───────────────► β”‚  AuthController  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                               β–Ό
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚  AuthenticationMgr   β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                          β–Ό                  β–Ό                  β–Ό
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚UserDetailsSvcβ”‚  β”‚PasswordEncoderβ”‚  β”‚  JwtService  β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

JWT Token Structure

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      JWT TOKEN                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚     HEADER      β”‚     PAYLOAD     β”‚     SIGNATURE      β”‚
β”‚  {"alg":"HS256" β”‚  {"sub":"user"  β”‚   HMACSHA256(      β”‚
β”‚   "typ":"JWT"}  β”‚   "role":"ADMIN"β”‚   base64(header)+  β”‚
β”‚                 β”‚   "exp":1234567}β”‚   base64(payload)) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Technologies

Technology Version Purpose
17+ Programming Language
3.x Spring Boot Framework
8.0+ Database
3.6+ Build Tool
Latest API Testing

πŸš€ Getting Started

Prerequisites

  • Java JDK 17+
  • Maven 3.6+
  • MySQL Server
  • Postman (for API testing)

Quick Start

# Clone the repository
git clone https://github.com/Shubh2-0/Spring_Security.git
cd Spring_Security

# Choose a project
cd SpringSecurityJwtWithRole

# Configure database in application.properties
# Update username, password, and database name

# Run the application
mvn spring-boot:run

API Testing

# Register endpoint
POST /api/auth/register
{
  "username": "user",
  "password": "password",
  "role": "USER"
}

# Login endpoint
POST /api/auth/login
{
  "username": "user",
  "password": "password"
}

# Protected endpoint (with JWT token)
GET /api/protected
Authorization: Bearer <your-jwt-token>

πŸ“š Learning Path

πŸ”° Beginner
β”œβ”€β”€ Spring_Security_1 (Basic Config)
β”œβ”€β”€ SpringSecurityWithoutJwt (Session-based)
β”‚
πŸ”΅ Intermediate
β”œβ”€β”€ SpringSecurityAuthProviderWithoutJwt
β”œβ”€β”€ Custom Authentication Provider
β”‚
πŸ”΄ Advanced
β”œβ”€β”€ SpringSecurityWithJwt (Token-based)
β”œβ”€β”€ SpringSecurityJwtWithRole (RBAC)
β”œβ”€β”€ SpringSecurityWithJwtCors (CORS)
β”‚
πŸ† Expert
└── Build your own Security Architecture!

🀝 Contributing

Security is everyone's responsibility! Contributions welcome:

  • πŸ” Add new authentication patterns
  • πŸ“– Improve documentation
  • πŸ› Fix security vulnerabilities
  • πŸ’‘ Suggest best practices

πŸ“¬ Contact

Shubham Bhati - Java Developer

LinkedIn
Gmail
WhatsApp


⭐ Star this repository if it helped you secure your applications!

Keywords: Spring-Security JWT Authentication Authorization RBAC OAuth2 Java Spring-Boot Security API-Security Token-Based-Auth