Merge branch 'master' into 'master'

Add general policy filter to delegate only general policies

Closes product-iots#268

See merge request entgra/carbon-device-mgt!369
merge-requests/368/merge
Saad Sahibjan 5 years ago
commit 0c9ab04bd9

@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -29,6 +46,13 @@ public interface PolicyFilter {
List<Policy> filterActivePolicies(List<Policy> policies);
/**
* Filter and retrieve all the general policies out of active policies
* @param policies contains a list of active policies
* @return a list of {@link Policy} general policies
*/
List<Policy> filterGeneralPolicies(List<Policy> policies);
List<Policy> filterDeviceGroupsPolicies(Map<Integer, DeviceGroup> groupMap, List<Policy> policies);
List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies);

@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -63,6 +80,33 @@ public class PolicyFilterImpl implements PolicyFilter {
return temp;
}
@Override
public List<Policy> filterGeneralPolicies(List<Policy> policies) {
if (log.isDebugEnabled()) {
log.debug("No of policies went in to filterGeneralPolicies : " + policies.size());
for (Policy policy : policies) {
log.debug("Names of policy went in to filterGeneralPolicies : " + policy.getPolicyName());
}
}
List<Policy> generalPolicies = new ArrayList<>();
for (Policy policy : policies) {
if (PolicyManagementConstants.GENERAL_POLICY_TYPE.equalsIgnoreCase(policy.getPolicyType())) {
generalPolicies.add(policy);
}
}
if (log.isDebugEnabled()) {
log.debug("No of policies returned from filterGeneralPolicies :" + policies.size());
for (Policy policy : generalPolicies) {
log.debug("Names of policy filtered in filterGeneralPolicies : " + policy.getPolicyName());
}
}
return generalPolicies;
}
@Override
public List<Policy> filterDeviceGroupsPolicies(Map<Integer, DeviceGroup> groupMap, List<Policy> policies) {

@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.policy.mgt.core.impl;
@ -113,6 +130,7 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
}
policies = policyFilter.filterActivePolicies(policies);
policies = policyFilter.filterGeneralPolicies(policies);
if (pipDevice.getDeviceType() != null) {
policies = policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies);

Loading…
Cancel
Save