Skip to content

A production-ready authentication and authorization system built with Jakarta EE. Features include user registration, secure login/logout, session management, profile editing, password change, and password reset functionality. Built with Servlets, JSP, Hibernate ORM, PostgreSQL, Redis, and containerized with Docker.

License

Notifications You must be signed in to change notification settings

Ilya-sss/AuthApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Secure Authentication System (JEE)

A comprehensive, enterprise-grade authentication system built with Jakarta EE technologies. This application demonstrates secure user management, password recovery via email, and robust session handling.

πŸš€ Features

Core Authentication

  • βœ… User registration with validation
  • βœ… Secure login with BCrypt password hashing
  • βœ… Session-based authentication
  • βœ… Remember me functionality
  • βœ… Logout with session cleanup

Password Management

  • πŸ” Secure password hashing with BCrypt
  • πŸ“§ Email-based password reset with 6-digit verification codes
  • πŸ”’ Password change functionality
  • πŸ“‹ Password requirements enforcement

User Features

  • πŸ‘€ User profile management
  • ✏️ Profile editing capabilities
  • πŸ“Š Protected dashboard with authentication filter
  • 🎨 Responsive, modern UI design

Security Features

  • πŸ›‘οΈ CSRF protection considerations
  • 🚫 Input validation and sanitization
  • πŸ”’ Session timeout management (15 minutes for password reset)
  • πŸ“‹ Security constraints configuration
  • πŸ” Secure cookie configuration (HTTP-only)

πŸ—οΈ Technology Stack

Backend

  • Jakarta EE 10 - Enterprise Java framework
  • Servlet API 6.0 - Web component development
  • JSP 3.1 - Dynamic web pages
  • JSTL - JSP Standard Tag Library
  • Hibernate 6.4 - ORM for database operations
  • PostgreSQL - Primary database
  • Redis - Session storage and caching
  • JavaMail - Email functionality

Frontend

  • HTML5/CSS3 - Modern responsive design
  • Vanilla JavaScript - Client-side interactions
  • JSP Templates - Server-side rendering

Build & Deployment

  • Apache Maven - Dependency management and build automation
  • Docker & Docker Compose - Containerization
  • Apache Tomcat 10.1 - Application server
  • C3P0 - Database connection pooling

Development Tools

  • Lombok - Code generation
  • SLF4J - Logging framework
  • JUnit - Testing framework

πŸ“‹ Prerequisites

  • Java 17 or higher
  • Maven 3.6+
  • Docker & Docker Compose
  • PostgreSQL (or use the provided Docker setup)
  • Redis (or use the provided Docker setup)
  • Gmail account with App Password (for email functionality)

πŸš€ Quick Start

1. Clone the Repository

git clone <repository-url>
cd authapp2

2. Configure Email (Required for password reset)

Create a .env file with your Gmail credentials:

# Generate App Password at: https://myaccount.google.com/apppasswords
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-16-digit-app-password
FROM_EMAIL=your-email@gmail.com

3. Start with Docker Compose

docker-compose up -d

4. Access the Application

πŸ“ Project Structure

authapp2/
β”œβ”€β”€ src/main/
β”‚   β”œβ”€β”€ java/com/auth/
β”‚   β”‚   β”œβ”€β”€ dao/           # Data Access Objects
β”‚   β”‚   β”œβ”€β”€ model/         # Entity classes
β”‚   β”‚   β”œβ”€β”€ servlet/       # HTTP request handlers
β”‚   β”‚   β”œβ”€β”€ filter/        # Security filters
β”‚   β”‚   β”œβ”€β”€ service/       # Business logic
β”‚   β”‚   └── util/          # Utility classes (Password, Email)
β”‚   β”œβ”€β”€ webapp/
β”‚   β”‚   β”œβ”€β”€ WEB-INF/
β”‚   β”‚   β”‚   β”œβ”€β”€ views/     # JSP pages
β”‚   β”‚   β”‚   └── web.xml    # Deployment descriptor
β”‚   β”‚   └── css/           # Stylesheets
β”‚   └── resources/
β”‚       β”œβ”€β”€ META-INF/      # JPA configuration
β”‚       └── email.properties # Email settings template
β”œβ”€β”€ docker/
β”‚   └── Dockerfile         # Application container
β”œβ”€β”€ docker-compose.yml      # Multi-container setup
β”œβ”€β”€ pom.xml               # Maven configuration
β”œβ”€β”€ .env.example          # Environment variables template
└── README.md             # This file

πŸ”§ Configuration

Database Configuration

The application uses PostgreSQL with connection pooling. Database settings are configured in:

  • src/main/resources/META-INF/persistence.xml - JPA configuration
  • docker-compose.yml - Docker database setup

Email Configuration

