Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package com.kpksoftware.domain;
  2.  
  3. import lombok.Getter;
  4. import org.springframework.security.authentication.LockedException;
  5. import org.springframework.security.core.authority.AuthorityUtils;
  6.  
  7. import static com.kpksoftware.util.Constants.LOCKED_ACCOUNT_MESSAGE;
  8.  
  9.  
  10. @Getter
  11. public class CurrentUser extends org.springframework.security.core.userdetails.User {
  12. private User user;
  13.  
  14. public CurrentUser(User user) {
  15. super(user.getEmail(), user.getPassword(), AuthorityUtils.createAuthorityList(user.getRole().toString()));
  16. this.user = user;
  17. }
  18.  
  19. public boolean isAccountNonLocked() {
  20. if (!user.isActive()) {
  21. throw new LockedException(LOCKED_ACCOUNT_MESSAGE);
  22. }
  23. return true;
  24. }
  25.  
  26. public User getUser() {
  27. return user;
  28. }
  29.  
  30. public Long getId() {
  31. return new Long(user.getId());
  32. }
  33.  
  34. public Role getRole() {
  35. return user.getRole();
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement