1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.service.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.Collections; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import org.apache.commons.lang.StringUtils; |
26 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
27 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
28 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
29 | |
import org.kuali.rice.kim.util.KimConstants; |
30 | |
import org.kuali.rice.kns.bo.Namespace; |
31 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
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 namespaceRequiredOnStoredAttributeSet; |
42 | |
|
43 | |
@Override |
44 | |
protected List<KimPermissionInfo> performPermissionMatches(AttributeSet requestedDetails, List<KimPermissionInfo> permissionsList) { |
45 | 0 | List<KimPermissionInfo> matchingPermissions = new ArrayList<KimPermissionInfo>(); |
46 | 0 | List<KimPermissionInfo> matchingBlankPermissions = new ArrayList<KimPermissionInfo>(); |
47 | 0 | String requestedAttributeValue = requestedDetails.get(exactMatchStringAttributeName); |
48 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
49 | 0 | String permissionAttributeValue = kpi.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<KimPermissionInfo> matchingWithNamespace = super.performPermissionMatches(requestedDetails, matchingPermissions); |
60 | 0 | if ( !namespaceRequiredOnStoredAttributeSet ) { |
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<KimPermissionInfo> matchingWithNamespace = super.performPermissionMatches(requestedDetails, matchingBlankPermissions); |
70 | 0 | if ( !namespaceRequiredOnStoredAttributeSet ) { |
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 setNamespaceRequiredOnStoredAttributeSet( |
89 | |
boolean namespaceRequiredOnStoredAttributeSet) { |
90 | 0 | this.namespaceRequiredOnStoredAttributeSet = namespaceRequiredOnStoredAttributeSet; |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
@Override |
97 | |
protected Map<String, List<String>> validateReferencesExistAndActive(KimTypeInfo kimType, AttributeSet attributes, Map<String, String> previousValidationErrors) { |
98 | 0 | Map<String,List<String>> errors = new HashMap<String,List<String>>(); |
99 | 0 | AttributeSet nonNamespaceCodeAttributes = new AttributeSet(attributes); |
100 | |
|
101 | 0 | if (attributes.containsKey(NAMESPACE_CODE)) { |
102 | 0 | nonNamespaceCodeAttributes.remove(NAMESPACE_CODE); |
103 | 0 | Collection<Namespace> namespaces = KNSServiceLocator.getLookupService().findCollectionBySearchUnbounded( |
104 | |
Namespace.class, Collections.singletonMap("code", attributes.get(NAMESPACE_CODE))); |
105 | |
|
106 | 0 | if (namespaces != null && !namespaces.isEmpty()) { |
107 | 0 | for (Namespace namespace : namespaces) { |
108 | 0 | errors.putAll(super.validateReferencesExistAndActive(kimType, new AttributeSet(NAMESPACE_CODE, namespace.getNamespaceCode()), previousValidationErrors)); |
109 | |
} |
110 | |
} else { |
111 | |
|
112 | 0 | errors.putAll(super.validateReferencesExistAndActive(kimType, new AttributeSet(NAMESPACE_CODE, attributes.get(NAMESPACE_CODE)), previousValidationErrors)); |
113 | |
} |
114 | |
} |
115 | |
|
116 | 0 | errors.putAll(super.validateReferencesExistAndActive(kimType, nonNamespaceCodeAttributes, previousValidationErrors)); |
117 | 0 | return errors; |
118 | |
} |
119 | |
} |