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