CustomUserDetails.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //package seecoder.devcloud.web.vo.user;
  2. //
  3. //import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  4. //
  5. //import lombok.*;
  6. //import org.apache.commons.codec.digest.DigestUtils;
  7. //import org.springframework.beans.BeanUtils;
  8. //import org.springframework.security.core.GrantedAuthority;
  9. //import org.springframework.security.core.userdetails.UserDetails;
  10. //import org.springframework.security.core.userdetails.UsernameNotFoundException;
  11. //import seecoder.devcloud.web.po.user.User;
  12. //
  13. //import java.util.Collections;
  14. //import java.util.Set;
  15. //
  16. //import static seecoder.devcloud.web.enums.UserIdentity.STUDENT;
  17. //import static seecoder.devcloud.web.enums.UserIdentity.TEACHER;
  18. //import static seecoder.devcloud.web.infrastructure.security.WebSecurityConstants.*;
  19. //
  20. //
  21. //@Data
  22. //@EqualsAndHashCode
  23. //@ToString
  24. //@NoArgsConstructor
  25. //@AllArgsConstructor
  26. //@JsonIgnoreProperties(ignoreUnknown = true)
  27. //public class CustomUserDetails implements UserDetails {
  28. // private Integer id;
  29. // private String username;
  30. // private String password;
  31. // private Set<GrantedAuthority> authorities;
  32. //
  33. // CustomUserDetails(User user) {
  34. // BeanUtils.copyProperties(user, this);
  35. // switch (user.getRole()) {
  36. // case STUDENT:
  37. // this.authorities = Collections.singleton(STUDENT_AUTHORITY);
  38. // break;
  39. // case TEACHER:
  40. // this.authorities = Collections.singleton(TEACHER_AUTHORITY);
  41. // break;
  42. // default:
  43. // throw new UsernameNotFoundException(username);
  44. // }
  45. // }
  46. //
  47. // CustomUserDetails(String username, String password) {
  48. // this.id = 0;
  49. // this.username = username;
  50. // this.password = DigestUtils.sha256Hex(password);
  51. // this.authorities = Collections.singleton(ADMIN_AUTHORITY);
  52. // }
  53. //
  54. // @Override
  55. // public boolean isAccountNonExpired() {
  56. // return true;
  57. // }
  58. //
  59. // @Override
  60. // public boolean isAccountNonLocked() {
  61. // return true;
  62. // }
  63. //
  64. // @Override
  65. // public boolean isCredentialsNonExpired() {
  66. // return true;
  67. // }
  68. //
  69. // @Override
  70. // public boolean isEnabled() {
  71. // return true;
  72. // }
  73. //
  74. // public boolean isStudent() {
  75. // return authorities.contains(STUDENT_AUTHORITY);
  76. // }
  77. //
  78. // public boolean isTeacher() {
  79. // return authorities.contains(TEACHER_AUTHORITY);
  80. // }
  81. //
  82. // public boolean isAdmin() {
  83. // return authorities.contains(ADMIN_AUTHORITY);
  84. // }
  85. //}