Skip to content

Add authentication, security, and JWT functionality#9

Merged
NourAlPha merged 16 commits intodevfrom
Add-auth
May 1, 2025
Merged

Add authentication, security, and JWT functionality#9
NourAlPha merged 16 commits intodevfrom
Add-auth

Conversation

@NourAlPha
Copy link
Copy Markdown
Contributor

Implement foundational authentication features, including user and role management, JWT-based authentication, and role-based security configurations. Add REST endpoints for login, signup, and logout, along with a Dockerized development setup, CI/CD workflows, and logging configurations.

Implement foundational authentication features, including user and role management, JWT-based authentication, and role-based security configurations. Add REST endpoints for login, signup, and logout, along with a Dockerized development setup, CI/CD workflows, and logging configurations.
Implement foundational authentication features, including user and role management, JWT-based authentication, and role-based security configurations. Add REST endpoints for login, signup, and logout, along with a Dockerized development setup, CI/CD workflows, and logging configurations.
@NourAlPha NourAlPha requested a review from YehiaFarghaly April 27, 2025 11:09
@NourAlPha NourAlPha self-assigned this Apr 27, 2025
@NourAlPha NourAlPha requested review from Copilot and removed request for YehiaFarghaly April 27, 2025 11:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces foundational authentication functionality including Spring Security configuration for JWT‐based authentication, user/role management, and REST endpoints for login, signup, and logout. The key changes include:

  • Implementation of security configuration and JWT authentication filter
  • Addition of repository, model, DTO, and controller classes for authentication flows
  • Inclusion of Docker compose and CI/CD workflow configurations to support development and deployment

Reviewed Changes

Copilot reviewed 23 out of 27 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/com/podzilla/auth/security/SecurityConfig.java Spring Security configuration with JWT filter
src/main/java/com/podzilla/auth/security/RestAuthenticationEntryPoint.java Custom authentication entry point for REST APIs
src/main/java/com/podzilla/auth/security/JWTAuthenticationFilter.java JWT filter for validating and setting authentication context
src/main/java/com/podzilla/auth/repository/UserRepository.java JPA repository for User entity
src/main/java/com/podzilla/auth/repository/RoleRepository.java JPA repository for Role entity with enum filtering
src/main/java/com/podzilla/auth/model/User.java User entity including validation annotations
src/main/java/com/podzilla/auth/model/Role.java Role entity with enum mapping
src/main/java/com/podzilla/auth/model/ERole.java Enum definition for roles
src/main/java/com/podzilla/auth/dto/SignupRequest.java DTO for signup operation
src/main/java/com/podzilla/auth/dto/LoginRequest.java DTO for login operation
src/main/java/com/podzilla/auth/controller/AuthenticationController.java REST endpoints for authentication flows
Others (Docker, Promtail, Workflows) Configuration files supporting deployment and CI/CD
Files not reviewed (4)
  • .gitattributes: Language not supported
  • mvnw: Language not supported
  • mvnw.cmd: Language not supported
  • pom.xml: Language not supported
Comments suppressed due to low confidence (3)

src/main/java/com/podzilla/auth/controller/AuthenticationController.java:44

  • Consider returning a generic error message instead of the raw exception message to avoid exposing internal details to the client.
return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED);

src/main/java/com/podzilla/auth/repository/RoleRepository.java:12

  • [nitpick] The method name 'findByErole' may be ambiguous; consider renaming it (e.g., to 'findByErole' with consistent casing or a more descriptive name) to improve code readability.
Optional<Role> findByErole(ERole eRole);

src/main/java/com/podzilla/auth/security/JWTAuthenticationFilter.java:47

  • Verify that extractEmail() correctly uses the JWT token from the request; if it requires the token as a parameter, consider passing the jwt retrieved earlier to ensure the email is extracted from the correct token.
String userEmail = jwtService.extractEmail();

Comment thread src/main/java/com/podzilla/auth/model/User.java Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@NourAlPha NourAlPha requested a review from YehiaFarghaly April 27, 2025 11:12
@YehiaFarghaly YehiaFarghaly changed the base branch from main to dev April 27, 2025 11:24
@NourAlPha NourAlPha requested a review from Copilot April 27, 2025 13:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements foundational authentication features, including JWT-based authentication, user/role management, and REST endpoints for login, signup, and logout, along with a Dockerized development and CI/CD setup.

  • Introduces Spring Security configuration with JWT support
  • Implements authentication endpoints and custom JWT filter
  • Sets up Docker Compose, Promtail, and CI/CD workflows

Reviewed Changes

Copilot reviewed 24 out of 28 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/com/podzilla/auth/security/SecurityConfig.java Configures security, JWT filter integration
src/main/java/com/podzilla/auth/security/JWTAuthenticationFilter.java Implements JWT token extraction and authentication
src/main/java/com/podzilla/auth/security/RestAuthenticationEntryPoint.java Provides custom unauthorized error handling
src/main/java/com/podzilla/auth/repository/*.java Introduces repository interfaces for User and Role
src/main/java/com/podzilla/auth/model/*.java Defines User, Role, and enum models
src/main/java/com/podzilla/auth/dto/*.java Includes DTOs for signup and login
src/main/java/com/podzilla/auth/controller/AuthenticationController.java Exposes endpoints for authentication operations
Other config files (docker-compose.yml, promtail-config.yml, workflows) Provides deployment, logging, and CI configurations
Files not reviewed (4)
  • .gitattributes: Language not supported
  • mvnw: Language not supported
  • mvnw.cmd: Language not supported
  • pom.xml: Language not supported
Comments suppressed due to low confidence (1)

src/main/java/com/podzilla/auth/security/SecurityConfig.java:45

  • The request matcher for the GET method is using "public_resource" without a leading slash. This may result in the matcher not correctly identifying the endpoint and should be updated to "/public_resource".
auth.requestMatchers(HttpMethod.GET, "public_resource")

Comment thread src/main/java/com/podzilla/auth/security/JWTAuthenticationFilter.java Outdated
@NourAlPha NourAlPha requested a review from Copilot April 28, 2025 16:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the foundational authentication functionality for the application by introducing user and role management, JWT-based authentication, and several REST endpoints along with a complete Dockerized and CI/CD setup.

  • Added repository, model, and DTO classes for users, roles, and refresh tokens
  • Created authentication and admin controllers with login, signup, logout, and token refresh endpoints
  • Provided Docker compose configuration for backend, database, Loki, Promtail, and Grafana, as well as CI/CD and linter GitHub workflows

Reviewed Changes

Copilot reviewed 28 out of 32 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/java/com/podzilla/auth/repository/UserRepository.java Added repository interface for User management
src/main/java/com/podzilla/auth/repository/RoleRepository.java Added repository interface for Role management
src/main/java/com/podzilla/auth/repository/RefreshTokenRepository.java Added repository interface to support refresh token expiration check
src/main/java/com/podzilla/auth/model/*.java Introduced User, Role, RefreshToken, and ERole model classes
src/main/java/com/podzilla/auth/dto/*.java Added DTOs for Login and Signup requests
src/main/java/com/podzilla/auth/controller/*.java Developed Authentication and Admin controllers with REST endpoints
src/main/java/com/podzilla/auth/AuthApplication.java Bootstrapped the Spring Boot application
promtail-config.yml Configured Promtail for log collection
docker-compose.yml Set up Docker compose services for backend, database, and monitoring tools
.github/workflows/linter.yml, ci-cd.yml Introduced GitHub workflows for linting and CI/CD
Files not reviewed (4)
  • .gitattributes: Language not supported
  • mvnw: Language not supported
  • mvnw.cmd: Language not supported
  • pom.xml: Language not supported
Comments suppressed due to low confidence (1)

src/main/java/com/podzilla/auth/repository/RoleRepository.java:12

  • [nitpick] The method name 'findByErole' and the field 'erole' are less clear; consider renaming them to 'findByRole' and 'role' for improved clarity.
    Optional<Role> findByErole(ERole eRole);

Comment thread src/main/java/com/podzilla/auth/controller/AuthenticationController.java Outdated
Comment thread src/main/java/com/podzilla/auth/controller/AuthenticationController.java Outdated
Comment thread .github/workflows/ci-cd.yml Outdated
NourAlPha and others added 4 commits April 28, 2025 19:15
…oller.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…oller.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@NourAlPha NourAlPha requested a review from Copilot April 28, 2025 18:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces foundational authentication features including user management, JWT-based authentication, and role-based security configurations along with necessary infrastructure updates.

  • Implements repositories, domain models, and DTOs for users, roles, and refresh tokens.
  • Adds REST endpoints for login, signup, logout, and token refresh in the authentication controller as well as an admin endpoint for user management.
  • Provides Docker, Promtail, and GitHub workflow configuration updates to support development, logging, and CI/CD.

Reviewed Changes

Copilot reviewed 29 out of 33 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/com/podzilla/auth/repository/RoleRepository.java Adds repository interface to query roles by enum value.
src/main/java/com/podzilla/auth/repository/RefreshTokenRepository.java Introduces repository for managing refresh tokens with expiry checks.
src/main/java/com/podzilla/auth/model/User.java Defines the User entity including relationships to roles and refresh tokens.
src/main/java/com/podzilla/auth/model/Role.java Implements Role entity with enum-based default role.
src/main/java/com/podzilla/auth/model/RefreshToken.java Establishes RefreshToken model using UUID generation.
src/main/java/com/podzilla/auth/model/ERole.java Provides enum definition for user roles.
src/main/java/com/podzilla/auth/dto/SignupRequest.java Creates DTO for handling user signup requests.
src/main/java/com/podzilla/auth/dto/LoginRequest.java Creates DTO for handling user login requests.
src/main/java/com/podzilla/auth/controller/ResourceController.java Sets up sample public and secure resource endpoints.
src/main/java/com/podzilla/auth/controller/AuthenticationController.java Implements endpoints for login, signup, logout, and token refresh with logging.
src/main/java/com/podzilla/auth/controller/AdminController.java Provides an endpoint to retrieve all users accessible by admins.
src/main/java/com/podzilla/auth/AuthApplication.java Defines the Spring Boot application entry point.
promtail-config.yml Adds configuration for log scraping with Promtail and Grafana Loki.
docker-compose.yml Sets up multi-service Docker configuration including backend, DB, Loki, Promtail, and Grafana.
.github/workflows/linter.yml Configures a GitHub Action for linting using a shared template.
.github/workflows/ci-cd.yml Configures CI/CD pipeline using a shared Java CI/CD workflow template.
Files not reviewed (4)
  • .gitattributes: Language not supported
  • mvnw: Language not supported
  • mvnw.cmd: Language not supported
  • pom.xml: Language not supported
Comments suppressed due to low confidence (1)

src/main/java/com/podzilla/auth/controller/AuthenticationController.java:49

  • Consider using a generic error message instead of e.getMessage() to avoid exposing internal exception details.
return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED);

Comment thread src/main/java/com/podzilla/auth/controller/AdminController.java Outdated
Comment thread src/main/java/com/podzilla/auth/model/RefreshToken.java
Comment thread src/main/java/com/podzilla/auth/service/JWTService.java Outdated
@NourAlPha NourAlPha merged commit e578c08 into dev May 1, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants