mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding merged policy evaluation service component
This commit is contained in:
parent
6565e14051
commit
62acc2ebf2
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -60,6 +60,11 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "MergedPolicyEvaluationServiceComponent";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
|
||||
|
||||
|
||||
@ -59,4 +59,9 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint {
|
||||
policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);*/
|
||||
return effectiveFeatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SimplePolicyEvaluationServiceComponent";
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,4 +43,6 @@ public interface PolicyEvaluationPoint {
|
||||
* @return returns the effective feature set.
|
||||
*/
|
||||
List<ProfileFeature> getEffectiveFeatures(List<Policy> policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException;
|
||||
|
||||
String getName();
|
||||
}
|
||||
|
||||
@ -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<Policy> policyList) throws PolicyEvaluationException {
|
||||
Collections.sort(policyList);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user