Coverage Report - org.kuali.student.enrollment.class1.lpr.service.decorators.LuiPersonRelationServiceAuthorizationDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
LuiPersonRelationServiceAuthorizationDecorator
0%
0/15
0%
0/2
1.333
 
 1  
 package org.kuali.student.enrollment.class1.lpr.service.decorators;
 2  
 
 3  
 import java.util.*;
 4  
 
 5  
 
 6  
 import org.kuali.rice.kim.api.permission.PermissionService;
 7  
 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
 8  
 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
 9  
 import org.kuali.student.r2.common.exceptions.DisabledIdentifierException;
 10  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 11  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 12  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 13  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 14  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 15  
 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
 16  
 import org.kuali.student.r2.common.infc.HoldsPermissionService;
 17  
 import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo;
 18  
 import org.kuali.student.enrollment.lpr.service.LuiPersonRelationService;
 19  
 import org.kuali.student.enrollment.lpr.service.LuiPersonRelationServiceDecorator;
 20  
 import org.kuali.student.r2.common.dto.ContextInfo;
 21  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 22  
 
 23  
 /**
 24  
  * An example authorization decorator for the {@link LuiPersonRelationService}.
 25  
  * We would like to decorate the createBulkRelationshipsForPerson method here with authorization checks and custom logic
 26  
  * 
 27  
  * @author sambit
 28  
  *
 29  
  */
 30  
 
 31  0
 public class LuiPersonRelationServiceAuthorizationDecorator extends LuiPersonRelationServiceDecorator  implements HoldsPermissionService {
 32  
  
 33  
         private PermissionService permissionService;
 34  
          
 35  
         public static final String ENRLLMENT_NAMESPACE = "KS-Enrollment";
 36  
                 
 37  
         @Override
 38  
         public PermissionService getPermissionService() {
 39  0
                 return permissionService;
 40  
         }
 41  
 
 42  
         @Override
 43  
         public void setPermissionService(PermissionService permissionService) {
 44  0
                 this.permissionService = permissionService;
 45  0
         }
 46  
 
 47  
         
 48  
         @Override
 49  
         public List<String> createBulkRelationshipsForPerson(String personId, List<String> luiIds, String relationState, String luiPersonRelationTypeKey, LuiPersonRelationInfo luiPersonRelationInfo, ContextInfo context) throws DataValidationErrorException, AlreadyExistsException, DoesNotExistException, DisabledIdentifierException, ReadOnlyException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 50  
                 // TODO Auto-generated method stub
 51  0
                 List<String> bulkRelationshipValues = new ArrayList<String>();
 52  0
                 System.out.println("Inside authorization impl for createBulkRelationshipsForPerson" );
 53  
                 //Simulating unknown exception behavior
 54  0
                 if(personId != null){
 55  0
                         bulkRelationshipValues.addAll(getNextDecorator().createBulkRelationshipsForPerson(personId, luiIds, relationState, luiPersonRelationTypeKey, luiPersonRelationInfo, context));
 56  
                 }else {
 57  0
                         throw new NullPointerException("person id is null");
 58  
                 }
 59  0
                 return super.createBulkRelationshipsForPerson(personId, luiIds, relationState, luiPersonRelationTypeKey, luiPersonRelationInfo, context);                
 60  
         }
 61  
 
 62  
     @Override
 63  
     public List<LuiPersonRelationInfo> getLprsByLui(String luiId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 64  0
             return getNextDecorator().getLprsByLui(luiId, context);
 65  
     }
 66  
 
 67  
         @Override
 68  
         public List<ValidationResultInfo> validateLpr(String validationType,
 69  
                         LuiPersonRelationInfo luiPersonRelationInfo,
 70  
                         ContextInfo context)
 71  
                         throws DoesNotExistException,
 72  
                         MissingParameterException,
 73  
                         OperationFailedException,
 74  
                         PermissionDeniedException, 
 75  
                         InvalidParameterException {
 76  0
                 return getNextDecorator().validateLpr(validationType, luiPersonRelationInfo, context);
 77  
         }
 78  
 
 79  
           /**
 80  
      * Fake authorization method.
 81  
      *
 82  
      * @param principal
 83  
      * @param permissionName  the authorization permission
 84  
      * @param qualifier an authorization qualifier
 85  
      * @return true if authorization successful
 86  
      */
 87  
 
 88  
         protected boolean isAuthorized(String principal, String permissionName, String qualifier) {
 89  0
                 Map<String, String> qualifierDetails = new HashMap<String,String>();
 90  0
                 qualifierDetails.put("qualifierKey", qualifier);
 91  0
                 return this.permissionService.isAuthorized(principal,
 92  
                                 ENRLLMENT_NAMESPACE,
 93  
                                 permissionName,
 94  
                                 qualifierDetails);
 95  
         }
 96  
 
 97  
 }