Coverage Report - org.kuali.rice.kim.service.support.impl.PrincipalDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PrincipalDerivedRoleTypeServiceImpl
0%
0/23
0%
0/16
3.75
 
 1  
 /*
 2  
  * Copyright 2008 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.kim.service.support.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.core.util.AttributeSet;
 22  
 import org.kuali.rice.kim.api.entity.principal.Principal;
 23  
 import org.kuali.rice.kim.api.services.IdentityManagementService;
 24  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 25  
 import org.kuali.rice.kim.bo.Role;
 26  
 
 27  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo;
 28  
 import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
 29  
 import org.kuali.rice.kim.util.KimConstants;
 30  
 
 31  
 
 32  
 /**
 33  
  * This is a description of what this class does - kellerj don't forget to fill this in. 
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  *
 37  
  */
 38  0
 public class PrincipalDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase {
 39  
         
 40  
         private IdentityManagementService identityManagementService;
 41  
         
 42  
         {
 43  0
                 requiredAttributes.add( KimConstants.AttributeConstants.PRINCIPAL_ID );
 44  0
                 checkRequiredAttributes = false;
 45  0
         }
 46  
         
 47  
         /**
 48  
          * @see org.kuali.rice.kim.service.support.impl.KimTypeServiceBase#performMatch(org.kuali.rice.core.util.AttributeSet, org.kuali.rice.core.util.AttributeSet)
 49  
          */
 50  
         @Override
 51  
         public boolean performMatch(AttributeSet inputAttributeSet, AttributeSet storedAttributeSet) {
 52  0
                 return true;
 53  
         }
 54  
 
 55  
         /**
 56  
          * Since this is potentially the entire set of users, just check the qualification for the user we are interested in and return it.
 57  
          * 
 58  
          * @see org.kuali.rice.kim.service.support.impl.RoleTypeServiceBase#getRoleMembersFromApplicationRole(String, String, AttributeSet)
 59  
          */
 60  
         @Override
 61  
     public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, AttributeSet qualification) {
 62  0
                 ArrayList<RoleMembershipInfo> tempIdList = new ArrayList<RoleMembershipInfo>();
 63  0
                 if ( qualification == null || qualification.isEmpty() ) {
 64  0
                         return tempIdList;
 65  
                 }
 66  0
                 qualification = translateInputAttributeSet(qualification);
 67  
                 // check that the principal ID is not null
 68  0
                 String principalId = qualification.get( KimConstants.AttributeConstants.PRINCIPAL_ID );
 69  0
                 if ( hasApplicationRole(principalId, null, namespaceCode, roleName, qualification)) {
 70  0
                 tempIdList.add( new RoleMembershipInfo(null/*roleId*/, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) );
 71  
                 }
 72  0
                 return tempIdList;
 73  
         }
 74  
         
 75  
         @Override
 76  
         public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, AttributeSet qualification) {
 77  
         // check that the principal exists and is active
 78  0
         Principal principal = getIdentityManagementService().getPrincipal( principalId );
 79  0
         if ( principal == null || !principal.isActive() ) {
 80  0
             return false;
 81  
         }
 82  
         // check that the entity is active
 83  0
         KimEntityDefaultInfo entity = getIdentityManagementService().getEntityDefaultInfo( principal.getEntityId() );
 84  0
         if ( entity == null || !entity.isActive() ) {
 85  0
             return false;
 86  
         }
 87  0
         return true;
 88  
         }
 89  
         
 90  
         protected IdentityManagementService getIdentityManagementService() {
 91  0
                 if ( identityManagementService == null ) {
 92  0
                         identityManagementService = KimApiServiceLocator.getIdentityManagementService();
 93  
                 }
 94  0
                 return identityManagementService;
 95  
         }
 96  
 }