Coverage Report - org.kuali.rice.kim.service.support.impl.KimRoleTypeServiceBase
 
Classes in this File Line Coverage Branch Coverage Complexity
KimRoleTypeServiceBase
0%
0/40
0%
0/24
2.545
 
 1  
 /*
 2  
  * Copyright 2007-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 org.apache.commons.lang.StringUtils;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.kim.api.role.Role;
 21  
 import org.kuali.rice.kim.api.role.RoleMembership;
 22  
 import org.kuali.rice.kim.framework.type.KimDelegationTypeService;
 23  
 import org.kuali.rice.kim.framework.type.KimRoleTypeService;
 24  
 import org.kuali.rice.kim.impl.type.KimTypeServiceBase;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.List;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * This is a description of what this class does - jonathan don't forget to fill this in. 
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  0
 public class KimRoleTypeServiceBase extends KimTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService {
 37  
 
 38  0
         private static final Logger LOG = Logger.getLogger(KimRoleTypeServiceBase.class);
 39  
         
 40  
         /**
 41  
          * Performs a simple check that the qualifier on the role matches the qualification.
 42  
          * Extra qualification attributes are ignored.
 43  
          * 
 44  
          * @see KimRoleTypeService#doesRoleQualifierMatchQualification(Map<String, String>, Map<String, String>)
 45  
          */
 46  
 
 47  
         public boolean doesRoleQualifierMatchQualification(Map<String, String> qualification, Map<String, String> roleQualifier) {
 48  0
                 Map<String, String> translatedQualification = translateInputAttributes(qualification);
 49  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 50  0
                 return performMatch(translatedQualification, roleQualifier);
 51  
         }
 52  
         
 53  
         /**
 54  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#doRoleQualifiersMatchQualification(Map<String, String>, List)
 55  
          */
 56  
         public List<RoleMembership> doRoleQualifiersMatchQualification(Map<String, String> qualification, List<RoleMembership> roleMemberList) {
 57  0
                 Map<String, String> translatedQualification = translateInputAttributes(qualification);
 58  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 59  0
                 List<RoleMembership> matchingMemberships = new ArrayList<RoleMembership>();
 60  0
                 for ( RoleMembership roleMembership : roleMemberList ) {
 61  0
                         if ( performMatch( translatedQualification, roleMembership.getQualifier() ) ) {
 62  0
                                 matchingMemberships.add( roleMembership );
 63  
                         }
 64  
                 }
 65  0
                 return matchingMemberships;
 66  
         }
 67  
 
 68  
         /**
 69  
          * Return an empty list since this method should not be called by the role service for this service type.
 70  
          * Subclasses which are application role types should override this method.
 71  
          * 
 72  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#getRoleMembersFromApplicationRole(String, String, Map<String, String>)
 73  
          */
 74  
         public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) {
 75  0
                 validateRequiredAttributesAgainstReceived(qualification);
 76  0
                 if ( !isApplicationRoleType() ) {
 77  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." );
 78  
                 } else {
 79  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is an application role type but has not overridden this method." );
 80  
                 }
 81  
         }
 82  
 
 83  
         /**
 84  
          * This simple initial implementation just calls  
 85  
          * {@link #getRoleMembersFromApplicationRole(String, String, Map<String, String>)} and checks the results.
 86  
          *
 87  
          */
 88  
         public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification) {
 89  0
                 if ( !isApplicationRoleType() ) {
 90  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." );
 91  
                 }
 92  
                 // if principal ID given, check if it is in the list generated from the getPrincipalIdsFromApplicationRole method
 93  0
                 if ( StringUtils.isNotBlank( principalId ) ) {
 94  0
                     List<RoleMembership> members = getRoleMembersFromApplicationRole(namespaceCode, roleName, qualification);
 95  0
                     for ( RoleMembership rm : members ) {
 96  0
                             if ( StringUtils.isBlank( rm.getRoleMemberId() ) ) {
 97  0
                                     continue;
 98  
                             }
 99  0
                         if ( rm.getMemberTypeCode().equals( Role.PRINCIPAL_MEMBER_TYPE ) ) {
 100  0
                             if ( rm.getMemberId().equals( principalId ) ) {
 101  0
                                 return true;
 102  
                             }
 103  
                         } else { // groups
 104  0
                             if ( groupIds != null 
 105  
                                     && groupIds.contains(rm.getMemberId())) {
 106  0
                                 return true;
 107  
                             }
 108  
                         }
 109  
                         }
 110  
                 }
 111  0
                 return false;
 112  
         }
 113  
         
 114  
         /**
 115  
          * Default to not being an application role type.  Always returns false.
 116  
          * 
 117  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#isApplicationRoleType()
 118  
          */
 119  
         public boolean isApplicationRoleType() {
 120  0
                 return false;
 121  
         }
 122  
                 
 123  
         /**
 124  
          * This base implementation simply returns the passed in Attributes.
 125  
          * 
 126  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#convertQualificationForMemberRoles(String, String, String, String, Map<String, String>)
 127  
          */
 128  
         public Map<String, String> convertQualificationForMemberRoles(String namespaceCode, String roleName, String memberRoleNamespaceCode, String memberRoleName, Map<String, String> qualification) {
 129  0
                 return qualification;
 130  
         }
 131  
         
 132  
         /**
 133  
          * Base implementation: no sorting.  Just returns the input list.
 134  
          * 
 135  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#sortRoleMembers(java.util.List)
 136  
          */
 137  
         public List<RoleMembership> sortRoleMembers(List<RoleMembership> roleMembers) {
 138  0
                 return roleMembers;
 139  
         }
 140  
         
 141  
         /**
 142  
          * This base implementation does nothing but log that the method was called.
 143  
          * 
 144  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#principalInactivated(java.lang.String, java.lang.String, java.lang.String)
 145  
          */
 146  
         public void principalInactivated(String principalId, String namespaceCode,
 147  
                         String roleName) {
 148  0
                 if ( LOG.isDebugEnabled() ) {
 149  0
                         LOG.debug( "Principal Inactivated called: principalId="+principalId+" role=" + namespaceCode + "/" + roleName );
 150  
                 }
 151  
                 // base implementation - do nothing
 152  0
         }
 153  
         
 154  
         /**
 155  
          * Performs a simple check that the qualifier on the delegation matches the qualification.
 156  
          * Extra qualification attributes are ignored.
 157  
          *
 158  
          */
 159  
         public boolean doesDelegationQualifierMatchQualification(Map<String, String> qualification, Map<String, String> roleQualifier) {
 160  0
                 Map<String, String> translatedQualification = translateInputAttributes(qualification);
 161  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 162  0
                 return performMatch(translatedQualification, roleQualifier);
 163  
         }
 164  
 
 165  
         /**
 166  
          * Returns true as a default
 167  
          * 
 168  
          * @see org.kuali.rice.kim.framework.type.KimRoleTypeService#shouldCacheRoleMembershipResults(java.lang.String, java.lang.String)
 169  
          */
 170  
         public boolean shouldCacheRoleMembershipResults(String namespaceCode,
 171  
                         String roleName) {
 172  0
                 return true;
 173  
         }
 174  
 
 175  
         public List<String> getQualifiersForExactMatch() {    
 176  0
                 return new ArrayList<String>(); 
 177  
         }
 178  
         
 179  
 }