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.springframework.security;
17
18 /**
19 * Abstract superclass for all exceptions related an {@link Authentication} object being invalid for whatever
20 * reason.
21 *
22 * @author Ben Alex
23 * @version $Id: AuthenticationException.java 2653 2008-02-18 20:18:40Z luke_t $
24 */
25 public abstract class AuthenticationException extends SpringSecurityException {
26 //~ Instance fields ================================================================================================
27
28 private Authentication authentication;
29 private Object extraInformation;
30
31 //~ Constructors ===================================================================================================
32
33 /**
34 * Constructs an <code>AuthenticationException</code> with the specified
35 * message and root cause.
36 *
37 * @param msg the detail message
38 * @param t the root cause
39 */
40 public AuthenticationException(String msg, Throwable t) {
41 super(msg, t);
42 }
43
44 /**
45 * Constructs an <code>AuthenticationException</code> with the specified
46 * message and no root cause.
47 *
48 * @param msg the detail message
49 */
50 public AuthenticationException(String msg) {
51 super(msg);
52 }
53
54 public AuthenticationException(String msg, Object extraInformation) {
55 super(msg);
56 this.extraInformation = extraInformation;
57 }
58
59 //~ Methods ========================================================================================================
60
61 /**
62 * The authentication request which this exception corresponds to (may be <code>null</code>)
63 */
64 public Authentication getAuthentication() {
65 return authentication;
66 }
67
68 void setAuthentication(Authentication authentication) {
69 this.authentication = authentication;
70 }
71
72 /**
73 * Any additional information about the exception. Generally a <code>UserDetails</code> object.
74 *
75 * @return extra information or <code>null</code>
76 */
77 public Object getExtraInformation() {
78 return extraInformation;
79 }
80
81 void clearExtraInformation() {
82 this.extraInformation = null;
83 }
84 }