Package: AbstractPolicyFinderModule

AbstractPolicyFinderModule

nameinstructionbranchcomplexitylinemethod
AbstractPolicyFinderModule()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getActivePolicies()
M: 90 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
getOrderedPolicyIdentifiers()
M: 93 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getSearchAttributes(String, Set)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSupportedSearchAttributesScheme()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
invalidateCache()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
invalidateCache(String, String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isDefaultCategoriesSupported()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isPolicyDeActivationSupport()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isPolicyOrderingSupport()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3: *
4: * WSO2 Inc. licenses this file to you under the Apache License,
5: * Version 2.0 (the "License"); you may not use this file except
6: * in compliance with the License.
7: * You may obtain a copy of the License at
8: *
9: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing,
12: * software distributed under the License is distributed on an
13: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14: * KIND, either express or implied. See the License for the
15: * specific language governing permissions and limitations
16: * under the License.
17: */
18:
19: package org.wso2.carbon.identity.entitlement.policy.finder;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.wso2.carbon.identity.entitlement.PolicyOrderComparator;
24: import org.wso2.carbon.identity.entitlement.dto.AttributeDTO;
25: import org.wso2.carbon.identity.entitlement.dto.PolicyStoreDTO;
26: import org.wso2.carbon.identity.entitlement.pap.EntitlementAdminEngine;
27: import org.wso2.carbon.identity.entitlement.pdp.EntitlementEngine;
28:
29: import java.util.ArrayList;
30: import java.util.Arrays;
31: import java.util.Date;
32: import java.util.List;
33: import java.util.Map;
34: import java.util.Set;
35:
36: /**
37: * Abstract implementation of a policy finder module. This can be easily extended by any module
38: * that support dynamic policy changes.
39: */
40: public abstract class AbstractPolicyFinderModule implements PolicyFinderModule {
41:
42: private static Log log = LogFactory.getLog(AbstractPolicyFinderModule.class);
43:
44: /**
45: * This method must be called by the module when its policies are updated
46: */
47: public static void invalidateCache(String policyId, String action) {
48: EntitlementEngine.getInstance().getPolicyCache().invalidateCache(policyId, action);
49: EntitlementEngine.getInstance().clearDecisionCache();
50: }
51:
52: public static void invalidateCache() {
53: EntitlementEngine.getInstance().clearDecisionCache();
54: EntitlementEngine.getInstance().invalidatePolicyCache();
55: }
56:
57: @Override
58: public String[] getOrderedPolicyIdentifiers() {
59:
60: log.debug("Start retrieving ordered policy identifiers at : " + new Date());
61: String[] policyIdentifiers = getPolicyIdentifiers();
62:• if (policyIdentifiers != null && !isPolicyOrderingSupport()) {
63: PolicyStoreDTO[] policyDTOs = EntitlementAdminEngine.getInstance().
64: getPolicyStoreManager().getAllPolicyData();
65: Arrays.sort(policyDTOs, new PolicyOrderComparator());
66: List<String> list = new ArrayList<String>();
67: List<String> finalList = new ArrayList<String>();
68: // 1st put non -order items
69: list.addAll(Arrays.asList(policyIdentifiers));
70:• for (PolicyStoreDTO dto : policyDTOs) {
71: list.remove(dto.getPolicyId());
72: finalList.add(dto.getPolicyId());
73: }
74: finalList.addAll(list);
75: return finalList.toArray(new String[finalList.size()]);
76: }
77: log.debug("Finish retrieving ordered policy identifiers at : " + new Date());
78: return policyIdentifiers;
79: }
80:
81: @Override
82: public String[] getActivePolicies() {
83: log.debug("Start retrieving active policies at : " + new Date());
84: List<String> policies = new ArrayList<String>();
85: String[] policyIdentifiers = getOrderedPolicyIdentifiers();
86:• if (policyIdentifiers != null) {
87:• for (String identifier : policyIdentifiers) {
88:• if (!isPolicyDeActivationSupport()) {
89: PolicyStoreDTO data = EntitlementAdminEngine.getInstance().
90: getPolicyDataStore().getPolicyData(identifier);
91:• if (data != null && data.isActive()) {
92: String policy = getPolicy(identifier);
93:• if (policy != null) {
94: policies.add(policy);
95: }
96: }
97: } else {
98: String policy = getPolicy(identifier);
99:• if (policy != null) {
100: policies.add(policy);
101: }
102: }
103: }
104: }
105: log.debug("Finish retrieving active policies at : " + new Date());
106: return policies.toArray(new String[policies.size()]);
107:
108: }
109:
110:
111: @Override
112: public boolean isDefaultCategoriesSupported() {
113: return true;
114: }
115:
116: @Override
117: public boolean isPolicyOrderingSupport() {
118: return false;
119: }
120:
121: @Override
122: public boolean isPolicyDeActivationSupport() {
123: return false;
124: }
125:
126: @Override
127: public Map<String, Set<AttributeDTO>> getSearchAttributes(String identifier,
128: Set<AttributeDTO> givenAttribute) {
129: return null;
130: }
131:
132: @Override
133: public int getSupportedSearchAttributesScheme() {
134: return 0;
135: }
136:
137: /**
138: * @return
139: */
140: protected abstract String[] getPolicyIdentifiers();
141: }