01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity;
17:
18: import java.io.Serializable;
19:
20: /**
21: * Basic concrete implementation of a {@link GrantedAuthority}.<p>Stores a <code>String</code> representation of an
22: * authority granted to the {@link Authentication} object.</p>
23: *
24: * @author Ben Alex
25: * @version $Id: GrantedAuthorityImpl.java 1784 2007-02-24 21:00:24Z luke_t $
26: */
27: public class GrantedAuthorityImpl implements GrantedAuthority,
28: Serializable {
29: //~ Instance fields ================================================================================================
30:
31: private static final long serialVersionUID = 1L;
32: private String role;
33:
34: //~ Constructors ===================================================================================================
35:
36: public GrantedAuthorityImpl(String role) {
37: super ();
38: this .role = role;
39: }
40:
41: //~ Methods ========================================================================================================
42:
43: public boolean equals(Object obj) {
44: if (obj instanceof String) {
45: return obj.equals(this .role);
46: }
47:
48: if (obj instanceof GrantedAuthority) {
49: GrantedAuthority attr = (GrantedAuthority) obj;
50:
51: return this .role.equals(attr.getAuthority());
52: }
53:
54: return false;
55: }
56:
57: public String getAuthority() {
58: return this .role;
59: }
60:
61: public int hashCode() {
62: return this .role.hashCode();
63: }
64:
65: public String toString() {
66: return this.role;
67: }
68: }
|