diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java index 3a7d4a50af..50a2bac110 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java @@ -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 filterActivePolicies(List 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 filterGeneralPolicies(List policies); + List filterDeviceGroupsPolicies(Map groupMap, List policies); List filterRolesBasedPolicies(String roles[], List policies); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java index a78caa995b..acb2c48794 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java @@ -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 filterGeneralPolicies(List 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 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 filterDeviceGroupsPolicies(Map groupMap, List policies) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java index 20fddc6cdb..20da56c812 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java @@ -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);