From 5a253b286e5dea5ae2375ceed10df6df613e1e44 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Wed, 18 Mar 2015 12:08:25 +0530 Subject: [PATCH] Adding the policy management service and dao implementation, basic architecture is implemented here, only thing we have to do is to fill the method with relavant informations. PDP, PEP, PIP services are renamed. --- .../point/PolicyInformationServiceImpl.java | 9 +- ...PolicyInformationPointBundleActivator.java | 4 +- .../org.wso2.carbon.policy.mgt.common/pom.xml | 3 +- .../policy/mgt/common/PIPDeviceData.java | 79 ++++++++++++++++- ...ice.java => PolicyAdministratorPoint.java} | 36 ++++---- ...ervice.java => PolicyEvaluationPoint.java} | 12 +-- ...rvice.java => PolicyInformationPoint.java} | 14 +-- .../carbon/policy/mgt/common/Profile.java | 2 + .../mgt/common/impl/PolicyManagement.java | 88 ------------------- .../mgt/common/PolicyManagementTestCase.java | 54 ------------ .../org.wso2.carbon.policy.mgt.core/pom.xml | 3 +- .../carbon/policy/mgt/core/dao/PolicyDAO.java | 16 ++-- .../mgt/core/dao/impl/PolicyDAOImpl.java | 38 ++++++-- .../core/impl/PolicyInformationPointImpl.java | 67 ++++++++++++++ .../PolicyManagementServiceComponent.java | 13 ++- .../pom.xml | 4 + .../point/PolicyEvaluationException.java | 55 ++++++++++++ .../point/PolicyEvaluationServiceImpl.java | 9 +- .../decision/point/SimpleEvaluation.java | 31 +++++++ .../decision/point/SimpleEvaluationImpl.java | 47 ++++++++++ 20 files changed, 383 insertions(+), 201 deletions(-) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyAdministratorService.java => PolicyAdministratorPoint.java} (75%) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyEvaluationService.java => PolicyEvaluationPoint.java} (75%) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyInformationService.java => PolicyInformationPoint.java} (77%) delete mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java delete mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java index 5ce43efddf4..2cdb6bcf9fa 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java @@ -18,17 +18,18 @@ package org.wso2.carbon.policy.information.point; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.PIPDeviceData; import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyInformationService; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; import java.util.List; -public class PolicyInformationServiceImpl implements PolicyInformationService{ +public class PolicyInformationServiceImpl implements PolicyInformationPoint { @Override - public void getDeviceData(PIPDeviceData pipDeviceData) { - + public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) { + return null; } @Override diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java index c25b2855dba..b28a545dd6e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java @@ -24,7 +24,7 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.wso2.carbon.policy.information.point.PolicyInformationServiceImpl; -import org.wso2.carbon.policy.mgt.common.PolicyInformationService; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; public class PolicyInformationPointBundleActivator implements BundleActivator { @@ -38,7 +38,7 @@ public class PolicyInformationPointBundleActivator implements BundleActivator { log.debug("Activating Policy information Point bundle."); } - pipServiceRegRef = bundleContext.registerService(PolicyInformationService.class.getName(), + pipServiceRegRef = bundleContext.registerService(PolicyInformationPoint.class.getName(), new PolicyInformationServiceImpl(), null); if (log.isDebugEnabled()) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index bf119e445d9..1685a5b72ad 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -55,7 +55,8 @@ org.wso2.carbon.policy.mgt.common.internal org.apache.commons.logging, - org.wso2.carbon.device.mgt.core.* + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.core.dto.* org.wso2.carbon.policy.mgt.common.* diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java index caf5c81e2cd..d234fa96b1a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java @@ -18,14 +18,18 @@ package org.wso2.carbon.policy.mgt.common; + +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; + import java.sql.Timestamp; import java.util.List; import java.util.Map; public class PIPDeviceData { - String deviceId; - String deviceType; + Device device; + DeviceType deviceType; String ownershipType; List userIds; List roles; @@ -36,4 +40,75 @@ public class PIPDeviceData { /*This will be used to record attributes to which would come from other PDPs*/ Map attributes; + public Device getDevice() { + return device; + } + + public void setDevice(Device device) { + this.device = device; + } + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } + + public String getOwnershipType() { + return ownershipType; + } + + public void setOwnershipType(String ownershipType) { + this.ownershipType = ownershipType; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } + + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + public String getAltitude() { + return altitude; + } + + public void setAltitude(String altitude) { + this.altitude = altitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public Timestamp getTimestamp() { + return timestamp; + } + + public void setTimestamp(Timestamp timestamp) { + this.timestamp = timestamp; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java similarity index 75% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index 4fb239d1fbe..2174b64c12c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java @@ -22,7 +22,7 @@ package org.wso2.carbon.policy.mgt.common; * This interface defines the policy management which should be implemented by the plugins */ -public interface PolicyAdministratorService { +public interface PolicyAdministratorPoint { /** * This method adds a policy to the platform @@ -31,28 +31,21 @@ public interface PolicyAdministratorService { * @return primary key (generated key) */ - int addPolicy(Policy policy); + Policy addPolicy(Policy policy) throws PolicyManagementException; - /** - * This method adds a policy per device which should be implemented by the related plugins. - * - * @param deviceId - * @param deviceType - * @param policy - * @return primary key (generated key) - */ - int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; + Policy updatePolicy(Policy policy) throws PolicyManagementException; /** - * This method adds a policy to device type by the related device type plugins. + * This method adds a policy per device which should be implemented by the related plugins. * + * @param deviceId * @param deviceType * @param policy * @return primary key (generated key) */ - int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; + Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; /** * This method adds the policy to specific role. @@ -61,7 +54,7 @@ public interface PolicyAdministratorService { * @param policy * @return primary key (generated key) */ - int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException; + Policy addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException; /** * This method returns the policy of whole platform @@ -119,7 +112,7 @@ public interface PolicyAdministratorService { * @return * @throws PolicyManagementException */ - boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException; + boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException; /** @@ -135,7 +128,16 @@ public interface PolicyAdministratorService { * @param profile * @throws PolicyManagementException */ - void addProfile(Profile profile) throws PolicyManagementException; + Profile addProfile(Profile profile) throws PolicyManagementException; + + boolean deleteProfile(int profileId) throws PolicyManagementException; + + Profile updateProfile(Profile profile) throws PolicyManagementException; + + Feature addFeature(Feature feature) throws FeatureManagementException; + + Feature updateFeature(Feature feature) throws FeatureManagementException; + + void deleteFeature(int featureId) throws FeatureManagementException; - void deleteProfile(int profileId) throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java similarity index 75% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java index b5082c578d5..944e3aa6201 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java @@ -19,26 +19,28 @@ package org.wso2.carbon.policy.mgt.common; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; + import java.util.List; /** * This is the interface which will be used to create plug-able policy decision points. */ -public interface PolicyEvaluationService { +public interface PolicyEvaluationPoint { /** * This method returns the effective policy from the list. - * @param pipDeviceData device information. + * @param deviceIdentifier device information. * @return returns the effective policy. */ - Policy getEffectivePolicy(PIPDeviceData pipDeviceData); + Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier); /** * This class will return the effective feature set from the list. - * @param pipDeviceData device information. + * @param deviceIdentifier device information. * @return returns the effective feature set. */ - List getEffectiveFeatures(PIPDeviceData pipDeviceData); + List getEffectiveFeatures(DeviceIdentifier deviceIdentifier); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java similarity index 77% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java index ea9509506a0..0ba6f912ffa 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java @@ -19,26 +19,30 @@ package org.wso2.carbon.policy.mgt.common; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.dto.Device; + import java.util.List; /** * This will be used retrieve data database. This interface has to be implemented by PIP. PIP will be plug-able. */ -public interface PolicyInformationService { +public interface PolicyInformationPoint { /** * This method will return the data related Device, Some of the device data will provided in the initial pipDeviceData object such as * device id, device time and location, Other data such as roles, owned users and ownership type will be filled by this method. - * @param pipDeviceData device data. + * @param deviceIdentifier device data. + * @return PIPDeviceData */ - void getDeviceData(PIPDeviceData pipDeviceData); + PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; /** * This method will retrieve the policies related given device Data. * @param pipDeviceData * @return */ - List getRelatedPolicies(PIPDeviceData pipDeviceData); + List getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException; /** * This is will retrieve the features related to device type. This feature list will be used for dynamically @@ -46,5 +50,5 @@ public interface PolicyInformationService { * @param deviceType * @return */ - List getRelatedFeatures(String deviceType); + List getRelatedFeatures(String deviceType) throws FeatureManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java index e81dc42eb8b..9df30554a0a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java @@ -18,6 +18,8 @@ package org.wso2.carbon.policy.mgt.common; + + import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.sql.Timestamp; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java deleted file mode 100644 index 77ba5b6fe80..00000000000 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2014, 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.mgt.common.impl; - -import org.wso2.carbon.policy.mgt.common.*; - -public class PolicyManagement implements PolicyAdministratorService { - @Override - public int addPolicy(Policy policy) { - return 0; - } - - @Override - public int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException { - return 0; - } - - @Override - public int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException { - return 0; - } - - @Override - public int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException { - return 0; - } - - @Override - public Policy getPolicy() { - return null; - } - - @Override - public Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException { - return null; - } - - @Override - public Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException { - return null; - } - - @Override - public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException { - return null; - } - - @Override - public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException { - return false; - } - - @Override - public boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException { - return false; - } - - @Override - public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException { - - } - - @Override - public void addProfile(Profile profile) throws PolicyManagementException { - - } - - @Override - public void deleteProfile(int profileId) throws PolicyManagementException { - - } -} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java deleted file mode 100644 index 568c59684ef..00000000000 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2014, 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.wos2.carbon.policy.mgt.common; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.testng.Assert; -import org.testng.annotations.Test; -import org.wos2.carbon.policy.mgt.common.utils.PolicyCreator; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.impl.PolicyManagement; - -public class PolicyManagementTestCase { - - private static final Log log = LogFactory.getLog(PolicyManagementTestCase.class); - - Policy policy = PolicyCreator.createPolicy(); - - private PolicyManagement policyManagement = new PolicyManagement(); - - @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device") - public void testAddPolicy() throws FeatureManagementException, PolicyManagementException { - Assert.assertEquals(policyManagement.addPolicyToDevice("1212-ESDD-12ER-7890", "MD", policy), 0); - } - - @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device type") - public void testAddPolicyToDeviceType() throws FeatureManagementException, PolicyManagementException { - Assert.assertEquals(policyManagement.addPolicyToDeviceType("MD", policy), 0); - } - - @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a user Role") - public void testAddPolicyToRole() throws FeatureManagementException, PolicyManagementException { - Assert.assertEquals(policyManagement.addPolicyToRole("Admin", policy), 0); - } - -} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 0a08696f4eb..9f4a7527140 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -68,7 +68,8 @@ org.wso2.carbon.policy.mgt.common.*, org.wso2.carbon.user.core.*, org.wso2.carbon.utils.*, - org.wso2.carbon.device.mgt.core.* + org.wso2.carbon.device.mgt.core.*, + org.wso2.carbon.device.mgt.common.* !org.wso2.carbon.policy.mgt.core.internal, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java index 9fd866f51f6..0ed1d8e529b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -27,13 +27,15 @@ import java.util.List; public interface PolicyDAO { - int addPolicy(Policy policy) throws PolicyManagerDAOException; + Policy addPolicy(Policy policy) throws PolicyManagerDAOException; - int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException; + Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException; - int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException; + Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException; - void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException; + Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException; + + Policy updatePolicy(Policy policy) throws PolicyManagerDAOException; Policy getPolicy() throws PolicyManagerDAOException; @@ -43,7 +45,9 @@ public interface PolicyDAO { void deletePolicy(Policy policy) throws PolicyManagerDAOException; - void addProfile(Profile profile) throws PolicyManagerDAOException; + Profile addProfile(Profile profile) throws PolicyManagerDAOException; + + Profile updateProfile(Profile profile) throws PolicyManagerDAOException; void deleteProfile(Profile profile) throws PolicyManagerDAOException; @@ -60,4 +64,6 @@ public interface PolicyDAO { void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException; Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; + + Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index e5afa35ec2b..20b46af07c9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -42,13 +42,13 @@ public class PolicyDAOImpl implements PolicyDAO { @Override - public int addPolicy(Policy policy) throws PolicyManagerDAOException { + public Policy addPolicy(Policy policy) throws PolicyManagerDAOException { persistPolicy(policy); - return policy.getId(); + return policy; } @Override - public int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException { + public Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException { // First persist the policy to the data base. persistPolicy(policy); @@ -73,12 +73,17 @@ public class PolicyDAOImpl implements PolicyDAO { PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); } - return policy.getId(); + return policy; } @Override - public int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException { + public Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException { + return null; + } + + @Override + public Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException { // First persist the policy to the data base. persistPolicy(policy); @@ -96,11 +101,11 @@ public class PolicyDAOImpl implements PolicyDAO { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } - return 0; + return policy; } @Override - public void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException { + public Policy updatePolicy(Policy policy) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -114,6 +119,8 @@ public class PolicyDAOImpl implements PolicyDAO { } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } + + return policy; } @Override @@ -219,7 +226,7 @@ public class PolicyDAOImpl implements PolicyDAO { int tenantId = -1234; try { conn = this.getConnection(); - String query = "IINSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID) VALUES (?, ?, ?)"; + String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); stmt.setString(1, policy.getPolicyName()); @@ -276,7 +283,7 @@ public class PolicyDAOImpl implements PolicyDAO { } } - public void addProfile(Profile profile) throws PolicyManagerDAOException { + public Profile addProfile(Profile profile) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; ResultSet generatedKeys = null; @@ -319,6 +326,13 @@ public class PolicyDAOImpl implements PolicyDAO { } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } + + return profile; + } + + + public Profile updateProfile(Profile profile) throws PolicyManagerDAOException { + return profile; } @Override @@ -398,6 +412,12 @@ public class PolicyDAOImpl implements PolicyDAO { return feature; } + + @Override + public Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException { + return feature; + } + @Override public List getAllProfiles() throws PolicyManagerDAOException { Connection conn = null; 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 new file mode 100644 index 00000000000..4bec7d69800 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java @@ -0,0 +1,67 @@ +/* +* 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.mgt.core.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl; +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.policy.mgt.common.*; + +import java.util.List; + +public class PolicyInformationPointImpl implements PolicyInformationPoint { + + private static final Log log = LogFactory.getLog(PolicyInformationPointImpl.class); + DeviceDAOImpl deviceDAO; + + public PolicyInformationPointImpl() { + deviceDAO = new DeviceDAOImpl(DeviceManagementDAOFactory.getDataSource()); + } + + @Override + public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + PIPDeviceData pipDeviceData = new PIPDeviceData(); + Device device; + try { + device = deviceDAO.getDevice(deviceIdentifier); + pipDeviceData.setDevice(device); + + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred when retrieving the data related to device from the database."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + + return pipDeviceData; + } + + @Override + public List getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException { + return null; + } + + @Override + public List getRelatedFeatures(String deviceType) throws FeatureManagementException { + return null; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index 16255d95dcc..f7fce484b16 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -21,11 +21,13 @@ package org.wso2.carbon.policy.mgt.core.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.PolicyInformationService; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.core.PolicyManager; import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager; import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; +import org.wso2.carbon.policy.mgt.core.service.PolicyManagementService; import org.wso2.carbon.user.core.service.RealmService; /** @@ -37,7 +39,7 @@ import org.wso2.carbon.user.core.service.RealmService; * bind="setRealmService" * unbind="unsetRealmService" * @scr.reference name="org.wso2.carbon.devicemgt.policy.information.point.default" - * interface="org.wso2.carbon.policy.mgt.common.PolicyInformationService" + * interface="org.wso2.carbon.policy.mgt.common.PolicyInformationPoint" * cardinality="1..1" * policy="dynamic" * bind="setPIPService" @@ -56,6 +58,9 @@ public class PolicyManagementServiceComponent { DataSourceConfig dsConfig = config.getPolicyManagementRepository().getDataSourceConfig(); PolicyManagementDAOFactory.init(dsConfig); + componentContext.getBundleContext().registerService( + PolicyManager.class.getName(), new PolicyManagementService(), null); + } catch (Throwable t) { String msg = "Error occurred while initializing the Policy management core."; log.error(msg, t); @@ -89,13 +94,13 @@ public class PolicyManagementServiceComponent { } - protected void setPIPService(PolicyInformationService policyInformationService) { + protected void setPIPService(PolicyInformationPoint policyInformationService) { if (log.isDebugEnabled()) { log.debug("Setting Policy Information Service"); } } - protected void unsetPIPService(PolicyInformationService policyInformationService) { + protected void unsetPIPService(PolicyInformationPoint policyInformationService) { if (log.isDebugEnabled()) { log.debug("Unsetting Policy Information Service"); } diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml index f6fe137b9b7..58a7644503e 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml @@ -59,5 +59,9 @@ org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.common + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java new file mode 100644 index 00000000000..f3dcdb6cd5c --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java @@ -0,0 +1,55 @@ +/* +* 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.simple.policy.decision.point; + +public class PolicyEvaluationException extends Exception { + + private String policyErrorMessage; + + public String getPolicyErrorMessage() { + return policyErrorMessage; + } + + public void setPolicyErrorMessage(String policyErrorMessage) { + this.policyErrorMessage = policyErrorMessage; + } + + public PolicyEvaluationException(String message) { + super(message); + setPolicyErrorMessage(message); + } + + public PolicyEvaluationException(String message, Exception ex) { + super(message, ex); + setPolicyErrorMessage(message); + } + + public PolicyEvaluationException(String message, Throwable cause) { + super(message, cause); + setPolicyErrorMessage(message); + } + + public PolicyEvaluationException() { + super(); + } + + public PolicyEvaluationException(Throwable cause) { + super(cause); + } +} diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java index fbeb04c7a48..21e3888e806 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java @@ -18,21 +18,22 @@ package org.wso2.carbon.simple.policy.decision.point; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.PIPDeviceData; import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationService; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import java.util.List; -public class PolicyEvaluationServiceImpl implements PolicyEvaluationService { +public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { @Override - public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) { + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) { return null; } @Override - public List getEffectiveFeatures(PIPDeviceData pipDeviceData) { + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) { return null; } } diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java new file mode 100644 index 00000000000..f1d076d0fdc --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java @@ -0,0 +1,31 @@ +/* +* 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.simple.policy.decision.point; + +import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.Policy; + +public interface SimpleEvaluation { + + void sortPolicy(Policy policy) throws PolicyEvaluationException; + + Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException; + +} diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java new file mode 100644 index 00000000000..95f902a985b --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java @@ -0,0 +1,47 @@ +/* +* 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.simple.policy.decision.point; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; + +public class SimpleEvaluationImpl implements SimpleEvaluation { + + private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class); + + PolicyDAOImpl policyDAO; + + + public SimpleEvaluationImpl() { + policyDAO = new PolicyDAOImpl(); + } + + @Override + public void sortPolicy(Policy policy) throws PolicyEvaluationException { + + } + + @Override + public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException { + return null; + } +}