Coverage Report - org.kuali.rice.kns.kim.role.RoleTypeServiceBase
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleTypeServiceBase
0%
0/77
0%
0/64
7.444
 
 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  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 20  
 import org.kuali.rice.core.api.membership.MemberType;
 21  
 import org.kuali.rice.kim.api.role.Role;
 22  
 import org.kuali.rice.kim.api.role.RoleMembership;
 23  
 import org.kuali.rice.kim.framework.common.delegate.DelegationTypeService;
 24  
 import org.kuali.rice.kim.framework.role.RoleTypeService;
 25  
 import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase;
 26  
 
 27  
 import java.util.ArrayList;
 28  
 import java.util.Collections;
 29  
 import java.util.HashMap;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 
 33  
 /**
 34  
  * @deprecated A krad integrated type service base class will be provided in the future.
 35  
  */
 36  
 @Deprecated
 37  0
 public class RoleTypeServiceBase extends DataDictionaryTypeServiceBase implements RoleTypeService, DelegationTypeService {
 38  
         
 39  
         /**
 40  
          * Performs a simple check that the qualifier on the role matches the qualification.
 41  
          * Extra qualification attributes are ignored.
 42  
          */
 43  
     @Override
 44  
         public boolean doesRoleQualifierMatchQualification(Map<String, String> qualification, Map<String, String> roleQualifier) {
 45  0
                 if (qualification == null) {
 46  0
             throw new RiceIllegalArgumentException("qualification was null or blank");
 47  
         }
 48  
 
 49  0
         if (roleQualifier == null) {
 50  0
             throw new RiceIllegalArgumentException("roleQualifier was null or blank");
 51  
         }
 52  
 
 53  0
         Map<String, String> translatedQualification = translateInputAttributes(qualification);
 54  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 55  0
                 return performMatch(translatedQualification, roleQualifier);
 56  
         }
 57  
         
 58  
     @Override
 59  
         public List<RoleMembership> getMatchingRoleMemberships(Map<String, String> qualification,
 60  
             List<RoleMembership> roleMemberList) {
 61  0
                 if (qualification == null) {
 62  0
             throw new RiceIllegalArgumentException("qualification was null or blank");
 63  
         }
 64  
 
 65  0
         if (roleMemberList == null) {
 66  0
             throw new RiceIllegalArgumentException("roleMemberList was null or blank");
 67  
         }
 68  
 
 69  0
         Map<String, String> translatedQualification = translateInputAttributes(qualification);
 70  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 71  0
                 List<RoleMembership> matchingMemberships = new ArrayList<RoleMembership>();
 72  0
                 for ( RoleMembership roleMembership : roleMemberList ) {
 73  0
                         if ( performMatch( translatedQualification, roleMembership.getQualifier() ) ) {
 74  0
                                 matchingMemberships.add( roleMembership );
 75  
                         }
 76  
                 }
 77  0
                 return Collections.unmodifiableList(matchingMemberships);
 78  
         }
 79  
 
 80  
         /**
 81  
          * Return an empty list since this method should not be called by the role service for this service type.
 82  
          * Subclasses which are application role types should override this method.
 83  
          *
 84  
          */
 85  
     @Override
 86  
         public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) {
 87  
 
 88  0
         if (StringUtils.isBlank(namespaceCode)) {
 89  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 90  
         }
 91  
 
 92  0
         if (StringUtils.isBlank(roleName)) {
 93  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 94  
         }
 95  
 
 96  0
         if (qualification == null) {
 97  0
             throw new RiceIllegalArgumentException("qualification was null or blank");
 98  
         }
 99  
 
 100  0
         validateRequiredAttributesAgainstReceived(qualification);
 101  0
                 if ( !isApplicationRoleType() ) {
 102  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." );
 103  
                 } else {
 104  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is an application role type but has not overridden this method." );
 105  
                 }
 106  
         }
 107  
 
 108  
         /**
 109  
          * This simple initial implementation just calls  
 110  
          * {@link #getRoleMembersFromApplicationRole(String, String, Map<String, String>)} and checks the results.
 111  
          *
 112  
          */
 113  
     @Override
 114  
         public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification) {
 115  0
             if (StringUtils.isBlank(principalId)) {
 116  0
             throw new RiceIllegalArgumentException("principalId was null or blank");
 117  
         }
 118  
 
 119  0
         if (groupIds == null) {
 120  0
             throw new RiceIllegalArgumentException("groupIds was null or blank");
 121  
         }
 122  
 
 123  0
         if (StringUtils.isBlank(namespaceCode)) {
 124  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 125  
         }
 126  
 
 127  0
         if (StringUtils.isBlank(roleName)) {
 128  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 129  
         }
 130  
 
 131  0
         if (qualification == null) {
 132  0
             throw new RiceIllegalArgumentException("qualification was null or blank");
 133  
         }
 134  
 
 135  0
         if ( !isApplicationRoleType() ) {
 136  0
                         throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." );
 137  
                 }
 138  
                 // if principal ID given, check if it is in the list generated from the getPrincipalIdsFromApplicationRole method
 139  0
                 if ( StringUtils.isNotBlank( principalId ) ) {
 140  0
                     List<RoleMembership> members = getRoleMembersFromApplicationRole(namespaceCode, roleName, qualification);
 141  0
                     for ( RoleMembership rm : members ) {
 142  0
                             if ( StringUtils.isBlank( rm.getRoleMemberId() ) ) {
 143  0
                                     continue;
 144  
                             }
 145  0
                         if ( MemberType.PRINCIPAL.equals(rm.getMemberType()) ) {
 146  0
                             if ( rm.getMemberId().equals( principalId ) ) {
 147  0
                                 return true;
 148  
                             }
 149  
                         } else { // groups
 150  0
                             if ( groupIds != null 
 151  
                                     && groupIds.contains(rm.getMemberId())) {
 152  0
                                 return true;
 153  
                             }
 154  
                         }
 155  
                         }
 156  
                 }
 157  0
                 return false;
 158  
         }
 159  
         
 160  
         /**
 161  
          * Default to not being an application role type.  Always returns false.
 162  
          * 
 163  
          * @see org.kuali.rice.kim.framework.role.RoleTypeService#isApplicationRoleType()
 164  
          */
 165  
     @Override
 166  
         public boolean isApplicationRoleType() {
 167  0
                 return false;
 168  
         }
 169  
                 
 170  
         /**
 171  
          * This base implementation simply returns the passed in Attributes.
 172  
          * 
 173  
          * @see org.kuali.rice.kim.framework.role.RoleTypeService#convertQualificationForMemberRoles(String, String, String, String, Map<String, String>)
 174  
          */
 175  
     @Override
 176  
         public Map<String, String> convertQualificationForMemberRoles(String namespaceCode, String roleName, String memberRoleNamespaceCode, String memberRoleName, Map<String, String> qualification) {
 177  
 
 178  0
         if (StringUtils.isBlank(namespaceCode)) {
 179  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 180  
         }
 181  
 
 182  0
         if (StringUtils.isBlank(roleName)) {
 183  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 184  
         }
 185  
 
 186  0
         if (StringUtils.isBlank(memberRoleNamespaceCode)) {
 187  0
             throw new RiceIllegalArgumentException("memberRoleNamespaceCode was null or blank");
 188  
         }
 189  
 
 190  0
         if (StringUtils.isBlank(memberRoleName)) {
 191  0
             throw new RiceIllegalArgumentException("memberRoleName was null or blank");
 192  
         }
 193  
 
 194  0
         if (qualification == null) {
 195  0
             throw new RiceIllegalArgumentException("qualification was null or blank");
 196  
         }
 197  
 
 198  0
         return Collections.unmodifiableMap(new HashMap<String, String>(qualification));
 199  
         }
 200  
                 
 201  
         /**
 202  
          * Performs a simple check that the qualifier on the delegation matches the qualification.
 203  
          * Extra qualification attributes are ignored.
 204  
          *
 205  
          */
 206  
     @Override
 207  
         public boolean doesDelegationQualifierMatchQualification(Map<String, String> qualification, Map<String, String> roleQualifier) {
 208  0
                 if (qualification == null) {
 209  0
             throw new RiceIllegalArgumentException("qualification was null or blank");
 210  
         }
 211  
 
 212  0
         if (roleQualifier == null) {
 213  0
             throw new RiceIllegalArgumentException("roleQualifier was null or blank");
 214  
         }
 215  
 
 216  0
         Map<String, String> translatedQualification = translateInputAttributes(qualification);
 217  0
                 validateRequiredAttributesAgainstReceived(translatedQualification);
 218  0
                 return performMatch(translatedQualification, roleQualifier);
 219  
         }
 220  
 
 221  
         /**
 222  
          * Returns true as a default
 223  
          * 
 224  
          * @see org.kuali.rice.kim.framework.role.RoleTypeService#dynamicRoleMembership(java.lang.String, java.lang.String)
 225  
          */
 226  
     @Override
 227  
         public boolean dynamicRoleMembership(String namespaceCode, String roleName) {
 228  0
                 if (StringUtils.isBlank(namespaceCode)) {
 229  0
             throw new RiceIllegalArgumentException("namespaceCode was null or blank");
 230  
         }
 231  
 
 232  0
         if (StringUtils.isBlank(roleName)) {
 233  0
             throw new RiceIllegalArgumentException("roleName was null or blank");
 234  
         }
 235  
 
 236  0
         return true;
 237  
         }
 238  
 
 239  
     @Override
 240  
         public List<String> getQualifiersForExactMatch() {    
 241  0
                 return Collections.emptyList();
 242  
         }
 243  
         
 244  
 }