https://github.com/anmol420/authenticationsystemapi
An Authentication System designed in Spring Security.
https://github.com/anmol420/authenticationsystemapi
authentication-backend docker-compose java postgresql spring-boot spring-data-jpa spring-security
Last synced: 2 months ago
JSON representation
An Authentication System designed in Spring Security.
- Host: GitHub
- URL: https://github.com/anmol420/authenticationsystemapi
- Owner: anmol420
- Created: 2025-06-08T12:21:37.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-11T11:10:15.000Z (about 1 year ago)
- Last Synced: 2025-06-11T11:51:29.128Z (about 1 year ago)
- Topics: authentication-backend, docker-compose, java, postgresql, spring-boot, spring-data-jpa, spring-security
- Language: Java
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```bash
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:
```bash
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
```bash
./mvnw spring-boot:run
```
---
## API Endpoints
### 1. Register
```http
POST /auth/register
```
**Request Body:**
```json
{
"username": "your_username",
"password": "your_password"
}
```
### 2. Login
```http
POST /auth/login
```
**Request Body:**
```json
{
"username": "your_username",
"password": "your_password"
}
```
**Response:** Sets a JWT cookie if successful.
### 3. Logout
```http
POST /auth/logout
```
Logs the user out and clears the cookie.
### 4. Dashboard (Protected)
```http
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.