Coverage Report - org.kuali.student.enrollment.lpr.service.adapter.authorization.LuiPersonRelationAuthorizationAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
LuiPersonRelationAuthorizationAdapter
0%
0/20
0%
0/8
2.714
 
 1  
 /*
 2  
  * Copyright 2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the
 5  
  * "License"); you may not use this file except in compliance with the
 6  
  * License.  You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.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
 13  
  * implied.  See the License for the specific language governing
 14  
  * permissions and limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.student.enrollment.lpr.service.adapter.authorization;
 18  
 
 19  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 20  
 import org.kuali.student.common.exceptions.VersionMismatchException;
 21  
 import org.kuali.student.common.exceptions.MissingParameterException;
 22  
 import org.kuali.student.common.exceptions.OperationFailedException;
 23  
 import org.kuali.student.common.exceptions.DataValidationErrorException;
 24  
 import org.kuali.student.common.exceptions.PermissionDeniedException;
 25  
 import org.kuali.student.common.exceptions.DisabledIdentifierException;
 26  
 import org.kuali.student.common.exceptions.AlreadyExistsException;
 27  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 28  
 import org.kuali.student.common.exceptions.ReadOnlyException;
 29  
 import org.kuali.student.common.exceptions.*;
 30  
 
 31  
 
 32  
 import java.util.List;
 33  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 34  
 import org.kuali.rice.kim.service.PermissionService;
 35  
 import org.kuali.student.common.dto.ContextInfo;
 36  
 import org.kuali.student.common.dto.StatusInfo;
 37  
 import org.kuali.student.common.infc.HoldsPermissionService;
 38  
 import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo;
 39  
 import org.kuali.student.enrollment.lpr.mock.LuiPersonRelationServiceAdapter;
 40  
 
 41  
 
 42  
 
 43  
 /**
 44  
  * A example of an authorization adapter that extends the adapter
 45  
  * template and inserts some example authorization calls.
 46  
  *
 47  
  * @Author Tom
 48  
  */
 49  
 
 50  0
 public class LuiPersonRelationAuthorizationAdapter
 51  
         extends LuiPersonRelationServiceAdapter
 52  
         implements HoldsPermissionService
 53  
 {
 54  
 
 55  
         private PermissionService permissionService;
 56  
 
 57  
         @Override
 58  
         public PermissionService getPermissionService() {
 59  0
                 return permissionService;
 60  
         }
 61  
 
 62  
         @Override
 63  
         public void setPermissionService(PermissionService permissionService) {
 64  0
                 this.permissionService = permissionService;
 65  0
         }
 66  
 
 67  
 
 68  
     /**
 69  
      * Creates relation between the specified Person and LUI.
 70  
      *
 71  
      * @param personId              Person Identifier
 72  
      * @param luiId                 LUI Identifier
 73  
      * @param luiPersonRelationType Type of LUI to Person Relation
 74  
      * @param luiPersonRelationInfo Information required to create the
 75  
      *                              LUI Person relation
 76  
      * @param context               Context information containing the principalId
 77  
      *                              and locale information about the caller of service
 78  
      *                              operation
 79  
      * @return Structure containing LUI Person relation identifiers
 80  
      * @throws AlreadyExistsException      relation already exists
 81  
      * @throws DoesNotExistException       personId, luiId, relationState,
 82  
      *                                     luiPersonRelationType does not exist
 83  
      * @throws DisabledIdentifierException personId found, but has
 84  
      *                                     been retired
 85  
      * @throws InvalidParameterException   invalid personId, luiId,
 86  
      *                                     relationState, luiPersonRelationType,
 87  
      *                                     luiPersonRelationInfo
 88  
      * @throws MissingParameterException   missing personId, luiId,
 89  
      *                                     relationState, luiPersonRelationType,
 90  
      *                                     luiPersonRelationInfo
 91  
      * @throws OperationFailedException    unable to complete request
 92  
      * @throws PermissionDeniedException   authorization failure
 93  
      */
 94  
 
 95  
     @Override
 96  
     public String createLuiPersonRelation(String personId, String luiId, String luiPersonRelationType, LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context)
 97  
             throws DataValidationErrorException, AlreadyExistsException, DoesNotExistException, DisabledIdentifierException, ReadOnlyException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 98  
 
 99  0
         if (isAuthorized(context.getPrincipalId(), "create lpr", null)) {
 100  0
             return (getLprService().createLuiPersonRelation(personId, luiId, luiPersonRelationType, luiPersonRelationInfo, context));
 101  
         } else {
 102  0
             throw new PermissionDeniedException("unauthorized to create LPR");
 103  
         }
 104  
     }
 105  
 
 106  
 
 107  
     /**
 108  
      * Creates bulk relationships for one specified person. This is an
 109  
      * all or nothing transaction - any error will invalidate the
 110  
      * entire transaction.
 111  
      *
 112  
      * @param personId              Identifier for Person
 113  
      * @param luiIdList             Simple list of LUI identifiers
 114  
      * @param relationState         Relation state
 115  
      * @param luiPersonRelationType Type of LUI Person relation
 116  
      * @param luiPersonRelationInfo Information required to create the
 117  
      *                              LUI Person relation
 118  
      * @param context               Context information containing the principalId
 119  
      *                              and locale information about the caller of service
 120  
      *                              operation
 121  
      * @return Structure containing LUI Person relation identifiers
 122  
      * @throws AlreadyExistsException      relation already exists
 123  
      * @throws DoesNotExistException       personId, luiId, relationState,
 124  
      *                                     luiPersonRelationType does not exist
 125  
      * @throws DisabledIdentifierException personId found, but has
 126  
      *                                     been retired
 127  
      * @throws InvalidParameterException   invalid personId, luiId,
 128  
      *                                     relationState, luiPersonRelationType,
 129  
      *                                     luiPersonRelationInfo
 130  
      * @throws MissingParameterException   missing personId, luiId,
 131  
      *                                     relationState, luiPersonRelationType,
 132  
      *                                     luiPersonRelationInfo
 133  
      * @throws OperationFailedException    unable to complete request
 134  
      * @throws PermissionDeniedException   authorization failure
 135  
      */
 136  
 
 137  
     @Override
 138  
     public List<String> createBulkRelationshipsForPerson(String personId, List<String> luiIdList, String relationState, String luiPersonRelationType, LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context)
 139  
             throws DataValidationErrorException, AlreadyExistsException, DoesNotExistException, DisabledIdentifierException, ReadOnlyException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 140  
 
 141  0
         if (isAuthorized(context.getPrincipalId(), "create lpr", null)) {
 142  0
             return (getLprService().createBulkRelationshipsForPerson(personId, luiIdList, relationState, luiPersonRelationType, luiPersonRelationInfo, context));
 143  
         } else {
 144  0
             throw new PermissionDeniedException("unauthorized to create LPR");
 145  
         }
 146  
     }
 147  
 
 148  
 
 149  
     /**
 150  
      * Update relation between Person and LUI.
 151  
      *
 152  
      * @param luiPersonRelationId   Identifier for the LUI Person
 153  
      *                              Relation
 154  
      * @param luiPersonRelationInfo Changed information about the LUI
 155  
      *                              Person Relation
 156  
      * @param context               Context information containing the principalId
 157  
      *                              and locale information about the caller of service
 158  
      *                              operation
 159  
      * @return Updated information about the LUI Person Relation
 160  
      * @throws DoesNotExistException     luiPersonRelationId does not
 161  
      *                                   exist
 162  
      * @throws InvalidParameterException invalid luiPersonRelationId,
 163  
      *                                   luiPersonRelationInfo
 164  
      * @throws MissingParameterException missing luiPersonRelationId,
 165  
      *                                   luiPersonRelationInfo
 166  
      * @throws ReadOnlyException         attempt to update a read only attribute
 167  
      * @throws OperationFailedException  unable to complete request
 168  
      * @throws PermissionDeniedException authorization failure
 169  
      */
 170  
 
 171  
     @Override
 172  
     public LuiPersonRelationInfo updateLuiPersonRelation(String luiPersonRelationId, LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context)
 173  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, ReadOnlyException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 174  
 
 175  0
         if (isAuthorized(context.getPrincipalId(), "update lpr", luiPersonRelationId)) {
 176  0
             return (getLprService().updateLuiPersonRelation(luiPersonRelationId, luiPersonRelationInfo, context));
 177  
         } else {
 178  0
             throw new PermissionDeniedException("unauthorized to update LPR " + luiPersonRelationId);
 179  
         }
 180  
     }
 181  
 
 182  
 
 183  
     /**
 184  
      * Deletes relation between the specified Person and LUI.
 185  
      *
 186  
      * @param luiPersonRelationId Identifier for the LUI Person Relation
 187  
      * @param context             Context information containing the principalId
 188  
      *                            and locale information about the caller of service
 189  
      *                            operation
 190  
      * @return status of the operation (success, failed)
 191  
      * @throws DoesNotExistException     luiPersonRelationId does not exist
 192  
      * @throws InvalidParameterException invalid luiPersonRelationId
 193  
      * @throws MissingParameterException missing luiPersonRelationId
 194  
      * @throws OperationFailedException  unable to complete request
 195  
      * @throws PermissionDeniedException authorization failure
 196  
      */
 197  
 
 198  
     @Override
 199  
     public StatusInfo deleteLuiPersonRelation(String luiPersonRelationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 200  
 
 201  0
         if (isAuthorized(context.getPrincipalId(), "delete lpr", luiPersonRelationId)) {
 202  0
             return (getLprService().deleteLuiPersonRelation(luiPersonRelationId, context));
 203  
         } else {
 204  0
             throw new PermissionDeniedException("unauthorized to delete LPR " + luiPersonRelationId);
 205  
         }
 206  
     }
 207  
 
 208  
 
 209  
    public static final String ENRLLMENT_NAMESPACE = "KS-Enrollment";
 210  
     /**
 211  
      * Fake authorization method.
 212  
      *
 213  
      * @param principal
 214  
      * @param permissionName  the authorization permission
 215  
      * @param qualifier an authorization qualifier
 216  
      * @return true if authorization successful
 217  
      */
 218  
 
 219  
         protected boolean isAuthorized(String principal, String permissionName, String qualifier) {
 220  0
                 AttributeSet permissionDetails = null;
 221  0
                 AttributeSet qualifierDetails = new AttributeSet();
 222  0
                 qualifierDetails.put("qualifierKey", qualifier);
 223  0
                 return this.permissionService.isAuthorized(principal,
 224  
                                 ENRLLMENT_NAMESPACE,
 225  
                                 permissionName,
 226  
                                 permissionDetails,
 227  
                                 qualifierDetails);
 228  
         }
 229  
 }