mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Changed policy evaluation point
This commit is contained in:
parent
62acc2ebf2
commit
35f3fcc8f9
@ -33,7 +33,7 @@ public class PolicyConfiguration {
|
|||||||
private int minRetriesToMarkUnreachable;
|
private int minRetriesToMarkUnreachable;
|
||||||
private int minRetriesToMarkInactive;
|
private int minRetriesToMarkInactive;
|
||||||
private List<String> platforms;
|
private List<String> platforms;
|
||||||
private String policyEvaluationPointName;
|
private String policyEvaluationPointName;
|
||||||
|
|
||||||
@XmlElement(name = "MonitoringClass", required = true)
|
@XmlElement(name = "MonitoringClass", required = true)
|
||||||
public String getMonitoringClass() {
|
public String getMonitoringClass() {
|
||||||
|
|||||||
@ -21,6 +21,7 @@ package org.wso2.carbon.policy.decision.point.internal;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
@ -51,11 +52,8 @@ public class MergedPolicyEvaluationServiceComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//TODO: fetch PEP class from config
|
|
||||||
|
|
||||||
|
|
||||||
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
|
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
|
||||||
new MergedPolicyEvaluationServiceComponent(), null);
|
new MergedEvaluationPoint(), null);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("Error occurred while initializing the policy evaluation bundle");
|
log.error("Error occurred while initializing the policy evaluation bundle");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,8 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint;
|
import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint;
|
||||||
|
import org.wso2.carbon.policy.decision.point.simple.PolicyEvaluationServiceImpl;
|
||||||
|
import org.wso2.carbon.policy.decision.point.simple.SimpleEvaluationImpl;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
@ -52,9 +54,8 @@ public class PolicyEvaluationServiceComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//TODO: fetch PEP class from config
|
|
||||||
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
|
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
|
||||||
new MergedEvaluationPoint(), null);
|
new PolicyEvaluationServiceImpl(), null);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("Error occurred while initializing the simple policy evaluation bundle");
|
log.error("Error occurred while initializing the simple policy evaluation bundle");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -173,6 +173,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
|
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
|
||||||
|
PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
||||||
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.internal;
|
package org.wso2.carbon.policy.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
@ -36,6 +38,7 @@ public class PolicyManagementDataHolder {
|
|||||||
private RealmService realmService;
|
private RealmService realmService;
|
||||||
private TenantManager tenantManager;
|
private TenantManager tenantManager;
|
||||||
private PolicyEvaluationPoint policyEvaluationPoint;
|
private PolicyEvaluationPoint policyEvaluationPoint;
|
||||||
|
private Map<String, PolicyEvaluationPoint> policyEvaluationPoints = new HashMap<>();
|
||||||
private PolicyInformationPoint policyInformationPoint;
|
private PolicyInformationPoint policyInformationPoint;
|
||||||
private DeviceManagementProviderService deviceManagementService;
|
private DeviceManagementProviderService deviceManagementService;
|
||||||
private MonitoringManager monitoringManager;
|
private MonitoringManager monitoringManager;
|
||||||
@ -88,13 +91,23 @@ public class PolicyManagementDataHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PolicyEvaluationPoint getPolicyEvaluationPoint() {
|
public PolicyEvaluationPoint getPolicyEvaluationPoint() {
|
||||||
return policyEvaluationPoint;
|
PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance().
|
||||||
|
getDeviceManagementConfig().getPolicyConfiguration();
|
||||||
|
String policyEvaluationPointName = policyConfiguration.getPolicyEvaluationPointName();
|
||||||
|
return policyEvaluationPoints.get(policyEvaluationPointName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) {
|
public void putPolicyEvaluationPoint(String name, PolicyEvaluationPoint policyEvaluationPoint) {
|
||||||
this.policyEvaluationPoint = policyEvaluationPoint;
|
policyEvaluationPoints.put(name,policyEvaluationPoint);
|
||||||
|
// this.policyEvaluationPoint = policyEvaluationPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) {
|
||||||
|
policyEvaluationPoints.put(policyEvaluationPoint.getName(), this.policyEvaluationPoint);
|
||||||
|
// this.policyEvaluationPoint = policyEvaluationPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public PolicyInformationPoint getPolicyInformationPoint() {
|
public PolicyInformationPoint getPolicyInformationPoint() {
|
||||||
return policyInformationPoint;
|
return policyInformationPoint;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,9 +46,9 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|||||||
* policy="dynamic"
|
* policy="dynamic"
|
||||||
* bind="setRealmService"
|
* bind="setRealmService"
|
||||||
* unbind="unsetRealmService"
|
* unbind="unsetRealmService"
|
||||||
* @scr.reference name="org.wso2.carbon.devicemgt.simple.policy.evaluation.manager"
|
* @scr.reference name="org.wso2.carbon.devicemgt.policy.evaluation.manager"
|
||||||
* interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint"
|
* interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint"
|
||||||
* cardinality="1..1"
|
* cardinality="1..n"
|
||||||
* policy="dynamic"
|
* policy="dynamic"
|
||||||
* bind="setPEPService"
|
* bind="setPEPService"
|
||||||
* unbind="unsetPEPService"
|
* unbind="unsetPEPService"
|
||||||
@ -159,14 +159,14 @@ public class PolicyManagementServiceComponent {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Setting Policy Information Service");
|
log.debug("Setting Policy Information Service");
|
||||||
}
|
}
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(pepService);
|
PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(pepService.getName(), pepService);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unsetPEPService(PolicyEvaluationPoint pepService) {
|
protected void unsetPEPService(PolicyEvaluationPoint pepService) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Removing Policy Information Service");
|
log.debug("Removing Policy Information Service");
|
||||||
}
|
}
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null);
|
PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) {
|
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
|
|||||||
@Override
|
@Override
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest();
|
PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest();
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint);
|
PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -93,7 +93,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("activatePolicies"))
|
@Test(dependsOnMethods = ("activatePolicies"))
|
||||||
public void getEffectivePolicy() throws DeviceManagementException, PolicyEvaluationException {
|
public void getEffectivePolicy(DeviceIdentifier identifier) throws DeviceManagementException, PolicyEvaluationException {
|
||||||
|
|
||||||
log.debug("Getting effective policy for device started ..........");
|
log.debug("Getting effective policy for device started ..........");
|
||||||
|
|
||||||
@ -103,7 +103,6 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
|
|||||||
PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
||||||
|
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
|
||||||
identifier.setType(device.getType());
|
identifier.setType(device.getType());
|
||||||
identifier.setId(device.getDeviceIdentifier());
|
identifier.setId(device.getDeviceIdentifier());
|
||||||
Policy policy = evaluationPoint.getEffectivePolicy(identifier);
|
Policy policy = evaluationPoint.getEffectivePolicy(identifier);
|
||||||
|
|||||||
@ -79,7 +79,7 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "MergedPolicyEvaluationServiceComponent";
|
return "SimplePolicyEvaluationServiceComponent";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sortPolicies(List<Policy> policyList) throws PolicyEvaluationException {
|
public void sortPolicies(List<Policy> policyList) throws PolicyEvaluationException {
|
||||||
|
|||||||
@ -42,8 +42,8 @@
|
|||||||
<maxRetries>5</maxRetries>
|
<maxRetries>5</maxRetries>
|
||||||
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
||||||
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
|
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
|
||||||
<!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
|
<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>
|
||||||
<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>
|
<!--<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
|
||||||
</PolicyConfiguration>
|
</PolicyConfiguration>
|
||||||
</ManagementRepository>
|
</ManagementRepository>
|
||||||
</DeviceMgtConfiguration>
|
</DeviceMgtConfiguration>
|
||||||
|
|||||||
@ -43,8 +43,8 @@
|
|||||||
<MaxRetries>5</MaxRetries>
|
<MaxRetries>5</MaxRetries>
|
||||||
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
|
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
|
||||||
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
|
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
|
||||||
<!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
|
<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>
|
||||||
<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>
|
<!--<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
|
||||||
<Platforms>
|
<Platforms>
|
||||||
<Platform>android</Platform>
|
<Platform>android</Platform>
|
||||||
<Platform>ios</Platform>
|
<Platform>ios</Platform>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user