Coverage Report - org.kuali.rice.krad.service.impl.NamespacePermissionTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NamespacePermissionTypeServiceImpl
0%
0/22
0%
0/20
4.333
 
 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.krad.service.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kim.api.permission.Permission;
 20  
 import org.kuali.rice.kim.impl.permission.PermissionBo;
 21  
 import org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase;
 22  
 import org.kuali.rice.kim.util.KimConstants;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 /**
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class NamespacePermissionTypeServiceImpl extends
 32  
                 KimPermissionTypeServiceBase {
 33  
 
 34  0
         private Boolean exactMatchPriority = true;
 35  
         {
 36  
 //                requiredAttributes.add(KimAttributes.NAMESPACE_CODE);
 37  0
         }
 38  
         
 39  
         /**
 40  
          * Check for entries that match the namespace.
 41  
          * 
 42  
          * By default, this method will return all exact matches if any exist, and it will only return partial matches if there are no exact matches.
 43  
          * i.e. KR-NS will have priority over KR-*
 44  
          * 
 45  
      * If ExactMatchPriority is false, then this method will return all exact AND partial matching permissions.  By default, ExactMatchPriority will be set to true.
 46  
          */
 47  
         @Override
 48  
         protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails, List<Permission> permissionsList) {
 49  0
                 List<Permission> matchingPermissions = new ArrayList<Permission>();
 50  
                 
 51  0
                 String requestedNamespaceCode = requestedDetails.get(KimConstants.AttributeConstants.NAMESPACE_CODE);
 52  
                 
 53  
                 // Add all exact matches to the list 
 54  0
                 for ( Permission permission : permissionsList ) {
 55  0
             PermissionBo bo = PermissionBo.from(permission);
 56  0
                         String permissionNamespaceCode = bo.getDetails().get(KimConstants.AttributeConstants.NAMESPACE_CODE);
 57  0
                         if ( StringUtils.equals(requestedNamespaceCode, permissionNamespaceCode ) ) {
 58  0
                                 matchingPermissions.add(permission);
 59  
                         } 
 60  0
                 }
 61  
                 
 62  
                 // Add partial matches to the list if there are no exact matches or if exactMatchPriority is false
 63  0
                 if ((exactMatchPriority && matchingPermissions.isEmpty()) || (!(exactMatchPriority))) {
 64  0
                         for ( Permission kpi : permissionsList ) {
 65  0
                 PermissionBo bo = PermissionBo.from(kpi);
 66  0
                                 String permissionNamespaceCode = bo.getDetails().get(KimConstants.AttributeConstants.NAMESPACE_CODE);
 67  0
                                 if ( requestedNamespaceCode != null
 68  
                                          && permissionNamespaceCode != null
 69  
                                          && (!( StringUtils.equals(requestedNamespaceCode, permissionNamespaceCode ))) 
 70  
                                          && requestedNamespaceCode.matches(permissionNamespaceCode.replaceAll("\\*", ".*") ) ) {
 71  0
                                                  matchingPermissions.add(kpi);
 72  
                                 }
 73  0
                         }
 74  
                 }
 75  0
         return matchingPermissions;
 76  
         }
 77  
                 
 78  
         public Boolean getExactMatchPriority() {
 79  0
                 return this.exactMatchPriority;
 80  
         }
 81  
 
 82  
         public void setExactMatchPriority(Boolean exactMatchPriority) {
 83  0
                 this.exactMatchPriority = exactMatchPriority;
 84  0
         }
 85  
 }