mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fine tuning the code and removing PIP as osgi service
This commit is contained in:
parent
cf4a2f8fc4
commit
93ba0414bc
@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.common;
|
|||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -28,12 +29,11 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* This class will be the used to create policy object with relevant information for evaluating.
|
* This class will be the used to create policy object with relevant information for evaluating.
|
||||||
*/
|
*/
|
||||||
public class Policy implements Comparable<Policy> {
|
public class Policy implements Comparable<Policy>, Serializable {
|
||||||
|
|
||||||
private int id; // Identifier of the policy.
|
private int id; // Identifier of the policy.
|
||||||
private int priorityId; // Priority of the policies. This will be used only for simple evaluation.
|
private int priorityId; // Priority of the policies. This will be used only for simple evaluation.
|
||||||
private Profile profile; // Profile
|
private Profile profile; // Profile
|
||||||
private int profileId;
|
|
||||||
private String policyName; // Name of the policy.
|
private String policyName; // Name of the policy.
|
||||||
private boolean generic; // If true, this should be applied to all related device.
|
private boolean generic; // If true, this should be applied to all related device.
|
||||||
private List<String> roleList; // Roles which this policy should be applied.
|
private List<String> roleList; // Roles which this policy should be applied.
|
||||||
@ -57,6 +57,7 @@ public class Policy implements Comparable<Policy> {
|
|||||||
private String longitude; // Longitude
|
private String longitude; // Longitude
|
||||||
|
|
||||||
private int tenantId;
|
private int tenantId;
|
||||||
|
private int profileId;
|
||||||
|
|
||||||
/*This will be used to record attributes which will be used by customer extended PDPs and PIPs*/
|
/*This will be used to record attributes which will be used by customer extended PDPs and PIPs*/
|
||||||
|
|
||||||
|
|||||||
@ -31,8 +31,6 @@ public interface PolicyAdministratorPoint {
|
|||||||
/**
|
/**
|
||||||
* This method adds a policy to the platform
|
* This method adds a policy to the platform
|
||||||
*
|
*
|
||||||
* @param policy
|
|
||||||
* @return primary key (generated key)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Policy addPolicy(Policy policy) throws PolicyManagementException;
|
Policy addPolicy(Policy policy) throws PolicyManagementException;
|
||||||
@ -40,13 +38,10 @@ public interface PolicyAdministratorPoint {
|
|||||||
|
|
||||||
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
|
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds a policy per device which should be implemented by the related plugins.
|
* This method adds a policy per device which should be implemented by the related plugins.
|
||||||
*
|
|
||||||
* @param deviceIdentifierList
|
|
||||||
* @param policy
|
|
||||||
* @return
|
|
||||||
* @throws PolicyManagementException
|
|
||||||
*/
|
*/
|
||||||
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException;
|
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
@ -132,7 +127,7 @@ public interface PolicyAdministratorPoint {
|
|||||||
*/
|
*/
|
||||||
Profile addProfile(Profile profile) throws PolicyManagementException;
|
Profile addProfile(Profile profile) throws PolicyManagementException;
|
||||||
|
|
||||||
boolean deleteProfile(int profileId) throws PolicyManagementException;
|
boolean deleteProfile(Profile profile) throws PolicyManagementException;
|
||||||
|
|
||||||
Profile updateProfile(Profile profile) throws PolicyManagementException;
|
Profile updateProfile(Profile profile) throws PolicyManagementException;
|
||||||
|
|
||||||
|
|||||||
@ -119,6 +119,10 @@
|
|||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.core</artifactId>
|
<artifactId>org.wso2.carbon.core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.base</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core;
|
package org.wso2.carbon.policy.mgt.core;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.policy.mgt.common.*;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
|
|
||||||
@ -39,9 +38,11 @@ public interface PolicyManagerService {
|
|||||||
|
|
||||||
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
|
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||||
|
|
||||||
Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException;
|
List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException;
|
||||||
|
|
||||||
List<Policy> getPolicies(String deviceType) throws PolicyManagementException;
|
List<Policy> getPolicies(String deviceType) throws PolicyManagementException;
|
||||||
|
|
||||||
@ -50,4 +51,6 @@ public interface PolicyManagerService {
|
|||||||
PolicyAdministratorPoint getPAP() throws PolicyManagementException;
|
PolicyAdministratorPoint getPAP() throws PolicyManagementException;
|
||||||
|
|
||||||
PolicyInformationPoint getPIP() throws PolicyManagementException;
|
PolicyInformationPoint getPIP() throws PolicyManagementException;
|
||||||
|
|
||||||
|
PolicyEvaluationPoint getPEP() throws PolicyManagementException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|||||||
import org.wso2.carbon.policy.mgt.common.*;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
|
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
|
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -68,18 +69,40 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||||
return null;
|
return policyAdministratorPoint.deletePolicy(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException {
|
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
return null;
|
try {
|
||||||
|
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
|
||||||
|
getEffectivePolicies(deviceIdentifier);
|
||||||
|
} catch (PolicyEvaluationException e) {
|
||||||
|
String msg = "Error occurred while getting the effective policies from the PEP service for device " +
|
||||||
|
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws
|
||||||
|
FeatureManagementException {
|
||||||
|
try {
|
||||||
|
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
|
||||||
|
getEffectiveFeatures(deviceIdentifier);
|
||||||
|
} catch (PolicyEvaluationException e) {
|
||||||
|
String msg = "Error occurred while getting the effective features from the PEP service " +
|
||||||
|
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new FeatureManagementException(msg, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Policy> getPolicies(String deviceType) throws PolicyManagementException {
|
public List<Policy> getPolicies(String deviceType) throws PolicyManagementException {
|
||||||
return null;
|
return policyAdministratorPoint.getPoliciesOfDeviceType(deviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -96,4 +119,9 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
|
|||||||
public PolicyInformationPoint getPIP() throws PolicyManagementException {
|
public PolicyInformationPoint getPIP() throws PolicyManagementException {
|
||||||
return new PolicyInformationPointImpl();
|
return new PolicyInformationPointImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
|
||||||
|
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,4 +73,13 @@ public interface PolicyDAO {
|
|||||||
|
|
||||||
PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException;
|
PolicyLocations getLocationsOfPolicy(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||||
|
throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void setPolicyApplied(int deviceId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void updateEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||||
|
throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,23 +20,22 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
|
|||||||
|
|
||||||
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.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyDates;
|
import org.wso2.carbon.policy.mgt.common.PolicyDates;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyLocations;
|
import org.wso2.carbon.policy.mgt.common.PolicyLocations;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyTimes;
|
import org.wso2.carbon.policy.mgt.common.PolicyTimes;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
||||||
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.dao.PolicyManagerDAOException;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.Date;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PolicyDAOImpl implements PolicyDAO {
|
public class PolicyDAOImpl implements PolicyDAO {
|
||||||
@ -200,7 +199,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws PolicyManagerDAOException {
|
public Policy addLocationToPolicy(String latitude, String longitude, Policy policy) throws
|
||||||
|
PolicyManagerDAOException {
|
||||||
|
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -270,6 +270,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
policy.setId(policyId);
|
policy.setId(policyId);
|
||||||
policy.setPolicyName(resultSet.getString("NAME"));
|
policy.setPolicyName(resultSet.getString("NAME"));
|
||||||
policy.setTenantId(resultSet.getInt("TENANT_ID"));
|
policy.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
policy.setPriorityId(resultSet.getInt("PRIORITY"));
|
||||||
}
|
}
|
||||||
return policy;
|
return policy;
|
||||||
|
|
||||||
@ -302,6 +303,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
policy.setId(resultSet.getInt("ID"));
|
policy.setId(resultSet.getInt("ID"));
|
||||||
policy.setPolicyName(resultSet.getString("NAME"));
|
policy.setPolicyName(resultSet.getString("NAME"));
|
||||||
policy.setTenantId(resultSet.getInt("TENANT_ID"));
|
policy.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
policy.setPriorityId(resultSet.getInt("PRIORITY"));
|
||||||
}
|
}
|
||||||
return policy;
|
return policy;
|
||||||
|
|
||||||
@ -335,6 +337,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
|
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
|
||||||
policy.setPolicyName(resultSet.getString("NAME"));
|
policy.setPolicyName(resultSet.getString("NAME"));
|
||||||
policy.setTenantId(resultSet.getInt("TENANT_ID"));
|
policy.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
policy.setPriorityId(resultSet.getInt("PRIORITY"));
|
||||||
policies.add(policy);
|
policies.add(policy);
|
||||||
}
|
}
|
||||||
return policies;
|
return policies;
|
||||||
@ -432,7 +435,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
//TODO:
|
|
||||||
policy.setStartTime(resultSet.getInt("STARTING_TIME"));
|
policy.setStartTime(resultSet.getInt("STARTING_TIME"));
|
||||||
policy.setEndTime(resultSet.getInt("ENDING_TIME"));
|
policy.setEndTime(resultSet.getInt("ENDING_TIME"));
|
||||||
|
|
||||||
@ -467,7 +469,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
//TODO:
|
|
||||||
policy.setStartDate(resultSet.getDate("START_DATE"));
|
policy.setStartDate(resultSet.getDate("START_DATE"));
|
||||||
policy.setEndDate(resultSet.getDate("END_DATE"));
|
policy.setEndDate(resultSet.getDate("END_DATE"));
|
||||||
|
|
||||||
@ -502,7 +504,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
//TODO:
|
|
||||||
policy.setLatitude(resultSet.getString("LATITUDE"));
|
policy.setLatitude(resultSet.getString("LATITUDE"));
|
||||||
policy.setLongitude(resultSet.getString("LONGITUDE"));
|
policy.setLongitude(resultSet.getString("LONGITUDE"));
|
||||||
|
|
||||||
@ -521,6 +523,116 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||||
|
throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED " +
|
||||||
|
"(DEVICE_ID, POLICY_ID, POLICY_CONTENT, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, policyId);
|
||||||
|
stmt.setObject(3, profileFeatures);
|
||||||
|
stmt.setTimestamp(4, currentTimestamp);
|
||||||
|
stmt.setTimestamp(5, currentTimestamp);
|
||||||
|
|
||||||
|
stmt.executeQuery();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while adding the evaluated feature list to device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPolicyApplied(int deviceId) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? ";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setTimestamp(1, currentTimestamp);
|
||||||
|
stmt.setBoolean(2, true);
|
||||||
|
stmt.setInt(3, deviceId);
|
||||||
|
|
||||||
|
stmt.executeQuery();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while updating applied policy to device (" + deviceId + ")";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||||
|
throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ? UPDATED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, policyId);
|
||||||
|
stmt.setObject(2, profileFeatures);
|
||||||
|
stmt.setTimestamp(3, currentTimestamp);
|
||||||
|
stmt.setBoolean(4, false);
|
||||||
|
stmt.setInt(5, deviceId);
|
||||||
|
stmt.executeQuery();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while updating the evaluated feature list to device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException {
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
boolean exist = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
exist = resultSet.next();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while checking whether device (" + deviceId + ") has a policy to apply.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
|
this.closeConnection();
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> getPolicyIdsOfDevice(Device device) throws PolicyManagerDAOException {
|
public List<Integer> getPolicyIdsOfDevice(Device device) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
@ -711,8 +823,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet generatedKeys = null;
|
ResultSet generatedKeys = null;
|
||||||
|
int tenantId = PolicyManagerUtil.getTenantId();
|
||||||
|
|
||||||
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY) VALUES (?, ?, ?, ?)";
|
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY) VALUES (?, ?, ?, ?)";
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
|
|||||||
|
|
||||||
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.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
@ -27,7 +28,7 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
|||||||
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -45,7 +46,7 @@ public class ProfileDAOImpl implements ProfileDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet generatedKeys = null;
|
ResultSet generatedKeys = null;
|
||||||
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
|
int tenantId = PolicyManagerUtil.getTenantId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -91,7 +92,7 @@ public class ProfileDAOImpl implements ProfileDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet generatedKeys = null;
|
ResultSet generatedKeys = null;
|
||||||
int tenantId = MultitenantConstants.SUPER_TENANT_ID;
|
int tenantId = PolicyManagerUtil.getTenantId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
|
|||||||
@ -57,6 +57,11 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
return policyManager.updatePolicy(policy);
|
return policyManager.updatePolicy(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||||
|
return policyManager.deletePolicy(policy);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException {
|
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException {
|
||||||
return policyManager.addPolicyToDevice(deviceIdentifierList, policy);
|
return policyManager.addPolicyToDevice(deviceIdentifierList, policy);
|
||||||
@ -94,17 +99,17 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPolicyAvailableForDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
public boolean isPolicyAvailableForDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
return false;
|
return policyManager.checkPolicyAvailable(deviceIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
public boolean isPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
return false;
|
return policyManager.setPolicyApplied(deviceIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException {
|
public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException {
|
||||||
|
policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy.getId(), policy.getProfile().getProfileFeaturesList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -119,8 +124,14 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteProfile(int profileId) throws PolicyManagementException {
|
public boolean deleteProfile(Profile profile) throws PolicyManagementException {
|
||||||
return false;
|
try {
|
||||||
|
return profileManager.deleteProfile(profile);
|
||||||
|
} catch (ProfileManagementException e) {
|
||||||
|
String msg = "Error occurred while deleting the profile.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -59,7 +59,6 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
|||||||
PIPDevice pipDevice = new PIPDevice();
|
PIPDevice pipDevice = new PIPDevice();
|
||||||
org.wso2.carbon.device.mgt.common.Device device;
|
org.wso2.carbon.device.mgt.common.Device device;
|
||||||
|
|
||||||
// TODO : Find
|
|
||||||
DeviceType deviceType = new DeviceType();
|
DeviceType deviceType = new DeviceType();
|
||||||
deviceType.setName(deviceIdentifier.getType());
|
deviceType.setName(deviceIdentifier.getType());
|
||||||
|
|
||||||
|
|||||||
@ -40,12 +40,6 @@ 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.policy.information.point.default"
|
|
||||||
* interface="org.wso2.carbon.policy.mgt.common.PolicyInformationPoint"
|
|
||||||
* cardinality="1..1"
|
|
||||||
* policy="dynamic"
|
|
||||||
* bind="setPIPService"
|
|
||||||
* unbind="unsetPIPService"
|
|
||||||
* @scr.reference name="org.wso2.carbon.devicemgt.simple.policy.evaluation.manager"
|
* @scr.reference name="org.wso2.carbon.devicemgt.simple.policy.evaluation.manager"
|
||||||
* interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint"
|
* interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint"
|
||||||
* cardinality="1..1"
|
* cardinality="1..1"
|
||||||
@ -108,7 +102,7 @@ public class PolicyManagementServiceComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setPIPService(PolicyInformationPoint pipService) {
|
/* protected void setPIPService(PolicyInformationPoint pipService) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Setting Policy Information Service");
|
log.debug("Setting Policy Information Service");
|
||||||
}
|
}
|
||||||
@ -120,7 +114,7 @@ public class PolicyManagementServiceComponent {
|
|||||||
log.debug("Unsetting Policy Information Service");
|
log.debug("Unsetting Policy Information Service");
|
||||||
}
|
}
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyInformationPoint(null);
|
PolicyManagementDataHolder.getInstance().setPolicyInformationPoint(null);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
protected void setPEPService(PolicyEvaluationPoint pepService) {
|
protected void setPEPService(PolicyEvaluationPoint pepService) {
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|||||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -33,7 +34,8 @@ public interface PolicyManager {
|
|||||||
|
|
||||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException;
|
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
||||||
|
PolicyManagementException;
|
||||||
|
|
||||||
Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException;
|
Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
@ -54,4 +56,11 @@ public interface PolicyManager {
|
|||||||
List<Policy> getPoliciesOfUser(String username) throws PolicyManagementException;
|
List<Policy> getPoliciesOfUser(String username) throws PolicyManagementException;
|
||||||
|
|
||||||
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
|
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
|
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
|
||||||
|
PolicyManagementException;
|
||||||
|
|
||||||
|
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||||
|
|
||||||
|
boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
|
|
||||||
@ -565,4 +566,75 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
}
|
}
|
||||||
return deviceList;
|
return deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
|
||||||
|
PolicyManagementException {
|
||||||
|
int deviceId = -1;
|
||||||
|
try {
|
||||||
|
Device device = deviceDAO.getDevice(deviceIdentifier);
|
||||||
|
deviceId = device.getId();
|
||||||
|
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
||||||
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
if (exist) {
|
||||||
|
policyDAO.updateEffectivePolicyToDevice(deviceId, policyId, profileFeatures);
|
||||||
|
} else {
|
||||||
|
policyDAO.addEffectivePolicyToDevice(deviceId, policyId, profileFeatures);
|
||||||
|
}
|
||||||
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
try {
|
||||||
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
|
} catch (PolicyManagerDAOException e1) {
|
||||||
|
log.warn("Error occurred while roll backing the transaction.");
|
||||||
|
}
|
||||||
|
String msg = "Error occurred while adding the evaluated policy to device (" +
|
||||||
|
deviceId + " - " + policyId + ")";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
|
|
||||||
|
boolean exist;
|
||||||
|
try {
|
||||||
|
Device device = deviceDAO.getDevice(deviceIdentifier);
|
||||||
|
exist = policyDAO.checkPolicyAvailable(device.getId());
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
String msg = "Error occurred while checking whether device has a policy to apply.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Device device = deviceDAO.getDevice(deviceIdentifier);
|
||||||
|
policyDAO.setPolicyApplied(device.getId());
|
||||||
|
return true;
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
String msg = "Error occurred while setting the policy has applied to device (" +
|
||||||
|
deviceIdentifier.getId() + ")";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,13 +64,19 @@ public class PolicyManagementService implements PolicyManagerService {
|
|||||||
return policyManagerService.updatePolicy(policy);
|
return policyManagerService.updatePolicy(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||||
|
return policyManagerService.deletePolicy(policy);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
return policyManagerService.getEffectivePolicy(deviceIdentifier);
|
return policyManagerService.getEffectivePolicy(deviceIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException {
|
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws
|
||||||
|
FeatureManagementException {
|
||||||
return policyManagerService.getEffectiveFeatures(deviceIdentifier);
|
return policyManagerService.getEffectiveFeatures(deviceIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,4 +99,9 @@ public class PolicyManagementService implements PolicyManagerService {
|
|||||||
public PolicyInformationPoint getPIP() throws PolicyManagementException {
|
public PolicyInformationPoint getPIP() throws PolicyManagementException {
|
||||||
return policyManagerService.getPIP();
|
return policyManagerService.getPIP();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
|
||||||
|
return policyManagerService.getPEP();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,12 @@ package org.wso2.carbon.policy.mgt.core.util;
|
|||||||
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.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
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.config.datasource.JNDILookupDefinition;
|
import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
@ -82,4 +84,23 @@ public class PolicyManagerUtil {
|
|||||||
}
|
}
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getTenantId() {
|
||||||
|
|
||||||
|
//TODO: Get the tenant id proper way. This is has to be fix for test to run.
|
||||||
|
|
||||||
|
int tenantId;
|
||||||
|
tenantId = MultitenantConstants.SUPER_TENANT_ID;
|
||||||
|
/* try {
|
||||||
|
if (PrivilegedCarbonContext.getThreadLocalCarbonContext() != null) {
|
||||||
|
tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
} else {
|
||||||
|
tenantId = MultitenantConstants.SUPER_TENANT_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,7 @@ package org.wso2.carbon.simple.policy.decision.point;
|
|||||||
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.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.policy.mgt.common.PIPDevice;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder;
|
import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder;
|
||||||
|
|
||||||
@ -43,20 +40,31 @@ public class SimpleEvaluationImpl implements SimpleEvaluation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
|
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
|
||||||
|
Policy policy = new Policy();
|
||||||
|
PolicyAdministratorPoint policyAdministratorPoint;
|
||||||
|
PolicyInformationPoint policyInformationPoint;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (policyManagerService == null && policyList == null) {
|
if (policyManagerService != null && policyList == null) {
|
||||||
PIPDevice pipDevice = policyManagerService.getPIP().getDeviceData(deviceIdentifier);
|
|
||||||
policyList = policyManagerService.getPIP().getRelatedPolicies(pipDevice);
|
policyInformationPoint = policyManagerService.getPIP();
|
||||||
}
|
PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier);
|
||||||
|
policyList = policyInformationPoint.getRelatedPolicies(pipDevice);
|
||||||
|
|
||||||
sortPolicy();
|
sortPolicy();
|
||||||
|
policy = policyList.get(0);
|
||||||
|
|
||||||
|
policyAdministratorPoint = policyManagerService.getPAP();
|
||||||
|
policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String msg = "Error occurred when retrieving the policy related data from policy management service.";
|
String msg = "Error occurred when retrieving the policy related data from policy management service.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new PolicyEvaluationException(msg, e);
|
throw new PolicyEvaluationException(msg, e);
|
||||||
}
|
}
|
||||||
|
return policy;
|
||||||
return policyList.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user