Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. @Override
  2. public Authentication authenticate(Authentication authentication)
  3. throws AuthenticationException {
  4.  
  5. String username = authentication.getName();
  6. String password = authentication.getCredentials().toString();
  7. CustomUser user = _userDetailService.loadUserByUsername(username);
  8. if (user == null || !user.getUsername().equalsIgnoreCase(username)) {
  9. throw new BadCredentialsException("Username not found.");
  10. }
  11. if (!BCrypt.checkpw(password, user.getPassword())) {
  12. throw new BadCredentialsException("Wrong password.");
  13. }
  14. Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
  15. return new UsernamePasswordAuthenticationToken(user, password, authorities);
  16. }
  17.  
  18. try {
  19. Authentication auth = super.authenticate(authentication);
  20. //if reach here, means login success, else an exception will be thrown
  21. //reset the user_attempts
  22. return auth;
  23.  
  24. } catch (BadCredentialsException e) {
  25. //invalid login, update to user_attempts
  26. throw e;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement