This repository was archived by the owner on Jul 6, 2025. It is now read-only.
80 8 authenticated order creation#104
Merged
gustaavik merged 2 commits into80-complete-project-restructurefrom Feb 6, 2025
Merged
80 8 authenticated order creation#104gustaavik merged 2 commits into80-complete-project-restructurefrom
gustaavik merged 2 commits into80-complete-project-restructurefrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several changes to enhance the security and authorization mechanisms in the
OrderControllerand related classes. The most important changes include adding authorization checks for order creation and fetching, updating DTOs and models to support these checks, and adding new exception handling for unauthorized actions.Authorization Enhancements:
src/main/java/com/zenfulcode/commercify/api/order/OrderController.java: Added authorization checks to ensure that only authorized users can create, fetch, or cancel orders. This includes checking the authenticated user's ID against the order's user ID and throwingUnauthorizedOrderCreationExceptionorUnauthorizedOrderFetchingExceptionwhen unauthorized actions are detected. [1] [2] [3]DTO and Model Updates:
src/main/java/com/zenfulcode/commercify/api/order/dto/request/CreateOrderRequest.java: Added a method to get theUserIdfrom the request.src/main/java/com/zenfulcode/commercify/auth/domain/model/AuthenticatedUser.java: Added methods to get theUserIdand check if the user has an admin role.Exception Handling:
src/main/java/com/zenfulcode/commercify/order/domain/exception/UnauthorizedOrderCreationException.java: Added a new exception for unauthorized order creation attempts.src/main/java/com/zenfulcode/commercify/order/domain/exception/UnauthorizedOrderFetchingException.java: Added a new exception for unauthorized order fetching attempts.src/main/java/com/zenfulcode/commercify/shared/domain/exception/DomainForbiddenException.java: Added a base exception class for forbidden domain actions.src/main/java/com/zenfulcode/commercify/shared/interfaces/rest/exception/GlobalExceptionHandler.java: Added a handler forDomainForbiddenExceptionto return a 403 Forbidden response.Minor Changes:
src/main/java/com/zenfulcode/commercify/api/auth/dto/response/AuthResponse.java: Updated to convertuserIdto a string.src/main/java/com/zenfulcode/commercify/auth/infrastructure/security/TokenService.java: Updated to convertuserIdto a string in the JWT token.