Skip to content

Instantly share code, notes, and snippets.

@slmanju
Created January 7, 2018 14:35
Show Gist options
  • Select an option

  • Save slmanju/eb0a38b38bffd7e341dd9ee94f92a994 to your computer and use it in GitHub Desktop.

Select an option

Save slmanju/eb0a38b38bffd7e341dd9ee94f92a994 to your computer and use it in GitHub Desktop.
@RestController
public class LoginController {
@Autowired
private AuthenticationManager authenticationManager;
@PostMapping("/token")
public ResponseEntity<?> authenticate(@RequestBody LoginDto loginDto) {
// Perform the authentication
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
loginDto.getUsername(),
loginDto.getPassword()
);
Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
return ResponseEntity.ok(TokenDto.builder().token("winteriscoming").build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment