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.

4.x.x
Geeth Munasinghe 10 years ago
parent 7056b01d18
commit 5a253b286e

@ -18,17 +18,18 @@
package org.wso2.carbon.policy.information.point; 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.Feature;
import org.wso2.carbon.policy.mgt.common.PIPDeviceData; import org.wso2.carbon.policy.mgt.common.PIPDeviceData;
import org.wso2.carbon.policy.mgt.common.Policy; 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; import java.util.List;
public class PolicyInformationServiceImpl implements PolicyInformationService{ public class PolicyInformationServiceImpl implements PolicyInformationPoint {
@Override @Override
public void getDeviceData(PIPDeviceData pipDeviceData) { public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) {
return null;
} }
@Override @Override

@ -24,7 +24,7 @@ import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceRegistration;
import org.wso2.carbon.policy.information.point.PolicyInformationServiceImpl; 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 { public class PolicyInformationPointBundleActivator implements BundleActivator {
@ -38,7 +38,7 @@ public class PolicyInformationPointBundleActivator implements BundleActivator {
log.debug("Activating Policy information Point bundle."); log.debug("Activating Policy information Point bundle.");
} }
pipServiceRegRef = bundleContext.registerService(PolicyInformationService.class.getName(), pipServiceRegRef = bundleContext.registerService(PolicyInformationPoint.class.getName(),
new PolicyInformationServiceImpl(), null); new PolicyInformationServiceImpl(), null);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -55,7 +55,8 @@
<Private-Package>org.wso2.carbon.policy.mgt.common.internal</Private-Package> <Private-Package>org.wso2.carbon.policy.mgt.common.internal</Private-Package>
<Import-Package> <Import-Package>
org.apache.commons.logging, org.apache.commons.logging,
org.wso2.carbon.device.mgt.core.* org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.device.mgt.core.dto.*
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
org.wso2.carbon.policy.mgt.common.* org.wso2.carbon.policy.mgt.common.*

@ -18,14 +18,18 @@
package org.wso2.carbon.policy.mgt.common; 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.sql.Timestamp;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class PIPDeviceData { public class PIPDeviceData {
String deviceId; Device device;
String deviceType; DeviceType deviceType;
String ownershipType; String ownershipType;
List<String> userIds; List<String> userIds;
List<String> roles; List<String> roles;
@ -36,4 +40,75 @@ public class PIPDeviceData {
/*This will be used to record attributes to which would come from other PDPs*/ /*This will be used to record attributes to which would come from other PDPs*/
Map<String, Object> attributes; Map<String, Object> 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<String> getUserIds() {
return userIds;
}
public void setUserIds(List<String> userIds) {
this.userIds = userIds;
}
public List<String> getRoles() {
return roles;
}
public void setRoles(List<String> 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<String, Object> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
}
} }

@ -22,7 +22,7 @@ package org.wso2.carbon.policy.mgt.common;
* This interface defines the policy management which should be implemented by the plugins * 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 * This method adds a policy to the platform
@ -31,28 +31,21 @@ public interface PolicyAdministratorService {
* @return primary key (generated key) * @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 deviceType
* @param policy * @param policy
* @return primary key (generated key) * @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. * This method adds the policy to specific role.
@ -61,7 +54,7 @@ public interface PolicyAdministratorService {
* @param policy * @param policy
* @return primary key (generated key) * @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 * This method returns the policy of whole platform
@ -119,7 +112,7 @@ public interface PolicyAdministratorService {
* @return * @return
* @throws PolicyManagementException * @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 * @param profile
* @throws PolicyManagementException * @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;
} }

@ -19,26 +19,28 @@
package org.wso2.carbon.policy.mgt.common; package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.util.List; import java.util.List;
/** /**
* This is the interface which will be used to create plug-able policy decision points. * 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. * This method returns the effective policy from the list.
* @param pipDeviceData device information. * @param deviceIdentifier device information.
* @return returns the effective policy. * @return returns the effective policy.
*/ */
Policy getEffectivePolicy(PIPDeviceData pipDeviceData); Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier);
/** /**
* This class will return the effective feature set from the list. * 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. * @return returns the effective feature set.
*/ */
List<Feature> getEffectiveFeatures(PIPDeviceData pipDeviceData); List<Feature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier);
} }

@ -19,26 +19,30 @@
package org.wso2.carbon.policy.mgt.common; 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; import java.util.List;
/** /**
* This will be used retrieve data database. This interface has to be implemented by PIP. PIP will be plug-able. * 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 * 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. * 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. * This method will retrieve the policies related given device Data.
* @param pipDeviceData * @param pipDeviceData
* @return * @return
*/ */
List<Policy> getRelatedPolicies(PIPDeviceData pipDeviceData); List<Policy> getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException;
/** /**
* This is will retrieve the features related to device type. This feature list will be used for dynamically * 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 * @param deviceType
* @return * @return
*/ */
List<Feature> getRelatedFeatures(String deviceType); List<Feature> getRelatedFeatures(String deviceType) throws FeatureManagementException;
} }

@ -18,6 +18,8 @@
package org.wso2.carbon.policy.mgt.common; package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Timestamp; import java.sql.Timestamp;

@ -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 {
}
}

@ -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);
}
}

@ -68,7 +68,8 @@
org.wso2.carbon.policy.mgt.common.*, org.wso2.carbon.policy.mgt.common.*,
org.wso2.carbon.user.core.*, org.wso2.carbon.user.core.*,
org.wso2.carbon.utils.*, org.wso2.carbon.utils.*,
org.wso2.carbon.device.mgt.core.* org.wso2.carbon.device.mgt.core.*,
org.wso2.carbon.device.mgt.common.*
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
!org.wso2.carbon.policy.mgt.core.internal, !org.wso2.carbon.policy.mgt.core.internal,

@ -27,13 +27,15 @@ import java.util.List;
public interface PolicyDAO { 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; Policy getPolicy() throws PolicyManagerDAOException;
@ -43,7 +45,9 @@ public interface PolicyDAO {
void deletePolicy(Policy policy) throws PolicyManagerDAOException; 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; void deleteProfile(Profile profile) throws PolicyManagerDAOException;
@ -60,4 +64,6 @@ public interface PolicyDAO {
void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException; void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException;
Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException;
Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException;
} }

@ -42,13 +42,13 @@ public class PolicyDAOImpl implements PolicyDAO {
@Override @Override
public int addPolicy(Policy policy) throws PolicyManagerDAOException { public Policy addPolicy(Policy policy) throws PolicyManagerDAOException {
persistPolicy(policy); persistPolicy(policy);
return policy.getId(); return policy;
} }
@Override @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. // First persist the policy to the data base.
persistPolicy(policy); persistPolicy(policy);
@ -73,12 +73,17 @@ public class PolicyDAOImpl implements PolicyDAO {
PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
} }
return policy.getId(); return policy;
} }
@Override @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. // First persist the policy to the data base.
persistPolicy(policy); persistPolicy(policy);
@ -96,11 +101,11 @@ public class PolicyDAOImpl implements PolicyDAO {
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
} }
return 0; return policy;
} }
@Override @Override
public void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException { public Policy updatePolicy(Policy policy) throws PolicyManagerDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -114,6 +119,8 @@ public class PolicyDAOImpl implements PolicyDAO {
} finally { } finally {
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
} }
return policy;
} }
@Override @Override
@ -219,7 +226,7 @@ public class PolicyDAOImpl implements PolicyDAO {
int tenantId = -1234; int tenantId = -1234;
try { try {
conn = this.getConnection(); 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 = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS);
stmt.setString(1, policy.getPolicyName()); 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; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet generatedKeys = null; ResultSet generatedKeys = null;
@ -319,6 +326,13 @@ public class PolicyDAOImpl implements PolicyDAO {
} finally { } finally {
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
} }
return profile;
}
public Profile updateProfile(Profile profile) throws PolicyManagerDAOException {
return profile;
} }
@Override @Override
@ -398,6 +412,12 @@ public class PolicyDAOImpl implements PolicyDAO {
return feature; return feature;
} }
@Override
public Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException {
return feature;
}
@Override @Override
public List<Profile> getAllProfiles() throws PolicyManagerDAOException { public List<Profile> getAllProfiles() throws PolicyManagerDAOException {
Connection conn = null; Connection conn = null;

@ -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<Policy> getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException {
return null;
}
@Override
public List<Feature> getRelatedFeatures(String deviceType) throws FeatureManagementException {
return null;
}
}

@ -21,11 +21,13 @@ package org.wso2.carbon.policy.mgt.core.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.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.PolicyConfigurationManager;
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig; 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.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; 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; import org.wso2.carbon.user.core.service.RealmService;
/** /**
@ -37,7 +39,7 @@ import org.wso2.carbon.user.core.service.RealmService;
* bind="setRealmService" * bind="setRealmService"
* unbind="unsetRealmService" * unbind="unsetRealmService"
* @scr.reference name="org.wso2.carbon.devicemgt.policy.information.point.default" * @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" * cardinality="1..1"
* policy="dynamic" * policy="dynamic"
* bind="setPIPService" * bind="setPIPService"
@ -56,6 +58,9 @@ public class PolicyManagementServiceComponent {
DataSourceConfig dsConfig = config.getPolicyManagementRepository().getDataSourceConfig(); DataSourceConfig dsConfig = config.getPolicyManagementRepository().getDataSourceConfig();
PolicyManagementDAOFactory.init(dsConfig); PolicyManagementDAOFactory.init(dsConfig);
componentContext.getBundleContext().registerService(
PolicyManager.class.getName(), new PolicyManagementService(), null);
} catch (Throwable t) { } catch (Throwable t) {
String msg = "Error occurred while initializing the Policy management core."; String msg = "Error occurred while initializing the Policy management core.";
log.error(msg, t); log.error(msg, t);
@ -89,13 +94,13 @@ public class PolicyManagementServiceComponent {
} }
protected void setPIPService(PolicyInformationService policyInformationService) { protected void setPIPService(PolicyInformationPoint policyInformationService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Policy Information Service"); log.debug("Setting Policy Information Service");
} }
} }
protected void unsetPIPService(PolicyInformationService policyInformationService) { protected void unsetPIPService(PolicyInformationPoint policyInformationService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Unsetting Policy Information Service"); log.debug("Unsetting Policy Information Service");
} }

@ -59,5 +59,9 @@
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId> <artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -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);
}
}

@ -18,21 +18,22 @@
package org.wso2.carbon.simple.policy.decision.point; 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.Feature;
import org.wso2.carbon.policy.mgt.common.PIPDeviceData; import org.wso2.carbon.policy.mgt.common.PIPDeviceData;
import org.wso2.carbon.policy.mgt.common.Policy; 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; import java.util.List;
public class PolicyEvaluationServiceImpl implements PolicyEvaluationService { public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint {
@Override @Override
public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) { public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) {
return null; return null;
} }
@Override @Override
public List<Feature> getEffectiveFeatures(PIPDeviceData pipDeviceData) { public List<Feature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) {
return null; return null;
} }
} }

@ -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;
}

@ -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;
}
}
Loading…
Cancel
Save