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
.HashSet
;
14 import java
.util
.TreeSet
;
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
;
38 import org
.springframework
.security
.GrantedAuthority
;
39 import org
.springframework
.security
.userdetails
.UserDetails
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
43 @XmlAccessorType(XmlAccessType
.FIELD
)
44 @XmlType(name
= "User", propOrder
= {
52 "credentialsNonExpired",
56 @XmlRootElement(name
= "User")
59 @Table(name
= "UserAccount")
60 public class User
extends CdmBase
implements UserDetails
{
61 private static final long serialVersionUID
= 6582191171369439163L;
62 @SuppressWarnings(value
="unused")
63 private static final Logger logger
= Logger
.getLogger(User
.class);
65 public static User
NewInstance(String username
, String pwd
){
66 User user
= new User();
67 user
.setUsername(username
);
68 user
.setPassword(pwd
);
72 @XmlElement(name
= "Username")
74 protected String username
;
77 * a salted, MD5 encoded hash of the plaintext password
79 @XmlElement(name
= "Password")
81 protected String password
;
83 @XmlElement(name
= "EmailAddress")
84 protected String emailAddress
;
86 @XmlElementWrapper(name
= "GrantedAuthorities")
87 @XmlElement(name
= "GrantedAuthority", type
= GrantedAuthorityImpl
.class)
89 @XmlSchemaType(name
= "IDREF")
90 @ManyToMany(fetch
= FetchType
.LAZY
, targetEntity
= GrantedAuthorityImpl
.class)
92 protected Set
<GrantedAuthority
> grantedAuthorities
= new HashSet
<GrantedAuthority
>();
94 @XmlElementWrapper(name
= "Groups")
95 @XmlElement(name
= "Group")
97 @XmlSchemaType(name
= "IDREF")
98 @ManyToMany(fetch
= FetchType
.LAZY
)
100 protected Set
<Group
> groups
= new HashSet
<Group
>();
102 @XmlElement(name
= "Enabled")
103 protected boolean enabled
;
105 @XmlElement(name
= "AccountNonExpired")
106 protected boolean accountNonExpired
;
108 @XmlElement(name
= "CredentialsNonExpired")
109 protected boolean credentialsNonExpired
;
111 @XmlElement(name
= "AccountNonLocked")
112 protected boolean accountNonLocked
;
114 @XmlElement(name
= "Person")
116 @XmlSchemaType(name
= "IDREF")
117 @OneToOne(fetch
= FetchType
.LAZY
)
118 @Cascade({CascadeType
.SAVE_UPDATE
})
119 protected Person person
;
123 private GrantedAuthority
[] authorities
;
125 private void initAuthorities() {
126 Set
<GrantedAuthority
> allAuthorities
= new TreeSet
<GrantedAuthority
>();
127 allAuthorities
.addAll(grantedAuthorities
);
128 for(Group group
: groups
) {
129 allAuthorities
.addAll(group
.getGrantedAuthorities());
132 authorities
= allAuthorities
.toArray(new GrantedAuthority
[allAuthorities
.size()]);
136 public GrantedAuthority
[] getAuthorities() {
137 if(authorities
== null) initAuthorities();
141 public String
getPassword() {
145 public String
getUsername() {
149 public boolean isAccountNonExpired() {
150 return accountNonExpired
;
153 public boolean isAccountNonLocked() {
154 return accountNonLocked
;
157 public boolean isCredentialsNonExpired() {
158 return credentialsNonExpired
;
161 public boolean isEnabled() {
165 public String
getEmailAddress() {
169 public void setEmailAddress(String emailAddress
) {
170 this.emailAddress
= emailAddress
;
173 public Set
<GrantedAuthority
> getGrantedAuthorities() {
174 return grantedAuthorities
;
177 public void setGrantedAuthorities(Set
<GrantedAuthority
> grantedAuthorities
) {
178 this.grantedAuthorities
= grantedAuthorities
;
182 public void setUsername(String username
) {
183 this.username
= username
;
186 public void setPassword(String password
) {
187 this.password
= password
;
190 public void setEnabled(boolean enabled
) {
191 this.enabled
= enabled
;
194 public void setAccountNonExpired(boolean accountNonExpired
) {
195 this.accountNonExpired
= accountNonExpired
;
198 public void setCredentialsNonExpired(boolean credentialsNonExpired
) {
199 this.credentialsNonExpired
= credentialsNonExpired
;
202 public void setAccountNonLocked(boolean accountNonLocked
) {
203 this.accountNonLocked
= accountNonLocked
;
206 protected void setGroups(Set
<Group
> groups
) {
207 this.groups
= groups
;
211 public Set
<Group
> getGroups() {
215 public Person
getPerson() {
219 public void setPerson(Person person
) {
220 this.person
= person
;