| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| SecurityContextImpl |
|
| 2.6;2.6 |
| 1 | /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
| 2 | * |
|
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 4 | * you may not use this file except in compliance with the License. |
|
| 5 | * You may obtain a copy of the License at |
|
| 6 | * |
|
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 8 | * |
|
| 9 | * 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 | /** |
|
| 22 | * Base implementation of {@link SecurityContext}.<p>Used by default by {@link SecurityContextHolder} and {@link |
|
| 23 | * HttpSessionContextIntegrationFilter}.</p> |
|
| 24 | * |
|
| 25 | * @author Ben Alex |
|
| 26 | * @version $Id: SecurityContextImpl.java 1545 2006-06-14 21:46:21Z luke_t $ |
|
| 27 | */ |
|
| 28 | 190 | public class SecurityContextImpl implements SecurityContext { |
| 29 | //~ Instance fields ================================================================================================ |
|
| 30 | ||
| 31 | private Authentication authentication; |
|
| 32 | ||
| 33 | //~ Methods ======================================================================================================== |
|
| 34 | ||
| 35 | public boolean equals(Object obj) { |
|
| 36 | 8 | if (obj instanceof SecurityContextImpl) { |
| 37 | 8 | SecurityContextImpl test = (SecurityContextImpl) obj; |
| 38 | ||
| 39 | 8 | if ((this.getAuthentication() == null) && (test.getAuthentication() == null)) { |
| 40 | 6 | return true; |
| 41 | } |
|
| 42 | ||
| 43 | 2 | if ((this.getAuthentication() != null) && (test.getAuthentication() != null) |
| 44 | && this.getAuthentication().equals(test.getAuthentication())) { |
|
| 45 | 1 | return true; |
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| 49 | 1 | return false; |
| 50 | } |
|
| 51 | ||
| 52 | public Authentication getAuthentication() { |
|
| 53 | 7939 | return authentication; |
| 54 | } |
|
| 55 | ||
| 56 | public int hashCode() { |
|
| 57 | 23 | if (this.authentication == null) { |
| 58 | 11 | return -1; |
| 59 | } else { |
|
| 60 | 12 | return this.authentication.hashCode(); |
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| 64 | public void setAuthentication(Authentication authentication) { |
|
| 65 | 210 | this.authentication = authentication; |
| 66 | 210 | } |
| 67 | ||
| 68 | public String toString() { |
|
| 69 | 2 | StringBuffer sb = new StringBuffer(); |
| 70 | 2 | sb.append(super.toString()); |
| 71 | ||
| 72 | 2 | if (this.authentication == null) { |
| 73 | 0 | sb.append(": Null authentication"); |
| 74 | } else { |
|
| 75 | 2 | sb.append(": Authentication: ").append(this.authentication); |
| 76 | } |
|
| 77 | ||
| 78 | 2 | return sb.toString(); |
| 79 | } |
|
| 80 | } |