Email functionality uses Gmail SMTP. Configure in:

  • .env file (recommended) or
  • src/main/java/com/auth/util/EmailUtil.java

Security Configuration

Security settings are in src/main/webapp/WEB-INF/web.xml:

  • Session timeout: 30 minutes
  • Password reset timeout: 15 minutes
  • Transport guarantee: Configurable (HTTP/HTTPS)

πŸ“§ Email Setup Guide

Gmail Configuration

  1. Enable 2-Step Verification on your Gmail account
  2. Visit Google App Passwords
  3. Generate a new app password:
    • Select app: "Mail"
    • Select device: "Other" β†’ "AuthApp"
  4. Use the 16-character password in your .env file

Alternative Email Providers

Update EmailUtil.java with your SMTP provider settings:

SMTP_HOST = "smtp.your-provider.com"
SMTP_PORT = "587"  // or appropriate port

🐳 Docker Deployment

The application is fully containerized with:

Services

  • tomcat: Application server (port 8080)
  • postgres: PostgreSQL database (port 5432)
  • redis: Redis cache (port 6379)

Commands

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f tomcat

# Stop services
docker-compose down

# Rebuild after changes
mvn clean package && docker-compose up -d --build

πŸ§ͺ Testing

Manual Testing

  1. Registration: Create a new user account
  2. Login: Test authentication functionality
  3. Password Reset: Test email verification flow
  4. Profile Management: Edit user profile
  5. Session Management: Test session timeout

Automated Testing

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=UserServiceTest

πŸ”’ Security Considerations

Implemented

  • βœ… Password hashing with BCrypt
  • βœ… Session timeout management
  • βœ… Input validation
  • βœ… SQL injection protection via JPA/Hibernate
  • βœ… XSS protection via JSP escaping
  • βœ… Email verification for password reset

Production Recommendations

  • πŸ”„ Enable HTTPS (change transport-guarantee to CONFIDENTIAL)
  • πŸ”‘ Use environment variables for sensitive data
  • πŸ›‘οΈ Implement rate limiting
  • πŸ“ Add comprehensive logging and monitoring
  • πŸ” Set up CSP headers
  • 🌐 Configure reverse proxy (Nginx/Apache)

πŸ“Š Database Schema

Users Table

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,
    full_name VARCHAR(50),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

πŸš€ API Endpoints

Public Endpoints

  • GET / - Welcome page
  • GET /login - Login form
  • POST /login - Process login
  • GET /register - Registration form
  • POST /register - Process registration
  • GET /forgot-password - Forgot password form
  • POST /forgot-password - Send reset code
  • GET /reset-password - Reset password form
  • POST /reset-password - Process password reset

Protected Endpoints (Authentication Required)

  • GET /dashboard - User dashboard
  • GET /profile - View profile
  • GET /edit-profile - Edit profile form
  • POST /edit-profile - Update profile
  • GET /change-password - Change password form
  • POST /change-password - Update password
  • POST /logout - Logout

πŸ› Troubleshooting

Common Issues

Email Not Sending

  • Check Gmail app password configuration
  • Ensure 2-Step Verification is enabled
  • Verify SMTP settings in .env file

Database Connection Issues

  • Verify PostgreSQL is running: docker ps | grep postgres
  • Check database credentials in docker-compose.yml
  • Review persistence.xml configuration

Application Not Starting

  • Check Docker logs: docker logs auth-tomcat
  • Verify WAR file exists in target/ directory
  • Check for port conflicts (8080)

Session Issues

  • Clear browser cookies and session data
  • Check Redis connection if using external session storage
  • Review session timeout configuration

πŸ“ Development Guide

Adding New Features

  1. Create/update servlets in src/main/java/com/auth/servlet/
  2. Add JSP views in src/main/webapp/WEB-INF/views/
  3. Update security filters if needed
  4. Add DAO methods for database operations

Code Style

  • Follow Java naming conventions
  • Use Lombok for boilerplate code reduction
  • Maintain separation of concerns (DAO β†’ Service β†’ Servlet)
  • Add proper logging and error handling

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Commit changes: git commit -m 'Add new feature'
  4. Push to branch: git push origin feature/new-feature
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Jakarta EE community for the enterprise framework
  • Spring Security inspiration for authentication patterns
  • BCrypt library for secure password hashing
  • Docker community for containerization tools
  • Bootstrap and modern CSS frameworks for UI inspiration

Note: This is an educational project demonstrating enterprise Java patterns. For production deployment, ensure all security configurations are properly hardened.

About

A production-ready authentication and authorization system built with Jakarta EE. Features include user registration, secure login/logout, session management, profile editing, password change, and password reset functionality. Built with Servlets, JSP, Hibernate ORM, PostgreSQL, Redis, and containerized with Docker.

Topics

Resources

License

Stars

Watchers

Forks