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