Coverage Report - org.kuali.rice.krad.exception.AuthorizationException
 
Classes in this File Line Coverage Branch Coverage Complexity
AuthorizationException
0%
0/15
0%
0/4
1.25
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krad.exception;
 17  
 
 18  
 import org.kuali.rice.core.api.exception.KualiException;
 19  
 import org.kuali.rice.core.api.util.RiceKeyConstants;
 20  
 
 21  
 import java.util.Collections;
 22  
 import java.util.Map;
 23  
 
 24  
 /**
 25  
  * This class represents an exception that is thrown when a given user is not authorized to take the given action on the given
 26  
  * target type.
 27  
  */
 28  
 public class AuthorizationException extends KualiException {
 29  
     private static final long serialVersionUID = -3874239711783179351L;
 30  
     protected final String userId;
 31  
     protected final String action;
 32  
     protected final String targetType;
 33  
     protected final Map<String, Object> additionalDetails;
 34  
 
 35  
     public AuthorizationException(String userId, String action, String targetType) {
 36  0
         this(userId, action, targetType, Collections.<String, Object>emptyMap());
 37  0
     }
 38  
     
 39  
     /**
 40  
      * Constructs a exception with a message from the passed in information.
 41  
      * 
 42  
      * @param userId the userid of the user who failed authorization
 43  
      * @param action the action the user was trying to take
 44  
      * @param targetType what the user was trying to take action on
 45  
      * @param additionalDetails additional details about the authorization failure to be passed in and added to the exception message (ex: permission name, qualifiers, etc.)
 46  
      */
 47  
     public AuthorizationException(String userId, String action, String targetType, Map<String, Object> additionalDetails) {
 48  0
         this(userId, action, targetType,
 49  
                         "user '" + userId + "' is not authorized to take action '" + action + "' on targets of type '" + targetType + "'" + (additionalDetails != null && !additionalDetails.isEmpty() ? " Additional Details : " + additionalDetails : ""),
 50  
                         additionalDetails);
 51  0
     }
 52  
 
 53  
     /** allows you to construct the exception message manually. */
 54  
     public AuthorizationException(String userId, String action, String targetType, String message, Map<String, Object> additionalDetails) {
 55  0
         super(message);
 56  
 
 57  0
         this.userId = userId;
 58  0
         this.action = action;
 59  0
         this.targetType = targetType;
 60  0
         this.additionalDetails = additionalDetails;
 61  0
     }
 62  
 
 63  
     public Map<String, Object> getAdditionalDetails() {
 64  0
         return additionalDetails;
 65  
     }
 66  
 
 67  
     public String getUserId() {
 68  0
         return userId;
 69  
     }
 70  
 
 71  
     public String getAction() {
 72  0
         return action;
 73  
     }
 74  
 
 75  
     public String getTargetType() {
 76  0
         return targetType;
 77  
     }
 78  
 
 79  
     /**
 80  
      * @return message key used by Struts to select the error message to be displayed
 81  
      */
 82  
     public String getErrorMessageKey() {
 83  0
         return RiceKeyConstants.AUTHORIZATION_ERROR_GENERAL;
 84  
     }
 85  
 }