View Javadoc

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.event.authorization;
17  
18  import org.acegisecurity.AccessDeniedException;
19  import org.acegisecurity.Authentication;
20  import org.acegisecurity.ConfigAttributeDefinition;
21  
22  
23  /**
24   * Indicates a secure object invocation failed because the principal could not
25   * be authorized for the request.
26   *
27   * <p>This event might be thrown as a result of either an
28   * {@link org.acegisecurity.AccessDecisionManager AccessDecisionManager} or an
29   * {@link org.acegisecurity.AfterInvocationManager AfterInvocationManager}.
30   *
31   * @author Ben Alex
32   * @version $Id: AuthorizationFailureEvent.java 1784 2007-02-24 21:00:24Z luke_t $
33   */
34  public class AuthorizationFailureEvent extends AbstractAuthorizationEvent {
35      //~ Instance fields ================================================================================================
36  
37      private AccessDeniedException accessDeniedException;
38      private Authentication authentication;
39      private ConfigAttributeDefinition configAttributeDefinition;
40  
41      //~ Constructors ===================================================================================================
42  
43      /**
44       * Construct the event.
45       *
46       * @param secureObject the secure object
47       * @param configAttribs that apply to the secure object
48       * @param authentication that was found in the <code>SecurityContextHolder</code>
49       * @param accessDeniedException that was returned by the
50       *        <code>AccessDecisionManager</code>
51       *
52       * @throws IllegalArgumentException if any null arguments are presented.
53       */
54      public AuthorizationFailureEvent(Object secureObject, ConfigAttributeDefinition configAttribs,
55          Authentication authentication, AccessDeniedException accessDeniedException) {
56          super(secureObject);
57  
58          if ((configAttribs == null) || (authentication == null) || (accessDeniedException == null)) {
59              throw new IllegalArgumentException("All parameters are required and cannot be null");
60          }
61  
62          this.configAttributeDefinition = configAttribs;
63          this.authentication = authentication;
64          this.accessDeniedException = accessDeniedException;
65      }
66  
67      //~ Methods ========================================================================================================
68  
69      public AccessDeniedException getAccessDeniedException() {
70          return accessDeniedException;
71      }
72  
73      public Authentication getAuthentication() {
74          return authentication;
75      }
76  
77      public ConfigAttributeDefinition getConfigAttributeDefinition() {
78          return configAttributeDefinition;
79      }
80  }