461810302537b997b81b8fdf62b64d47a642610e
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.model
.common
;
12 import java
.util
.Collection
;
13 import java
.util
.HashSet
;
16 import javax
.persistence
.Entity
;
17 import javax
.persistence
.FetchType
;
18 import javax
.persistence
.ManyToMany
;
19 import javax
.persistence
.OneToOne
;
20 import javax
.persistence
.Table
;
21 import javax
.persistence
.Transient
;
22 import javax
.xml
.bind
.annotation
.XmlAccessType
;
23 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
24 import javax
.xml
.bind
.annotation
.XmlElement
;
25 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
26 import javax
.xml
.bind
.annotation
.XmlIDREF
;
27 import javax
.xml
.bind
.annotation
.XmlRootElement
;
28 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
29 import javax
.xml
.bind
.annotation
.XmlTransient
;
30 import javax
.xml
.bind
.annotation
.XmlType
;
32 import org
.apache
.log4j
.Logger
;
33 import org
.hibernate
.annotations
.Cascade
;
34 import org
.hibernate
.annotations
.CascadeType
;
35 import org
.hibernate
.annotations
.NaturalId
;
36 import org
.hibernate
.envers
.Audited
;
37 import org
.hibernate
.envers
.NotAudited
;
40 import org
.hibernate
.search
.annotations
.Field
;
41 import org
.hibernate
.search
.annotations
.Index
;
42 import org
.hibernate
.search
.annotations
.Indexed
;
43 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
44 import org
.springframework
.security
.core
.GrantedAuthority
;
45 import org
.springframework
.security
.core
.userdetails
.UserDetails
;
47 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
49 @XmlAccessorType(XmlAccessType
.FIELD
)
50 @XmlType(name
= "User", propOrder
= {
58 "credentialsNonExpired",
62 @XmlRootElement(name
= "User")
64 @Indexed(index
= "eu.etaxonomy.cdm.model.common.User")
66 @Table(name
= "UserAccount")
67 public class User
extends CdmBase
implements UserDetails
{
68 private static final long serialVersionUID
= 6582191171369439163L;
69 @SuppressWarnings(value
="unused")
70 private static final Logger logger
= Logger
.getLogger(User
.class);
76 public static User
NewInstance(String username
, String pwd
){
77 User user
= new User();
78 user
.setUsername(username
);
79 user
.setPassword(pwd
);
81 user
.setAccountNonExpired(true);
82 user
.setAccountNonLocked(true);
83 user
.setCredentialsNonExpired(true);
84 user
.setEnabled(true);
89 @XmlElement(name
= "Username")
91 @Field(index
= Index
.UN_TOKENIZED
)
92 protected String username
;
95 * a salted, MD5 encoded hash of the plaintext password
97 @XmlElement(name
= "Password")
99 protected String password
;
101 @XmlElement(name
= "EmailAddress")
102 protected String emailAddress
;
104 @XmlElementWrapper(name
= "GrantedAuthorities")
105 @XmlElement(name
= "GrantedAuthority", type
= GrantedAuthorityImpl
.class)
107 @XmlSchemaType(name
= "IDREF")
108 @ManyToMany(fetch
= FetchType
.LAZY
, targetEntity
= GrantedAuthorityImpl
.class)
110 protected Set
<GrantedAuthority
> grantedAuthorities
= new HashSet
<GrantedAuthority
>();
112 @XmlElementWrapper(name
= "Groups")
113 @XmlElement(name
= "Group")
115 @XmlSchemaType(name
= "IDREF")
116 @ManyToMany(fetch
= FetchType
.LAZY
)
117 @IndexedEmbedded(depth
= 1)
119 protected Set
<Group
> groups
= new HashSet
<Group
>();
121 @XmlElement(name
= "Enabled")
122 protected boolean enabled
;
124 @XmlElement(name
= "AccountNonExpired")
125 protected boolean accountNonExpired
;
127 @XmlElement(name
= "CredentialsNonExpired")
128 protected boolean credentialsNonExpired
;
130 @XmlElement(name
= "AccountNonLocked")
131 protected boolean accountNonLocked
;
133 @XmlElement(name
= "Person")
135 @XmlSchemaType(name
= "IDREF")
136 @OneToOne(fetch
= FetchType
.LAZY
)
137 @Cascade({CascadeType
.SAVE_UPDATE
})
138 @IndexedEmbedded(depth
= 1)
139 protected Person person
;
143 private Set
<GrantedAuthority
> authorities
;
145 private void initAuthorities() {
146 authorities
= new HashSet
<GrantedAuthority
>();
147 authorities
.addAll(grantedAuthorities
);
148 for(Group group
: groups
) {
149 authorities
.addAll(group
.getGrantedAuthorities());
154 public Collection
<GrantedAuthority
> getAuthorities() {
155 if(authorities
== null) initAuthorities();
159 public String
getPassword() {
163 public String
getUsername() {
167 public boolean isAccountNonExpired() {
168 return accountNonExpired
;
171 public boolean isAccountNonLocked() {
172 return accountNonLocked
;
175 public boolean isCredentialsNonExpired() {
176 return credentialsNonExpired
;
179 public boolean isEnabled() {
183 public String
getEmailAddress() {
187 public void setEmailAddress(String emailAddress
) {
188 this.emailAddress
= emailAddress
;
191 public Set
<GrantedAuthority
> getGrantedAuthorities() {
192 return grantedAuthorities
;
195 public void setGrantedAuthorities(Set
<GrantedAuthority
> grantedAuthorities
) {
196 this.grantedAuthorities
= grantedAuthorities
;
200 public void setUsername(String username
) {
201 this.username
= username
;
204 public void setPassword(String password
) {
205 this.password
= password
;
208 public void setEnabled(boolean enabled
) {
209 this.enabled
= enabled
;
212 public void setAccountNonExpired(boolean accountNonExpired
) {
213 this.accountNonExpired
= accountNonExpired
;
216 public void setCredentialsNonExpired(boolean credentialsNonExpired
) {
217 this.credentialsNonExpired
= credentialsNonExpired
;
220 public void setAccountNonLocked(boolean accountNonLocked
) {
221 this.accountNonLocked
= accountNonLocked
;
224 protected void setGroups(Set
<Group
> groups
) {
225 this.groups
= groups
;
229 public Set
<Group
> getGroups() {
234 public Person
getPerson() {
238 public void setPerson(Person person
) {
239 this.person
= person
;