diff --git a/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationController.java b/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationController.java index 805e89e..ead70b9 100644 --- a/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationController.java +++ b/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationController.java @@ -19,20 +19,22 @@ @RequestMapping("/login") public class AuthenticationController { - private final AuthenticationManager manager; + private final AuthenticationManager authenticationManager; private final TokenService tokenService; - public AuthenticationController(AuthenticationManager manager, TokenService tokenService) { - this.manager = manager; + public AuthenticationController(AuthenticationManager authenticationManager, TokenService tokenService) { + this.authenticationManager = authenticationManager; this.tokenService = tokenService; } @PostMapping public ResponseEntity login(@RequestBody @Valid AuthenticationDto dto) { log.info("Request to Login user: {}", dto.username()); + // Object wrapper that contains password and user final var authenticationToken = new UsernamePasswordAuthenticationToken(dto.username(), dto.password()); - final var authentication = this.manager.authenticate(authenticationToken); + //authenticationManager compare the password of the request with the password from database. + final var authentication = this.authenticationManager.authenticate(authenticationToken); final var tokenJWT = tokenService.generateTokenJWT((User) authentication.getPrincipal()); log.info("Token Generated with Success!"); return ResponseEntity.ok().body(new TokenJwtDto(tokenJWT)); diff --git a/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java b/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java index ca9d08e..f09b94e 100644 --- a/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java +++ b/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java @@ -49,7 +49,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { } /** - * Crete @Bean AuthenticationManager to authenticate a user + * Create @Bean AuthenticationManager to authenticate a user * @return AuthenticationManager */ @Bean