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: package org.acegisecurity.acls.sid;
16:
17: import org.acegisecurity.GrantedAuthority;
18:
19: import org.springframework.util.Assert;
20:
21: /**
22: * Represents a <code>GrantedAuthority</code> as a <code>Sid</code>.<p>This is a basic implementation that simply
23: * uses the <code>String</code>-based principal for <code>Sid</code> comparison. More complex principal objects may
24: * wish to provide an alternative <code>Sid</code> implementation that uses some other identifier.</p>
25: *
26: * @author Ben Alex
27: * @version $Id: GrantedAuthoritySid.java 1754 2006-11-17 02:01:21Z benalex $
28: */
29: public class GrantedAuthoritySid implements Sid {
30: //~ Instance fields ================================================================================================
31:
32: private String grantedAuthority;
33:
34: //~ Constructors ===================================================================================================
35:
36: public GrantedAuthoritySid(String grantedAuthority) {
37: Assert.hasText(grantedAuthority, "GrantedAuthority required");
38: this .grantedAuthority = grantedAuthority;
39: }
40:
41: public GrantedAuthoritySid(GrantedAuthority grantedAuthority) {
42: Assert.notNull(grantedAuthority, "GrantedAuthority required");
43: Assert
44: .notNull(
45: grantedAuthority.getAuthority(),
46: "This Sid is only compatible with GrantedAuthoritys that provide a non-null getAuthority()");
47: this .grantedAuthority = grantedAuthority.getAuthority();
48: }
49:
50: //~ Methods ========================================================================================================
51:
52: public boolean equals(Object object) {
53: if ((object == null)
54: || !(object instanceof GrantedAuthoritySid)) {
55: return false;
56: }
57:
58: // Delegate to getGrantedAuthority() to perform actual comparison (both should be identical)
59: return ((GrantedAuthoritySid) object).getGrantedAuthority()
60: .equals(this .getGrantedAuthority());
61: }
62:
63: public String getGrantedAuthority() {
64: return grantedAuthority;
65: }
66:
67: public String toString() {
68: return "GrantedAuthoritySid[" + this .grantedAuthority + "]";
69: }
70: }
|