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.core.api.CoreApiServiceLocator; |
20 | |
import org.kuali.rice.core.api.namespace.Namespace; |
21 | |
import org.kuali.rice.kim.api.permission.Permission; |
22 | |
import org.kuali.rice.kim.api.type.KimType; |
23 | |
import org.kuali.rice.kim.impl.permission.PermissionBo; |
24 | |
import org.kuali.rice.kim.util.KimConstants; |
25 | |
|
26 | |
import java.util.ArrayList; |
27 | |
import java.util.Collections; |
28 | |
import java.util.HashMap; |
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class NamespaceWildcardAllowedAndOrStringExactMatchPermissionTypeServiceImpl |
36 | |
extends NamespacePermissionTypeServiceImpl { |
37 | |
protected static final String NAMESPACE_CODE = KimConstants.UniqueKeyConstants.NAMESPACE_CODE; |
38 | |
|
39 | |
protected String exactMatchStringAttributeName; |
40 | |
protected boolean namespaceRequiredOnStoredMap; |
41 | |
|
42 | |
@Override |
43 | |
protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails, List<Permission> permissionsList) { |
44 | 0 | List<Permission> matchingPermissions = new ArrayList<Permission>(); |
45 | 0 | List<Permission> matchingBlankPermissions = new ArrayList<Permission>(); |
46 | 0 | String requestedAttributeValue = requestedDetails.get(exactMatchStringAttributeName); |
47 | 0 | for ( Permission kpi : permissionsList ) { |
48 | 0 | PermissionBo bo = PermissionBo.from(kpi); |
49 | 0 | String permissionAttributeValue = bo.getDetails().get(exactMatchStringAttributeName); |
50 | 0 | if ( StringUtils.equals(requestedAttributeValue, permissionAttributeValue) ) { |
51 | 0 | matchingPermissions.add(kpi); |
52 | 0 | } else if ( StringUtils.isBlank(permissionAttributeValue) ) { |
53 | 0 | matchingBlankPermissions.add(kpi); |
54 | |
} |
55 | 0 | } |
56 | |
|
57 | |
|
58 | 0 | if ( !matchingPermissions.isEmpty() ) { |
59 | 0 | List<Permission> matchingWithNamespace = super.performPermissionMatches(requestedDetails, matchingPermissions); |
60 | 0 | if ( !namespaceRequiredOnStoredMap ) { |
61 | |
|
62 | |
|
63 | 0 | if ( matchingWithNamespace.isEmpty() ) { |
64 | 0 | return matchingPermissions; |
65 | |
} |
66 | |
} |
67 | 0 | return matchingWithNamespace; |
68 | 0 | } else if ( !matchingBlankPermissions.isEmpty() ) { |
69 | 0 | List<Permission> matchingWithNamespace = super.performPermissionMatches(requestedDetails, matchingBlankPermissions); |
70 | 0 | if ( !namespaceRequiredOnStoredMap ) { |
71 | |
|
72 | |
|
73 | 0 | if ( matchingWithNamespace.isEmpty() ) { |
74 | 0 | return matchingBlankPermissions; |
75 | |
} |
76 | |
} |
77 | 0 | return matchingWithNamespace; |
78 | |
} |
79 | 0 | return matchingPermissions; |
80 | |
} |
81 | |
|
82 | |
public void setExactMatchStringAttributeName( |
83 | |
String exactMatchStringAttributeName) { |
84 | 0 | this.exactMatchStringAttributeName = exactMatchStringAttributeName; |
85 | 0 | requiredAttributes.add(exactMatchStringAttributeName); |
86 | 0 | } |
87 | |
|
88 | |
public void setNamespaceRequiredOnStoredMap( |
89 | |
boolean namespaceRequiredOnStoredMap) { |
90 | 0 | this.namespaceRequiredOnStoredMap = namespaceRequiredOnStoredMap; |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
@Override |
97 | |
protected Map<String, List<String>> validateReferencesExistAndActive(KimType kimType, Map<String, String> attributes, Map<String, String> previousValidationErrors) { |
98 | 0 | Map<String,List<String>> errors = new HashMap<String,List<String>>(); |
99 | 0 | Map<String, String> nonNamespaceCodeAttributes = new HashMap<String, String>(attributes); |
100 | |
|
101 | 0 | if (attributes.containsKey(NAMESPACE_CODE)) { |
102 | 0 | nonNamespaceCodeAttributes.remove(NAMESPACE_CODE); |
103 | 0 | final Namespace namespace = CoreApiServiceLocator.getNamespaceService().getNamespace(attributes.get(NAMESPACE_CODE)); |
104 | 0 | if (namespace != null) { |
105 | 0 | errors.putAll(super.validateReferencesExistAndActive(kimType, Collections.singletonMap(NAMESPACE_CODE, |
106 | |
namespace.getCode()), previousValidationErrors)); |
107 | |
} else { |
108 | |
|
109 | 0 | errors.putAll(super.validateReferencesExistAndActive(kimType, Collections.singletonMap(NAMESPACE_CODE, |
110 | |
attributes.get(NAMESPACE_CODE)), previousValidationErrors)); |
111 | |
} |
112 | |
} |
113 | |
|
114 | 0 | errors.putAll(super.validateReferencesExistAndActive(kimType, nonNamespaceCodeAttributes, previousValidationErrors)); |
115 | 0 | return errors; |
116 | |
} |
117 | |
} |