1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
@SuppressWarnings("serial")
@Entity
@Table (name="user")
public class User implements UserDetails, java.io.Serializable {
protected static String ROLE_ADMIN = "TMD_ADMIN";
protected static String ROLE_DEV = "TMD_DEV";
protected static String ROLE_CLIENT = "TMD_CLIENT";
@Id
@Column (name="code")
private String code;
@Column (name="password")
private String password;
@Column (name="fullname")
private String fullname;
@Column (name="email")
private String email;
@Column (name="version")
private Integer version;
private Set<String> roles = new HashSet<String>(0);
public User() {}
public User(String code,String password) {
this.code = code;
this.password = password;
}
public User(String code,String password,String fullname) {
this.code = code;
this.password = password;
this.fullname = fullname;
}
/*
* Les getters et les setters
*/
public String getCode() {
return this.code;
}
public String getPassword() {
return this.password;
}
public String getFullname() {
return this.fullname;
}
public String getEmail() {
return this.email;
}
public Integer getVersion() {
return this.version;
}
public Set<String> getRoles() {
return this.roles;
}
public void setCode(String code) {
this.code = code;
}
public void setPassword(String password) {
this.password = password;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public void setEmail(String email) {
this.email = email;
}
public void setVersion(Integer version) {
this.version = version;
}
public void setRoles(Set<String> roles) {
this.roles = roles;
}
@Override
public Collection<GrantedAuthority> getAuthorities() {
List<GrantedAuthority> grantedAuthority = new ArrayList<GrantedAuthority>(roles.size());
for(String role : roles){
grantedAuthority.add(new GrantedAuthorityImpl(role));
}
return grantedAuthority;
}
@Override
public String getUsername() {
// TODO Auto-generated method stub
return code;
}
@Override
public boolean isAccountNonExpired() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isAccountNonLocked() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isCredentialsNonExpired() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isEnabled() {
// TODO Auto-generated method stub
return true;
}
public boolean hasRole(String role) {
for(String r : roles){
if(r.equals(role))
return true;
}
return false;
}
public int hashCode() {
return (code != null ? code.hashCode() : 0);
}
public boolean equals(Object o) {
if(this == o) return true;
if(!(o instanceof User)) return false;
final User user = (User) o;
if(code != null ? !code.equals(user.getCode()) : user.getCode() !=null) return false;
return true;
}
} |
Partager