The Authentication Microservice is a core component of the Podzilla system, designed to handle user authentication and authorization securely. Built as a standalone microservice, it provides robust mechanisms for user management, secure access control, and session handling, ensuring seamless integration with other services in the Podzilla ecosystem.
- Login: Secure user authentication using email/username and password with JWT-based access tokens.
- Logout: Invalidate user sessions and refresh tokens.
- Register: Create new user accounts with email verification.
- Update User Data: Allow users to update their profile information securely.
- Activate/Deactivate Users: Admin functionality to manage user account statuses.
- Refresh Access Token: Generate new access tokens using refresh tokens for seamless user experience.
- Role-Based Access Control: Support for different user roles (e.g., admin, user) with fine-grained permissions.
The project adheres to Java conventions and best practices for maintainability and readability:
- Naming Conventions:
- Classes: PascalCase (e.g.,
UserService,AuthController) - Methods and Variables: camelCase (e.g.,
authenticateUser,userId) - Constants: UPPER_SNAKE_CASE (e.g.,
MAX_LOGIN_ATTEMPTS) - Packages: Lowercase with meaningful hierarchy (e.g.,
com.podzilla.auth.service)
- Classes: PascalCase (e.g.,
- Best Practices:
- Use meaningful names that reflect purpose (e.g.,
generateJwtTokeninstead ofgenToken). - Follow single-responsibility principle for methods and classes.
- Include JavaDoc for public methods and classes.
- Enforce code quality with Checkstyle to ensure consistent formatting and adherence to standards.
- Avoid magic numbers/strings; use constants instead.
- Handle exceptions gracefully with proper logging.
- Use meaningful names that reflect purpose (e.g.,
The Authentication Microservice follows a microservice architecture with Domain-Driven Design (DDD) and Clean Architecture principles. The codebase is organized into distinct layers to ensure separation of concerns:
- Models: Represent domain entities (e.g.,
User,Role). - Repositories: Handle data persistence using JDBC for MySQL and Redis for caching.
- Services: Contain business logic (e.g.,
AuthService,UserService). - Controllers: Expose RESTful endpoints for client interaction (e.g.,
/api/auth/login). - DTOs (Data Transfer Objects): Used for request/response payloads to decouple API contracts from domain models.
The microservice communicates with other Podzilla services via REST APIs and uses Redis for fast, in-memory token storage. Spring Security is leveraged for authentication and authorization, ensuring secure access control.
- Java 17
- Maven 3.8.6+
- Docker 24.0+
- MySQL 8.0+
- Redis 7.2+
- Git
-
Clone the Repository:
git clone https://github.com/Podzilla/authentication.git cd authentication -
Configure Environment:
- Create a
.envfile based on.env.exampleand update with your MySQL and Redis credentials:SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/auth_db SPRING_DATASOURCE_USERNAME=root SPRING_DATASOURCE_PASSWORD=your_password SPRING_REDIS_HOST=localhost SPRING_REDIS_PORT=6379
- Create a
-
Build the Project:
mvn clean install
-
Run the Application:
mvn spring-boot:run
The service will be available at
http://localhost:8080. -
Run with Docker:
docker build -t podzilla-authentication . docker run -p 8080:8080 --env-file .env podzilla-authentication -
Access Swagger UI:
- Navigate to
http://localhost:8080/swagger-ui.htmlto explore and test API endpoints.
- Navigate to
-
Run Tests:
mvn test- Unit and integration tests are written using JUnit 5.
- Code coverage reports are generated and available in
target/site/jacoco.
We welcome contributions to enhance the Authentication Microservice! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes and ensure tests pass (
mvn test). - Run Checkstyle to verify code quality:
mvn checkstyle:check
- Commit your changes with a clear message (
git commit -m "Add your feature"). - Push to your branch (
git push origin feature/your-feature). - Open a pull request with a detailed description of your changes.
- Ensure your PR passes CI/CD checks.
Please follow the code style guidelines and include tests for new features or bugfixes.