1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.acegisecurity.context;
16
17 import org.acegisecurity.Authentication;
18
19
20 /***
21 * Base implementation of {@link SecurityContext}.
22 *
23 * <p>
24 * Used by default by {@link SecurityContextHolder} and {@link HttpSessionContextIntegrationFilter}.
25 * </p>
26 *
27 * @author Ben Alex
28 * @version $Id: SecurityContextImpl.java,v 1.4 2005/11/17 00:55:49 benalex Exp $
29 */
30 public class SecurityContextImpl implements SecurityContext {
31 private Authentication authentication;
32
33 public void setAuthentication(Authentication authentication) {
34 this.authentication = authentication;
35 }
36
37 public Authentication getAuthentication() {
38 return authentication;
39 }
40
41 public boolean equals(Object obj) {
42 if (obj instanceof SecurityContextImpl) {
43 SecurityContextImpl test = (SecurityContextImpl) obj;
44
45 if ((this.getAuthentication() == null) &&
46 (test.getAuthentication() == null)) {
47 return true;
48 }
49
50 if ((this.getAuthentication() != null) &&
51 (test.getAuthentication() != null) &&
52 this.getAuthentication().equals(test.getAuthentication())) {
53 return true;
54 }
55 }
56
57 return false;
58 }
59
60 public String toString() {
61 StringBuffer sb = new StringBuffer();
62 sb.append(super.toString());
63
64 if (this.authentication == null) {
65 sb.append(": Null authentication");
66 } else {
67 sb.append(": Authentication: " + this.authentication);
68 }
69
70 return sb.toString();
71 }
72
73 public int hashCode() {
74 if (this.authentication == null) {
75 return -1;
76 } else {
77 return this.authentication.hashCode();
78 }
79 }
80 }