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