1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
30 | |
|
31 | 0 | public class NamespacePermissionTypeServiceImpl extends PermissionTypeServiceBase { |
32 | |
|
33 | 0 | private Boolean exactMatchPriority = true; |
34 | |
{ |
35 | |
|
36 | 0 | } |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
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 | |
|
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 | |
|
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 | |
} |