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