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.context;
17:
18: import org.acegisecurity.Authentication;
19:
20: /**
21: * Base implementation of {@link SecurityContext}.<p>Used by default by {@link SecurityContextHolder} and {@link
22: * HttpSessionContextIntegrationFilter}.</p>
23: *
24: * @author Ben Alex
25: * @version $Id: SecurityContextImpl.java 1545 2006-06-14 21:46:21Z luke_t $
26: */
27: public class SecurityContextImpl implements SecurityContext {
28: //~ Instance fields ================================================================================================
29:
30: private Authentication authentication;
31:
32: //~ Methods ========================================================================================================
33:
34: public boolean equals(Object obj) {
35: if (obj instanceof SecurityContextImpl) {
36: SecurityContextImpl test = (SecurityContextImpl) obj;
37:
38: if ((this .getAuthentication() == null)
39: && (test.getAuthentication() == null)) {
40: return true;
41: }
42:
43: if ((this .getAuthentication() != null)
44: && (test.getAuthentication() != null)
45: && this .getAuthentication().equals(
46: test.getAuthentication())) {
47: return true;
48: }
49: }
50:
51: return false;
52: }
53:
54: public Authentication getAuthentication() {
55: return authentication;
56: }
57:
58: public int hashCode() {
59: if (this .authentication == null) {
60: return -1;
61: } else {
62: return this .authentication.hashCode();
63: }
64: }
65:
66: public void setAuthentication(Authentication authentication) {
67: this .authentication = authentication;
68: }
69:
70: public String toString() {
71: StringBuffer sb = new StringBuffer();
72: sb.append(super .toString());
73:
74: if (this .authentication == null) {
75: sb.append(": Null authentication");
76: } else {
77: sb.append(": Authentication: ").append(this.authentication);
78: }
79:
80: return sb.toString();
81: }
82: }
|