| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| NamespacePermissionTypeServiceImpl |
|
| 4.333333333333333;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.kns.service.impl; | |
| 17 | ||
| 18 | import java.util.ArrayList; | |
| 19 | import java.util.List; | |
| 20 | ||
| 21 | import org.apache.commons.lang.StringUtils; | |
| 22 | import org.kuali.rice.core.util.AttributeSet; | |
| 23 | import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; | |
| 24 | import org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase; | |
| 25 | import org.kuali.rice.kim.util.KimConstants; | |
| 26 | ||
| 27 | /** | |
| 28 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 29 | */ | |
| 30 | 0 | public class NamespacePermissionTypeServiceImpl extends |
| 31 | KimPermissionTypeServiceBase { | |
| 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 | * @see org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase#performPermissionMatches(org.kuali.rice.core.util.AttributeSet, java.util.List) | |
| 47 | */ | |
| 48 | @Override | |
| 49 | protected List<KimPermissionInfo> performPermissionMatches(AttributeSet requestedDetails, List<KimPermissionInfo> permissionsList) { | |
| 50 | 0 | List<KimPermissionInfo> matchingPermissions = new ArrayList<KimPermissionInfo>(); |
| 51 | ||
| 52 | 0 | String requestedNamespaceCode = requestedDetails.get(KimConstants.AttributeConstants.NAMESPACE_CODE); |
| 53 | ||
| 54 | // Add all exact matches to the list | |
| 55 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
| 56 | 0 | String permissionNamespaceCode = kpi.getDetails().get(KimConstants.AttributeConstants.NAMESPACE_CODE); |
| 57 | 0 | if ( StringUtils.equals(requestedNamespaceCode, permissionNamespaceCode ) ) { |
| 58 | 0 | matchingPermissions.add(kpi); |
| 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 ( KimPermissionInfo kpi : permissionsList ) { |
| 65 | 0 | String permissionNamespaceCode = kpi.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 | } |