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