diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java new file mode 100644 index 00000000000..6ea320442c1 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. 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.decision.point.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component name="org.wso2.carbon.policy.decision.MergedPolicyEvaluationServiceComponent" immediate="true" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + * @scr.reference name="org.wso2.carbon.devicemgt.policy.manager" + * interface="org.wso2.carbon.policy.mgt.core.PolicyManagerService" + * cardinality="0..1" + * policy="dynamic" + * bind="setPolicyManagerService" + * unbind="unsetPolicyManagerService" + */ + +public class MergedPolicyEvaluationServiceComponent { + + private static Log log = LogFactory.getLog(MergedPolicyEvaluationServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("Activating the policy evaluation bundle."); + } + + try { + //TODO: fetch PEP class from config + + + componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), + new MergedPolicyEvaluationServiceComponent(), null); + } catch (Throwable t) { + log.error("Error occurred while initializing the policy evaluation bundle"); + } + } + + protected void deactivate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("De-activating the policy evaluation bundle."); + } + } + + /** + * Sets Realm Service + * + * @param realmService An instance of RealmService + */ + protected void setRealmService(RealmService realmService) { + + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + PolicyDecisionPointDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service + * + * @param realmService An instance of RealmService + */ + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + PolicyDecisionPointDataHolder.getInstance().setRealmService(null); + } + + protected void setPolicyManagerService(PolicyManagerService policyManagerService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting PolicyManagerService Service"); + } + PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(policyManagerService); + } + + protected void unsetPolicyManagerService(PolicyManagerService policyManagerService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting PolicyManagerService Service"); + } + PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(null); + } + + protected String getName() { + return MergedPolicyEvaluationServiceComponent.class.getName(); + } + +} + diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java index 88b9a36ad49..d88ca9fb14d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java @@ -60,6 +60,11 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { } } + @Override + public String getName() { + return "MergedPolicyEvaluationServiceComponent"; + } + @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java index 3b3727cff06..7229bfc747c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java @@ -59,4 +59,9 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);*/ return effectiveFeatures; } + + @Override + public String getName() { + return "SimplePolicyEvaluationServiceComponent"; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java index 3fbf83ff9c6..7b497ccb6e6 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java @@ -43,4 +43,6 @@ public interface PolicyEvaluationPoint { * @return returns the effective feature set. */ List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + + String getName(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java index ee62eb3ad75..62741ba5035 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java @@ -29,7 +29,8 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl; import java.util.Collections; import java.util.List; -public class SimplePolicyEvaluationTest implements PolicyEvaluationPoint { +public class +SimplePolicyEvaluationTest implements PolicyEvaluationPoint { private static final Log log = LogFactory.getLog(SimplePolicyEvaluationTest.class); @@ -76,6 +77,11 @@ public class SimplePolicyEvaluationTest implements PolicyEvaluationPoint { return null; } + @Override + public String getName() { + return "MergedPolicyEvaluationServiceComponent"; + } + public void sortPolicies(List policyList) throws PolicyEvaluationException { Collections.sort(policyList); }