Coverage Report - org.kuali.rice.kns.kim.role.PrincipalDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PrincipalDerivedRoleTypeServiceImpl
0%
0/40
0%
0/34
5.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.kns.kim.role;
 17  
 
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 21  
 import org.kuali.rice.core.api.membership.MemberType;
 22  
 import org.kuali.rice.kim.api.KimConstants;
 23  
 import org.kuali.rice.kim.api.identity.IdentityService;
 24  
 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
 25  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 26  
 import org.kuali.rice.kim.api.role.Role;
 27  
 import org.kuali.rice.kim.api.role.RoleMembership;
 28  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 29  
 import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase;
 30  
 
 31  
 import java.util.ArrayList;
 32  
 import java.util.Collections;
 33  
 import java.util.List;
 34  
 import java.util.Map;
 35  
 
 36  
 /**
 37  
  * This is a description of what this class does - kellerj don't forget to fill this in. 
 38  
  * 
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  * @deprecated A krad integrated type service base class will be provided in the future.
 42  
  */
 43  
 @Deprecated
 44  0
 public class PrincipalDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase {
 45  
         
 46  
         private IdentityService identityService;
 47  
 
 48  
     @Override
 49  
     protected List<String> getRequiredAttributes() {
 50  0
         final List<String> attrs = new ArrayList<String>(super.getRequiredAttributes());
 51  0
         attrs.add(KimConstants.AttributeConstants.PRINCIPAL_ID);
 52  0
         return Collections.unmodifiableList(attrs);
 53  
     }
 54  
 
 55  
     @Override
 56  
     protected boolean isCheckRequiredAttributes() {
 57  0
         return false;
 58  
     }
 59  
 
 60  
         @Override
 61  
         public boolean performMatch(Map<String, String> inputAttributes, Map<String, String> storedAttributes) {
 62  0
                 if (inputAttributes == null) {
 63  0
             throw new RiceIllegalArgumentException("inputAttributes was null");
 64  
         }
 65  
 
 66  0
                 if (storedAttributes == null) {
 67  0
             throw new RiceIllegalArgumentException("storedAttributes was null");
 68  
         }
 69  
 
 70  0
         return true;
 71  
         }
 72  
 
 73  
         /**
 74  
          * Since this is potentially the entire set of users, just check the qualification for the user we are interested in and return it.
 75  
          */
 76  
         @Override
 77  
     public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) {
 78  0
                 if (StringUtils.isBlank(namespaceCode)) {
 79  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 80  
         }
 81  
 
 82  0
         if (roleName == null) {
 83  0
             throw new RiceIllegalArgumentException("roleName was null");
 84  
         }
 85  
 
 86  0
                 if ( qualification == null || qualification.isEmpty() ) {
 87  0
                         return Collections.emptyList();
 88  
                 }
 89  0
         ArrayList<RoleMembership> tempIdList = new ArrayList<RoleMembership>();
 90  0
                 qualification = translateInputAttributes(qualification);
 91  
                 // check that the principal ID is not null
 92  0
                 String principalId = qualification.get( KimConstants.AttributeConstants.PRINCIPAL_ID );
 93  0
                 if ( hasApplicationRole(principalId, null, namespaceCode, roleName, qualification)) {
 94  0
                 tempIdList.add( RoleMembership.Builder.create(null/*roleId*/, null, principalId, MemberType.PRINCIPAL, null).build());
 95  
                 }
 96  0
                 return tempIdList;
 97  
         }
 98  
         
 99  
         @Override
 100  
         public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification) {
 101  0
         if (StringUtils.isBlank(principalId)) {
 102  0
             throw new RiceIllegalArgumentException("principalId was null or blank");
 103  
         }
 104  
 
 105  0
         if (groupIds == null) {
 106  0
             throw new RiceIllegalArgumentException("groupIds was null or blank");
 107  
         }
 108  
 
 109  0
         if (StringUtils.isBlank(namespaceCode)) {
 110  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 111  
         }
 112  
 
 113  0
         if (StringUtils.isBlank(roleName)) {
 114  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 115  
         }
 116  
 
 117  0
         if (qualification == null) {
 118  0
             throw new RiceIllegalArgumentException("qualification was null");
 119  
         }
 120  
 
 121  
         // check that the principal exists and is active
 122  0
         Principal principal = getIdentityService().getPrincipal( principalId );
 123  0
         if ( principal == null || !principal.isActive() ) {
 124  0
             return false;
 125  
         }
 126  
         // check that the identity is active
 127  0
         EntityDefault entity = getIdentityService().getEntityDefault( principal.getEntityId() );
 128  0
         return entity != null && entity.isActive();
 129  
         }
 130  
         
 131  
         protected IdentityService getIdentityService() {
 132  0
                 if ( identityService == null ) {
 133  0
                         identityService = KimApiServiceLocator.getIdentityService();
 134  
                 }
 135  0
                 return identityService;
 136  
         }
 137  
 }