Skip to content

yokDS15dcK/Java-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CodeJam Logo

AuthZen πŸ”

A secure, extensible authentication and authorization backend for modern applications built with Spring Boot. Designed for scalability and real-world integration, this project includes JWT, OAuth2, role-based access, admin controls, and token lifecycle management.


✨ Features

  • User Registration & Login (JWT-based)
  • Refresh Token handling (per user, revocable)
  • GitHub OAuth2 login support
  • Role-based Access Control (User/Admin)
  • Audit Logging (for all sensitive actions)
  • Admin Delegation (promote/demote users)
  • Token Revocation on logout
  • Account Lock/Unlock Management

πŸ“† Technologies

  • Java 21
  • Spring Boot 3
  • Spring Security
  • JWT (Access & Refresh)
  • OAuth2 (GitHub)
  • MySQL
  • Hibernate (JPA)
  • Lombok
  • MapStruct (optional)
  • Docker (optional for deployment)

🌐 API Endpoints

πŸ”“ Public

Method Endpoint Description
POST /auth/register Register a new user
POST /auth/login Login with email & password
POST /auth/oauth GitHub OAuth login
POST /auth/reset-request Request password reset token
POST /auth/reset-password Reset password using token
POST /auth/refresh Revoke refresh token

πŸ” Secured (Authenticated User)

Method Endpoint Description
GET /auth/me Get logged-in user profile
PUT /auth/update Update profile
POST /auth/logout Logout

πŸ› οΈ Admin Only

Method Endpoint Description
GET /admin/users View all users
PUT /admin/users/{id}/roles Update user roles to relevent user
GET /admin/audit-logs View audit logs
GET /admin/roles List all available roles
POST /admin/delegate Delegate admin role to another user
POST /admin/users/roles Update user roles

πŸŽ“ Project Structure

Authzen/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── com/
β”‚   β”‚   β”‚       └── yourorg/
β”‚   β”‚   β”‚           └── authzen/
β”‚   β”‚   β”‚               β”œβ”€β”€ AuthzenApplication.java
β”‚   β”‚   β”‚               β”œβ”€β”€ configs/
β”‚   β”‚   β”‚               β”œβ”€β”€ constants/
β”‚   β”‚   β”‚               β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚               β”œβ”€β”€ dtos/
β”‚   β”‚   β”‚               β”œβ”€β”€ endpoints/
β”‚   β”‚   β”‚               β”œβ”€β”€ exceptions/
β”‚   β”‚   β”‚               β”œβ”€β”€ models/
β”‚   β”‚   β”‚               β”œβ”€β”€ repositories/
β”‚   β”‚   β”‚               β”œβ”€β”€ responses/
β”‚   β”‚   β”‚               β”œβ”€β”€ security/
β”‚   β”‚   β”‚               β”œβ”€β”€ services/
β”‚   β”‚   β”‚               └── utils/
β”‚   β”‚   └── resources/
β”‚   β”‚       β”œβ”€β”€ application.yml
β”‚   β”‚       β”œβ”€β”€ static/
β”‚   β”‚       β”‚   β”œβ”€β”€ css/
β”‚   β”‚       β”‚   β”œβ”€β”€ js/
β”‚   β”‚       β”‚   └── reset-password/
β”‚   β”‚       └── templates/
β”œβ”€β”€ .env
β”œβ”€β”€ .env.docker
β”œβ”€β”€ .env.example
β”œβ”€β”€ .gitignore
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ HELP.md
β”œβ”€β”€ LICENSE.md
β”œβ”€β”€ mvnw
β”œβ”€β”€ mvnw.cmd
β”œβ”€β”€ pom.xml
└── README.md

βš™οΈ Getting Started

1. Clone the Repo

git clone https://github.com/kgchinthana/authzen.git
cd authzen

2. Setup Environment Variables

Create .env file in root directory:

  SPRING_APPLICATION_NAME=authzen
  SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/authzen?createDatabaseIfNotExist=true
  SPRING_DATASOURCE_USERNAME=root
  SPRING_DATASOURCE_PASSWORD=yourpassword
  SERVER_PORT=8080
  
  JWT_SECRET=your_secret_key
  JWT_ACCESS_TOKEN_EXPIRY_MS=900000
  JWT_REFRESH_TOKEN_EXPIRY_MS=604800000
  
  MAIL_HOST=smtp.gmail.com
  MAIL_PORT=587
  MAIL_USERNAME=youremail@gmail.com
  MAIL_PASSWORD=yourapppassword
  EMAIL_FROM=noreply@yourdomain.com
  
  GITHUB_CLIENT_ID=your_client_id
  GITHUB_CLIENT_SECRET=your_client_secret
  GITHUB_REDIRECT_URI=http://localhost:8080/oauth/callback
  
  ADMIN_EMAIL=admin@yourdomain.com
  ADMIN_USERNAME=admin
  ADMIN_PASSWORD=Admin@123

3. GitHub OAuth Setup

Register a GitHub OAuth App:

  • Homepage: http://localhost:8080
  • Callback: http://localhost:8080/auth/oauth

Set in .env:

  GITHUB_CLIENT_ID=your_client_id
  GITHUB_CLIENT_SECRET=your_client_secret
  GITHUB_REDIRECT_URI=http://localhost:8080/oauth/callback

4. Run the Application

./mvnw spring-boot:run

Roles (ROLE_USER, ROLE_ADMIN) will be auto-initialized.


🌎 OAuth Flow

  • Frontend gets GitHub access token from GitHub
  • Sends it to /auth/oauth
  • Server verifies token with GitHub & links to user

πŸš€ Example Request: Register

POST /auth/register
Content-Type: application/json

{
  "username": "alice",
  "email": "alice@example.com",
  "password": "securepass"
}

πŸ“„ Environment Variables

Key Description
GITHUB_CLIENT_ID GitHub OAuth client ID
GITHUB_CLIENT_SECRET GitHub OAuth client secret
JWT_SECRET JWT signing key
JWT_EXPIRATION Access token duration
REFRESH_TOKEN_EXPIRATION Refresh token duration

πŸ“Š Database Schema

  • users: user credentials and metadata
  • roles: available roles
  • user_roles: user-role associations
  • refresh_tokens: long-lived refresh tokens
  • oauth_providers: linked GitHub accounts
  • audit_logs: admin actions tracking
  • email_tokens: password reset tokens
  • permissions: defines fine-grained permissions
  • role_permissions: role-permissions associations

πŸ›‘οΈ Security Highlights

  • BCrypt hashed passwords
  • JWT with separate refresh token DB
  • Role-checking via @PreAuthorize & SecurityContext
  • Admin-only endpoints protected with ROLE_ADMIN
  • GitHub token verification before linking

πŸ”§ Contributing

  1. Fork the repo
  2. Fix a bug or implement a feature
  3. Submit a pull request

For the open-source competition, check the issues tab for bugs to solve!


πŸ“ƒ License

MIT Β© 2025 β€” CodeJam Codex Team

About

Repo Java-Project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors