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.
- 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
- Java 21
- Spring Boot
- Spring Security
- Spring Data JPA
- PostgreSQL
- Docker & Docker Compose
- Java 21
- Maven
- Docker & Docker Compose
git clone https://github.com/your-username/spring-auth-system.git
cd spring-auth-system
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.
./mvnw spring-boot:run
POST /auth/register
Request Body:
{
"username": "your_username",
"password": "your_password"
}
POST /auth/login
Request Body:
{
"username": "your_username",
"password": "your_password"
}
Response: Sets a JWT cookie if successful.
POST /auth/logout
Logs the user out and clears the cookie.
GET /dashboard
Requires authentication via cookie.
All environment settings (like DB URL, JWT expiration, etc.) can be configured in application.properties
.
- 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.