Skip to content

anmol420/AuthenticationSystemAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Authentication System

This is a secure and minimal authentication system built using Spring Boot, Spring Security, Spring Data JPA, PostgreSQL, and Docker Compose. It includes basic routes for user registration, login, logout, and access to a protected dashboard. It uses cookie-based authentication to maintain session security.


Features

  • Secure login and registration
  • Cookie-based session authentication
  • JWT token handling (with custom error handling)
  • PostgreSQL database integration
  • Docker Compose setup for easy database deployment

Tech Stack

  • Java 21
  • Spring Boot
  • Spring Security
  • Spring Data JPA
  • PostgreSQL
  • Docker & Docker Compose

Getting Started

Prerequisites

  • Java 21
  • Maven
  • Docker & Docker Compose

Clone the Repository

  git clone https://github.com/your-username/spring-auth-system.git
  cd spring-auth-system

Setup PostgreSQL with Docker

Use the provided docker-compose.yml to spin up a PostgreSQL container:

  docker-compose up -d

Default credentials (defined in application.properties):

  • Username: postgres
  • Password: changemeinprod!
  • DB Name: auth_system

Make sure your Spring Boot app connects to this database.

Run the Application

  ./mvnw spring-boot:run

API Endpoints

1. Register

POST /auth/register

Request Body:

{
  "username": "your_username",
  "password": "your_password"
}

2. Login

POST /auth/login

Request Body:

{
  "username": "your_username",
  "password": "your_password"
}

Response: Sets a JWT cookie if successful.

3. Logout

POST /auth/logout

Logs the user out and clears the cookie.

4. Dashboard (Protected)

GET /dashboard

Requires authentication via cookie.


Configuration

All environment settings (like DB URL, JWT expiration, etc.) can be configured in application.properties.


Troubleshooting

  • 403 Forbidden: Check if the JWT cookie is present and valid.
  • Password Error: Ensure password is Bcrypt encoded.
  • CORS issues: Make sure the frontend origin is allowed in your CORS configuration.

About

An Authentication System designed in Spring Security.

Topics

Resources

Stars

Watchers

Forks

Languages