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.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 | |
|
30 | |
|
31 | 0 | public class NamespacePermissionTypeServiceImpl extends |
32 | |
KimPermissionTypeServiceBase { |
33 | |
|
34 | 0 | private Boolean exactMatchPriority = true; |
35 | |
{ |
36 | |
|
37 | 0 | } |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
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 | |
|
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 | |
|
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 | |
} |