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