Skip to content

Priyanka-Rode/User-Authentication-Authorization-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

User-Authentication-Authorization-System

🔐 Auth System – Spring Boot JWT Authentication

A Spring Boot Authentication & Authorization System built using JWT (JSON Web Token) and Spring Security. This project demonstrates user registration, login, role-based access control, and secure REST APIs following clean layered architecture.


🚀 Features

  • User Registration & Login
  • JWT-based Authentication
  • Role-based Authorization (USER / ADMIN)
  • Password Encryption (BCrypt)
  • Secured REST APIs
  • Global Exception Handling
  • Clean Architecture (Controller, Service, Repository)
  • MySQL / H2 compatible

🛠 Tech Stack

  • Java 17
  • Spring Boot
  • Spring Security
  • JWT (JSON Web Token)
  • Spring Data JPA (Hibernate)
  • MySQL / H2
  • Maven
  • Postman (API Testing)

📂 Project Structure

auth-system/
│
├── controller/
│   ├── AuthController.java
│   └── UserController.java
│
├── dto/
│   ├── LoginRequest.java
│   ├── RegisterRequest.java
│   └── AuthResponse.java
│
├── entity/
│   ├── User.java
│   └── Role.java
│
├── repository/
│   ├── UserRepository.java
│   └── RoleRepository.java
│
├── security/
│   ├── JwtUtil.java
│   ├── JwtFilter.java
│   └── SecurityConfig.java
│
├── service/
│   ├── AuthService.java
│   └── UserService.java
│
├── exception/
│   ├── GlobalExceptionHandler.java
│   └── CustomException.java
│
├── AuthSystemApplication.java
└── application.properties

🔐 API Endpoints

✅ Register User

POST /api/auth/register

Request Body

{
  "username": "priyanka",
  "password": "1234",
  "email": "priyanka@gmail.com"
}

✅ Login User

POST /api/auth/login

Request Body

{
  "username": "priyanka",
  "password": "1234"
}

Response

{
  "token": "eyJhbGciOiJIUzI1NiJ9..."
}

🔒 Access Secured API

GET /api/users/profile

Header

Authorization: Bearer <JWT_TOKEN>

🔑 JWT Authentication Flow

  1. User logs in with username & password
  2. Server validates credentials
  3. JWT token is generated
  4. Client sends token in Authorization header
  5. JwtFilter validates token for every request
  6. Access granted to secured endpoints

⚙️ Configuration

Create application.properties file:

server.port=8080

spring.datasource.url=jdbc:mysql://localhost:3306/auth_db
spring.datasource.username=root
spring.datasource.password=your_password

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

jwt.secret=your_jwt_secret
jwt.expiration=86400000

---

## 🧪 Testing

* Use **Postman**
* Register → Login → Copy JWT
* Pass JWT in `Authorization` header to access protected APIs

---

## 🎯 Interview Explanation (One-Liner)

> “I built a Spring Boot authentication system using JWT and Spring Security, implementing secure login, registration, role-based authorization, and clean layered architecture.”

---

## 📌 Future Enhancements

* Refresh Token
* OAuth2 / Google Login
* Email Verification
* Forgot Password Feature
* Docker Deployment

---

## 👩‍💻 Author

**Priyanka Rode**
Java | Spring Boot | Backend Developer

---

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages