1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.common;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
|
14
|
import javax.persistence.Entity;
|
15
|
import javax.persistence.FetchType;
|
16
|
import javax.persistence.ManyToMany;
|
17
|
import javax.persistence.Table;
|
18
|
import javax.xml.bind.annotation.XmlAccessType;
|
19
|
import javax.xml.bind.annotation.XmlAccessorType;
|
20
|
import javax.xml.bind.annotation.XmlElement;
|
21
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
22
|
import javax.xml.bind.annotation.XmlIDREF;
|
23
|
import javax.xml.bind.annotation.XmlRootElement;
|
24
|
import javax.xml.bind.annotation.XmlSchemaType;
|
25
|
import javax.xml.bind.annotation.XmlType;
|
26
|
|
27
|
import org.hibernate.annotations.NaturalId;
|
28
|
import org.hibernate.search.annotations.Field;
|
29
|
import org.hibernate.search.annotations.Index;
|
30
|
import org.hibernate.search.annotations.Indexed;
|
31
|
import org.springframework.security.core.GrantedAuthority;
|
32
|
|
33
|
@XmlAccessorType(XmlAccessType.FIELD)
|
34
|
@XmlType(name = "Group", propOrder = {
|
35
|
"name",
|
36
|
"members",
|
37
|
"grantedAuthorities"
|
38
|
})
|
39
|
@XmlRootElement(name = "Group")
|
40
|
@Entity
|
41
|
@Indexed(index = "eu.etaxonomy.cdm.model.common.Group")
|
42
|
@Table(name = "PermissionGroup")
|
43
|
public class Group extends CdmBase {
|
44
|
private static final long serialVersionUID = 7216686200093054648L;
|
45
|
|
46
|
@XmlElement(name = "Name")
|
47
|
@NaturalId
|
48
|
@Field(index = Index.UN_TOKENIZED)
|
49
|
protected String name;
|
50
|
|
51
|
@XmlElementWrapper(name = "Members")
|
52
|
@XmlElement(name = "Member")
|
53
|
@XmlIDREF
|
54
|
@XmlSchemaType(name = "IDREF")
|
55
|
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "groups")
|
56
|
protected Set<User> members = new HashSet<User>();
|
57
|
|
58
|
@XmlElementWrapper(name = "GrantedAuthorities")
|
59
|
@XmlElement(name = "GrantedAuthority", type = GrantedAuthorityImpl.class)
|
60
|
@XmlIDREF
|
61
|
@XmlSchemaType(name = "IDREF")
|
62
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = GrantedAuthorityImpl.class)
|
63
|
protected Set <GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>();
|
64
|
|
65
|
public Set<GrantedAuthority> getGrantedAuthorities() {
|
66
|
return grantedAuthorities;
|
67
|
}
|
68
|
|
69
|
public void setName(String name) {
|
70
|
this.name = name;
|
71
|
}
|
72
|
|
73
|
public String getName() {
|
74
|
return name;
|
75
|
}
|
76
|
|
77
|
public Set<User> getMembers() {
|
78
|
return members;
|
79
|
}
|
80
|
|
81
|
public boolean addMember(User user) {
|
82
|
user.getGroups().add(this);
|
83
|
return this.members.add(user);
|
84
|
}
|
85
|
|
86
|
public boolean removeMember(User user) {
|
87
|
if(members.contains(user)) {
|
88
|
user.getGroups().remove(this);
|
89
|
return this.members.remove(user);
|
90
|
} else {
|
91
|
return false;
|
92
|
}
|
93
|
}
|
94
|
}
|