Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/maven/org.apache.maven.plugins-ma…
Browse files Browse the repository at this point in the history
…ven-compiler-plugin-3.13.0
  • Loading branch information
LauroSilveira authored Mar 19, 2024
2 parents d3bfc0f + 127fc98 commit ecb056b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenJwtDto> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecb056b

Please sign in to comment.