Skip to content

Conversation

@MateusOK
Copy link
Owner

@MateusOK MateusOK commented Oct 3, 2025

This pull request introduces JWT-based authentication to the application, refactoring the authentication flow to generate and validate JWT tokens, and integrating these changes throughout the codebase. It also improves security configurations and updates the persistence layer to better support user roles and statuses.

Authentication and Security Enhancements:

  • Added a new JwtService class to handle JWT token generation and validation, using the io.jsonwebtoken library. The service is now injected into the authentication use case and used to generate tokens upon successful authentication. [1] [2] [3] [4] [5]
  • Introduced JwtAuthenticationFilter to validate JWT tokens on incoming requests and set up the security context accordingly.
  • Added CustomUserDetailsService to integrate user details retrieval with Spring Security.
  • Implemented a new SecurityConfig class to configure stateless session management, password encoding, authentication providers, and filter chains for JWT-based authentication.

Persistence and Domain Model Adjustments:

  • Updated UserEntity to enforce uniqueness on the cpf field and to store role and status as string enums, improving data integrity and readability. [1] [2]
  • Fixed and expanded UserMapper to correctly map all relevant fields between User and UserEntity.

Configuration and Testing:

  • Migrated application configuration to application.yaml, adding JWT secret and expiration settings. [1] [2]
  • Updated tests for AuthenticateUserUseCase to mock and verify JWT token generation, ensuring correct behavior for both successful and failed authentication scenarios. [1] [2] [3] [4] [5] [6]

Bug Fixes:

  • Corrected the argument order in the password matching logic of BCryptPasswordHasher.

@MateusOK MateusOK self-assigned this Oct 3, 2025
@MateusOK MateusOK merged commit b1ffee9 into main Oct 6, 2025
1 check 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.

1 participant