Created
January 14, 2019 09:37
-
-
Save mohashari/9e309f44f4615caa14fe0d3cd8a70a93 to your computer and use it in GitHub Desktop.
User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.monggopesen.mainservice.persistence.domain; | |
| import lombok.Data; | |
| import org.hibernate.annotations.DynamicUpdate; | |
| import org.springframework.security.core.GrantedAuthority; | |
| import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
| import org.springframework.security.core.userdetails.UserDetails; | |
| import javax.persistence.Column; | |
| import javax.persistence.Entity; | |
| import javax.persistence.Index; | |
| import javax.persistence.Table; | |
| import javax.validation.constraints.NotNull; | |
| import java.util.Collection; | |
| import java.util.HashSet; | |
| import java.util.Set; | |
| @Entity | |
| @Table(name = "USERS", | |
| indexes = @Index(columnList = "EMAIL", name = "UK_EMAIL", unique = true)) | |
| @DynamicUpdate | |
| @Data | |
| public class User extends Base implements UserDetails { | |
| @Column(name = "EMAIL", nullable = false) | |
| private String email; | |
| @Column(name = "PASSWORD", nullable = false) | |
| private String password; | |
| @Column(name = "TOKEN") | |
| private String token; | |
| @Column(name = "ROLE") | |
| private String userRole; | |
| @Column(name = "PLATFORM_ID") | |
| private String platformId; | |
| @Column(name = "PLATFORM") | |
| private String platform; | |
| @NotNull | |
| @Column(nullable = false) | |
| private boolean enabled = false; | |
| @Column(name = "account_locked") | |
| private boolean accountNonLocked; | |
| @Column(name = "account_expired") | |
| private boolean accountNonExpired; | |
| @Column(name = "credentials_expired") | |
| private boolean credentialsNonExpired; | |
| @Override | |
| public Collection<? extends GrantedAuthority> getAuthorities() { | |
| Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(); | |
| authorities.add(new SimpleGrantedAuthority(userRole)); | |
| return authorities; | |
| } | |
| @Override | |
| public String getUsername() { | |
| return email; | |
| } | |
| @Override | |
| public boolean isAccountNonExpired() { | |
| return !isAccountNonExpired(); | |
| } | |
| @Override | |
| public boolean isAccountNonLocked() { | |
| return !isAccountNonLocked(); | |
| } | |
| @Override | |
| public boolean isCredentialsNonExpired() { | |
| return !isCredentialsNonExpired(); | |
| } | |
| @Override | |
| public boolean isEnabled() { | |
| return !isEnabled(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment