C:\Alura\Sprint3\Java Spring Boot API REST\forum\src\main\java\br\com\alura\forum\controller\AutenticacaoController.java:35:40 java: cannot find symbol symbol: method gerarToken(org.springframework.security.core.Authentication) location: variable tokenService of type org.springframework.security.core.token.TokenService
` package br.com.alura.forum.controller;
import br.com.alura.forum.controller.form.LoginForm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.token.TokenService; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RestController @RequestMapping("/auth") public class AutenticacaoController {
@Autowired
private AuthenticationManager authManager;
@Autowired
private TokenService tokenService;
@PostMapping
public ResponseEntity<?> autenticar(@RequestBody @Valid LoginForm form) {
UsernamePasswordAuthenticationToken dadosLogin = form.converter();
try {
Authentication authentication = authManager.authenticate(dadosLogin);
String token = tokenService.gerarToken(authentication);
System.out.println(token);
return ResponseEntity.ok().build();
}catch (AuthenticationException e) {
return ResponseEntity.badRequest().build();
}
}
} `