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