1 package eu
.etaxonomy
.cdm
.model
.common
;
3 import java
.util
.HashSet
;
5 import java
.util
.TreeSet
;
7 import javax
.persistence
.Entity
;
8 import javax
.persistence
.FetchType
;
9 import javax
.persistence
.ManyToMany
;
10 import javax
.persistence
.Transient
;
12 import org
.hibernate
.annotations
.NaturalId
;
13 import org
.springframework
.security
.GrantedAuthority
;
14 import org
.springframework
.security
.userdetails
.UserDetails
;
17 public class User
extends CdmBase
implements UserDetails
{
22 private static final long serialVersionUID
= 6582191171369439163L;
25 protected String username
;
28 * a salted, MD5 encoded hash of the plaintext password
30 protected String password
;
32 protected String emailAddress
;
34 @ManyToMany(fetch
= FetchType
.LAZY
, targetEntity
= GrantedAuthorityImpl
.class)
35 protected Set
<GrantedAuthority
> grantedAuthorities
= new HashSet
<GrantedAuthority
>();
37 @ManyToMany(fetch
= FetchType
.LAZY
)
38 protected Set
<Group
> groups
= new HashSet
<Group
>();
40 protected boolean enabled
;
42 protected boolean accountNonExpired
;
44 protected boolean credentialsNonExpired
;
46 protected boolean accountNonLocked
;
49 private GrantedAuthority
[] authorities
;
51 private void initAuthorities() {
52 Set
<GrantedAuthority
> allAuthorities
= new TreeSet
<GrantedAuthority
>();
53 allAuthorities
.addAll(grantedAuthorities
);
54 for(Group group
: groups
) {
55 allAuthorities
.addAll(group
.getGrantedAuthorities());
58 authorities
= allAuthorities
.toArray(new GrantedAuthority
[allAuthorities
.size()]);
61 public GrantedAuthority
[] getAuthorities() {
62 if(authorities
== null) initAuthorities();
66 public String
getPassword() {
70 public String
getUsername() {
74 public boolean isAccountNonExpired() {
75 return accountNonExpired
;
78 public boolean isAccountNonLocked() {
79 return accountNonLocked
;
82 public boolean isCredentialsNonExpired() {
83 return credentialsNonExpired
;
86 public boolean isEnabled() {
90 public String
getEmailAddress() {
94 public void setEmailAddress(String emailAddress
) {
95 this.emailAddress
= emailAddress
;
98 public Set
<GrantedAuthority
> getGrantedAuthorities() {
99 return grantedAuthorities
;
102 public void setGrantedAuthorities(Set
<GrantedAuthority
> grantedAuthorities
) {
103 this.grantedAuthorities
= grantedAuthorities
;
107 public void setUsername(String username
) {
108 this.username
= username
;
111 public void setPassword(String password
) {
112 this.password
= password
;
115 public void setEnabled(boolean enabled
) {
116 this.enabled
= enabled
;
119 public void setAccountNonExpired(boolean accountNonExpired
) {
120 this.accountNonExpired
= accountNonExpired
;
123 public void setCredentialsNonExpired(boolean credentialsNonExpired
) {
124 this.credentialsNonExpired
= credentialsNonExpired
;
127 public void setAccountNonLocked(boolean accountNonLocked
) {
128 this.accountNonLocked
= accountNonLocked
;
131 protected void setGroups(Set
<Group
> groups
) {
132 this.groups
= groups
;
136 public Set
<Group
> getGroups() {