1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity;
17
18 import java.io.Serializable;
19
20
21 /***
22 * Basic concrete implementation of a {@link GrantedAuthority}.
23 *
24 * <p>
25 * Stores a <code>String</code> representation of an authority granted to the
26 * {@link Authentication} object.
27 * </p>
28 *
29 * @author Ben Alex
30 * @version $Id: GrantedAuthorityImpl.java,v 1.5 2005/11/17 00:55:49 benalex Exp $
31 */
32 public class GrantedAuthorityImpl implements GrantedAuthority, Serializable {
33
34
35 private String role;
36
37
38
39 public GrantedAuthorityImpl(String role) {
40 super();
41 this.role = role;
42 }
43
44 protected GrantedAuthorityImpl() {
45 throw new IllegalArgumentException("Cannot use default constructor");
46 }
47
48
49
50 public String getAuthority() {
51 return this.role;
52 }
53
54 public boolean equals(Object obj) {
55 if (obj instanceof String) {
56 return obj.equals(this.role);
57 }
58
59 if (obj instanceof GrantedAuthority) {
60 GrantedAuthority attr = (GrantedAuthority) obj;
61
62 return this.role.equals(attr.getAuthority());
63 }
64
65 return false;
66 }
67
68 public int hashCode() {
69 return this.role.hashCode();
70 }
71
72 public String toString() {
73 return this.role;
74 }
75 }