From 127fc98e333db4fc68f8fea3f29c4caf740553ec Mon Sep 17 00:00:00 2001 From: Lauro Correia Silveira Date: Tue, 19 Mar 2024 11:46:26 +0100 Subject: [PATCH] Added comments on AuthenticationController (#108) --- .../authentication/AuthenticationController.java | 10 ++++++---- .../security/SecurityConfigurations.java | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) 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