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
|
|
10
|
package eu.etaxonomy.cdm.model.permission;
|
11
|
|
12
|
import javax.persistence.Column;
|
13
|
import javax.persistence.Entity;
|
14
|
import javax.validation.constraints.NotNull;
|
15
|
import javax.xml.bind.annotation.XmlAccessType;
|
16
|
import javax.xml.bind.annotation.XmlAccessorType;
|
17
|
import javax.xml.bind.annotation.XmlElement;
|
18
|
import javax.xml.bind.annotation.XmlRootElement;
|
19
|
import javax.xml.bind.annotation.XmlType;
|
20
|
|
21
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
22
|
import org.springframework.security.core.GrantedAuthority;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
|
26
|
@XmlAccessorType(XmlAccessType.FIELD)
|
27
|
@XmlType(name = "GrantedAuthority", propOrder = { "authority" })
|
28
|
@XmlRootElement(name = "Group")
|
29
|
@Entity
|
30
|
public class GrantedAuthorityImpl extends CdmBase implements GrantedAuthority {
|
31
|
|
32
|
private static final long serialVersionUID = 2651969425860655040L;
|
33
|
private static final Logger logger = LogManager.getLogger(GrantedAuthority.class);
|
34
|
|
35
|
@XmlElement(name = "Authority")
|
36
|
@Column(unique = true)
|
37
|
@NotNull
|
38
|
private String authority;
|
39
|
|
40
|
// ********************** FACTORY *********************************/
|
41
|
|
42
|
public static GrantedAuthorityImpl NewInstance(String authority) {
|
43
|
GrantedAuthorityImpl result = new GrantedAuthorityImpl();
|
44
|
result.setAuthority(authority);
|
45
|
return result;
|
46
|
}
|
47
|
|
48
|
// ************* CONSTRUCTOR ********************/
|
49
|
|
50
|
protected GrantedAuthorityImpl() {
|
51
|
super();
|
52
|
}
|
53
|
|
54
|
// *************** GETTER / SETTER ********************/
|
55
|
|
56
|
@Override
|
57
|
public String getAuthority() {
|
58
|
return authority;
|
59
|
}
|
60
|
|
61
|
public void setAuthority(String authority) {
|
62
|
this.authority = authority;
|
63
|
}
|
64
|
|
65
|
// ******************* METHODS ***********************************/
|
66
|
|
67
|
/**
|
68
|
* @param o
|
69
|
* @return
|
70
|
*/
|
71
|
public int compareTo(Object o) {
|
72
|
if (o instanceof GrantedAuthority) {
|
73
|
return this.authority.compareTo(((GrantedAuthority) o).getAuthority());
|
74
|
}
|
75
|
return 0;
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public boolean equals(Object o) {
|
80
|
if (o instanceof GrantedAuthority) {
|
81
|
if(this.authority == null && ((GrantedAuthority) o).getAuthority() == null) {
|
82
|
return true;
|
83
|
} else {
|
84
|
return this.authority.equals(((GrantedAuthority) o).getAuthority());
|
85
|
}
|
86
|
}
|
87
|
return false;
|
88
|
}
|
89
|
|
90
|
// ******************** TO STRING() **************************/
|
91
|
|
92
|
@Override
|
93
|
public String toString() {
|
94
|
return getAuthority();
|
95
|
}
|
96
|
|
97
|
// ***************** CLONE **********************************/
|
98
|
|
99
|
/**
|
100
|
* Clones <i>this</i> Granted Authority. This is a shortcut that enables to
|
101
|
* create a new instance that differs only slightly from <i>this</i> Granted
|
102
|
* Authority by modifying only some of the attributes.<BR>
|
103
|
|
104
|
*
|
105
|
* @see eu.etaxonomy.cdm.model.common.CdmBase#clone()
|
106
|
* @see java.lang.Object#clone()
|
107
|
*/
|
108
|
@Override
|
109
|
public GrantedAuthorityImpl clone() {
|
110
|
try {
|
111
|
GrantedAuthorityImpl result = (GrantedAuthorityImpl) super.clone();
|
112
|
// no changes to authority
|
113
|
return result;
|
114
|
} catch (CloneNotSupportedException e) {
|
115
|
logger.warn("Object does not implement cloneable");
|
116
|
e.printStackTrace();
|
117
|
return null;
|
118
|
}
|
119
|
}
|
120
|
}
|