mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Improve MDM policy functionality
This commit is contained in:
parent
94bdff30ed
commit
d25779774b
@ -334,7 +334,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException e) {
|
||||||
String msg = "Error occurred while creating a costom application";
|
String msg = "Error occurred while creating a custom application";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
} catch (RequestValidatingException e) {
|
} catch (RequestValidatingException e) {
|
||||||
@ -716,7 +716,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
.changeLifecycleState(applicationUuid, lifecycleChanger);
|
.changeLifecycleState(applicationUuid, lifecycleChanger);
|
||||||
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
|
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
|
||||||
} catch (BadRequestException e) {
|
} catch (BadRequestException e) {
|
||||||
String msg = "Request payload contains invalid data, hence veryfy the request payload.";
|
String msg = "Request payload contains invalid data, hence verify the request payload.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
} catch (ForbiddenException e) {
|
} catch (ForbiddenException e) {
|
||||||
@ -1005,10 +1005,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (attachmentList != null && !attachmentList.isEmpty()) {
|
if (attachmentList != null && !attachmentList.isEmpty()) {
|
||||||
Map<String, InputStream> scrrenshotData = new TreeMap<>();
|
Map<String, InputStream> screenshotData = new TreeMap<>();
|
||||||
for (Attachment sc : attachmentList) {
|
for (Attachment sc : attachmentList) {
|
||||||
dataHandler = sc.getDataHandler();
|
dataHandler = sc.getDataHandler();
|
||||||
String screenshotrFileName = dataHandler.getName();
|
String screenshotFileName = dataHandler.getName();
|
||||||
InputStream screenshotStream = dataHandler.getInputStream();
|
InputStream screenshotStream = dataHandler.getInputStream();
|
||||||
if (screenshotStream == null) {
|
if (screenshotStream == null) {
|
||||||
String msg =
|
String msg =
|
||||||
@ -1017,16 +1017,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
if (screenshotrFileName == null) {
|
if (screenshotFileName == null) {
|
||||||
String msg =
|
String msg =
|
||||||
"Screenshot file name retrieving is failed for one screenshot. Hence can't proceed. "
|
"Screenshot file name retrieving is failed for one screenshot. Hence can't proceed. "
|
||||||
+ "Please verify the screenshots.";
|
+ "Please verify the screenshots.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
scrrenshotData.put(screenshotrFileName, screenshotStream);
|
screenshotData.put(screenshotFileName, screenshotStream);
|
||||||
}
|
}
|
||||||
applicationArtifact.setScreenshots(scrrenshotData);
|
applicationArtifact.setScreenshots(screenshotData);
|
||||||
}
|
}
|
||||||
return applicationArtifact;
|
return applicationArtifact;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@ -136,6 +136,14 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GEt {@link Policy} from {@link PolicyWrapper}
|
||||||
|
*
|
||||||
|
* @param policyWrapper {@link PolicyWrapper}
|
||||||
|
* @return {@link Policy}
|
||||||
|
* @throws DeviceManagementException if error occurred while creating {@link Policy} object from
|
||||||
|
* {@link PolicyWrapper}
|
||||||
|
*/
|
||||||
private Policy getPolicyFromWrapper(@Valid PolicyWrapper policyWrapper) throws DeviceManagementException {
|
private Policy getPolicyFromWrapper(@Valid PolicyWrapper policyWrapper) throws DeviceManagementException {
|
||||||
Policy policy = new Policy();
|
Policy policy = new Policy();
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
@ -151,7 +159,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
|||||||
policy.setPolicyPayloadVersion(policyWrapper.getPayloadVersion());
|
policy.setPolicyPayloadVersion(policyWrapper.getPayloadVersion());
|
||||||
policy.setCorrectiveActions(policyWrapper.getCorrectiveActions());
|
policy.setCorrectiveActions(policyWrapper.getCorrectiveActions());
|
||||||
//TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here.
|
//TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here.
|
||||||
List<Device> devices = new ArrayList<Device>();
|
List<Device> devices = new ArrayList<>();
|
||||||
List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers();
|
List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers();
|
||||||
if (deviceIdentifiers != null) {
|
if (deviceIdentifiers != null) {
|
||||||
for (DeviceIdentifier id : deviceIdentifiers) {
|
for (DeviceIdentifier id : deviceIdentifiers) {
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
package org.wso2.carbon.device.mgt.common.policy.mgt;
|
package org.wso2.carbon.device.mgt.common.policy.mgt;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||||
|
|
||||||
|
|||||||
@ -150,7 +150,6 @@ import java.io.IOException;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
|||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,10 +34,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class DefaultPolicyMonitoringManager implements PolicyMonitoringManager {
|
public class DefaultPolicyMonitoringManager implements PolicyMonitoringManager {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DefaultPolicyMonitoringManager.class);
|
private static final Log log = LogFactory.getLog(DefaultPolicyMonitoringManager.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
|
public NonComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response) {
|
||||||
throws PolicyComplianceException {
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
|
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -188,14 +188,6 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
|||||||
stmt.setInt(4, tenantId);
|
stmt.setInt(4, tenantId);
|
||||||
stmt.setInt(5, enrolmentId);
|
stmt.setInt(5, enrolmentId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
// generatedKeys = stmt.getGeneratedKeys();
|
|
||||||
// if (generatedKeys.next()) {
|
|
||||||
// return generatedKeys.getInt(1);
|
|
||||||
// } else {
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new MonitoringDAOException("Error occurred while deleting the none compliance to the database.", e);
|
throw new MonitoringDAOException("Error occurred while deleting the none compliance to the database.", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -442,7 +434,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>();
|
List<ComplianceFeature> complianceFeatures = new ArrayList<>();
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -488,8 +480,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws MonitoringDAOException {
|
private Connection getConnection() {
|
||||||
return PolicyManagementDAOFactory.getConnection();
|
return PolicyManagementDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,41 +75,13 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
return persistPolicy(policy);
|
return persistPolicy(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public Policy addPolicyToDeviceType(String deviceType, Policy policy) throws PolicyManagerDAOException {
|
|
||||||
// Connection conn;
|
|
||||||
// PreparedStatement stmt = null;
|
|
||||||
// try {
|
|
||||||
// conn = this.getConnection();
|
|
||||||
// String query = "INSERT INTO DM_DEVICE_TYPE_POLICY (DEVICE_TYPE_ID, POLICY_ID) VALUES (?, ?)";
|
|
||||||
// stmt = conn.prepareStatement(query);
|
|
||||||
// stmt.setInt(1, getDeviceTypeId(deviceType));
|
|
||||||
// stmt.setInt(2, policy.getId());
|
|
||||||
// stmt.executeQuery();
|
|
||||||
// } catch (SQLException e) {
|
|
||||||
// throw new PolicyManagerDAOException("Error occurred while adding the device type policy to database.", e);
|
|
||||||
// } finally {
|
|
||||||
// PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
||||||
// }
|
|
||||||
// return policy;
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy addPolicyToRole(List<String> rolesToAdd, Policy policy) throws PolicyManagerDAOException {
|
public Policy addPolicyToRole(List<String> rolesToAdd, Policy policy) throws PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement insertStmt = null;
|
PreparedStatement insertStmt = null;
|
||||||
// PreparedStatement deleteStmt = null;
|
|
||||||
// final List<String> currentRoles = this.getPolicy(policy.getId()).getRoles();
|
|
||||||
//
|
|
||||||
// SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
|
|
||||||
//
|
|
||||||
// transformer.transform(currentRoles, rolesToAdd);
|
|
||||||
// rolesToAdd = transformer.getObjectsToAdd();
|
|
||||||
// List<String> rolesToDelete = transformer.getObjectsToRemove();
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
if (rolesToAdd.size() > 0) {
|
if (!rolesToAdd.isEmpty()) {
|
||||||
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
|
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
|
||||||
insertStmt = conn.prepareStatement(query);
|
insertStmt = conn.prepareStatement(query);
|
||||||
for (String role : rolesToAdd) {
|
for (String role : rolesToAdd) {
|
||||||
@ -119,16 +91,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
insertStmt.executeBatch();
|
insertStmt.executeBatch();
|
||||||
}
|
}
|
||||||
// if (rolesToDelete.size() > 0){
|
|
||||||
// String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?";
|
|
||||||
// deleteStmt = conn.prepareStatement(deleteQuery);
|
|
||||||
// for (String role : rolesToDelete) {
|
|
||||||
// deleteStmt.setString(1, role);
|
|
||||||
// deleteStmt.setInt(2, policy.getId());
|
|
||||||
// deleteStmt.addBatch();
|
|
||||||
// }
|
|
||||||
// deleteStmt.executeBatch();
|
|
||||||
// }
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagerDAOException("Error occurred while adding the role name with policy to database", e);
|
throw new PolicyManagerDAOException("Error occurred while adding the role name with policy to database", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -146,14 +108,14 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
|
|
||||||
final List<String> currentRoles = previousPolicy.getRoles();
|
final List<String> currentRoles = previousPolicy.getRoles();
|
||||||
|
|
||||||
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
|
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
||||||
|
|
||||||
transformer.transform(currentRoles, rolesToAdd);
|
transformer.transform(currentRoles, rolesToAdd);
|
||||||
rolesToAdd = transformer.getObjectsToAdd();
|
rolesToAdd = transformer.getObjectsToAdd();
|
||||||
List<String> rolesToDelete = transformer.getObjectsToRemove();
|
List<String> rolesToDelete = transformer.getObjectsToRemove();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
if (rolesToAdd.size() > 0) {
|
if (!rolesToAdd.isEmpty()) {
|
||||||
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
|
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
|
||||||
insertStmt = conn.prepareStatement(query);
|
insertStmt = conn.prepareStatement(query);
|
||||||
for (String role : rolesToAdd) {
|
for (String role : rolesToAdd) {
|
||||||
@ -163,7 +125,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
insertStmt.executeBatch();
|
insertStmt.executeBatch();
|
||||||
}
|
}
|
||||||
if (rolesToDelete.size() > 0) {
|
if (!rolesToDelete.isEmpty()) {
|
||||||
String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?";
|
String deleteQuery = "DELETE FROM DM_ROLE_POLICY WHERE ROLE_NAME=? AND POLICY_ID=?";
|
||||||
deleteStmt = conn.prepareStatement(deleteQuery);
|
deleteStmt = conn.prepareStatement(deleteQuery);
|
||||||
for (String role : rolesToDelete) {
|
for (String role : rolesToDelete) {
|
||||||
@ -186,17 +148,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
public Policy addPolicyToUser(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException {
|
public Policy addPolicyToUser(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement insertStmt = null;
|
PreparedStatement insertStmt = null;
|
||||||
// PreparedStatement deleteStmt = null;
|
|
||||||
// final List<String> currentUsers = this.getPolicy(policy.getId()).getUsers();
|
|
||||||
//
|
|
||||||
// SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
|
|
||||||
//
|
|
||||||
// transformer.transform(currentUsers, usersToAdd);
|
|
||||||
// usersToAdd = transformer.getObjectsToAdd();
|
|
||||||
// List<String> usersToDelete = transformer.getObjectsToRemove();
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
if (usersToAdd.size() > 0) {
|
if (!usersToAdd.isEmpty()) {
|
||||||
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
|
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
|
||||||
insertStmt = conn.prepareStatement(query);
|
insertStmt = conn.prepareStatement(query);
|
||||||
for (String username : usersToAdd) {
|
for (String username : usersToAdd) {
|
||||||
@ -206,22 +160,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
insertStmt.executeBatch();
|
insertStmt.executeBatch();
|
||||||
}
|
}
|
||||||
// if (usersToDelete.size() > 0){
|
|
||||||
// String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?";
|
|
||||||
// deleteStmt = conn.prepareStatement(deleteQuery);
|
|
||||||
// for (String username : usersToDelete) {
|
|
||||||
// deleteStmt.setString(1, username);
|
|
||||||
// deleteStmt.setInt(2, policy.getId());
|
|
||||||
// deleteStmt.addBatch();
|
|
||||||
// }
|
|
||||||
// deleteStmt.executeBatch();
|
|
||||||
// }
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagerDAOException("Error occurred while adding the user name with policy to database", e);
|
throw new PolicyManagerDAOException("Error occurred while adding the user name with policy to database", e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOUtil.cleanupResources(insertStmt, null);
|
PolicyManagementDAOUtil.cleanupResources(insertStmt, null);
|
||||||
// PolicyManagementDAOUtil.cleanupResources(deleteStmt, null);
|
|
||||||
}
|
}
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
@ -234,14 +176,14 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
PreparedStatement deleteStmt = null;
|
PreparedStatement deleteStmt = null;
|
||||||
final List<String> currentUsers = policy.getUsers();
|
final List<String> currentUsers = policy.getUsers();
|
||||||
|
|
||||||
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<String>();
|
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
||||||
|
|
||||||
transformer.transform(currentUsers, usersToAdd);
|
transformer.transform(currentUsers, usersToAdd);
|
||||||
usersToAdd = transformer.getObjectsToAdd();
|
usersToAdd = transformer.getObjectsToAdd();
|
||||||
List<String> usersToDelete = transformer.getObjectsToRemove();
|
List<String> usersToDelete = transformer.getObjectsToRemove();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
if (usersToAdd.size() > 0) {
|
if (!usersToAdd.isEmpty()) {
|
||||||
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
|
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
|
||||||
insertStmt = conn.prepareStatement(query);
|
insertStmt = conn.prepareStatement(query);
|
||||||
for (String username : usersToAdd) {
|
for (String username : usersToAdd) {
|
||||||
@ -251,7 +193,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
insertStmt.executeBatch();
|
insertStmt.executeBatch();
|
||||||
}
|
}
|
||||||
if (usersToDelete.size() > 0) {
|
if (!usersToDelete.isEmpty()) {
|
||||||
String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?";
|
String deleteQuery = "DELETE FROM DM_USER_POLICY WHERE USERNAME=? AND POLICY_ID=?";
|
||||||
deleteStmt = conn.prepareStatement(deleteQuery);
|
deleteStmt = conn.prepareStatement(deleteQuery);
|
||||||
for (String username : usersToDelete) {
|
for (String username : usersToDelete) {
|
||||||
@ -328,7 +270,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID, IS_REACTIVE " +
|
String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID, IS_REACTIVE " +
|
||||||
"FROM DM_POLICY_CORRECTIVE_ACTION ";
|
"FROM DM_POLICY_CORRECTIVE_ACTION ";
|
||||||
try (PreparedStatement stmt = conn.prepareStatement(query)) {
|
try (PreparedStatement stmt = conn.prepareStatement(query)) {
|
||||||
List<CorrectiveAction> correctiveActions = new ArrayList<>();
|
|
||||||
return extractCorrectivePolicies(stmt);
|
return extractCorrectivePolicies(stmt);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -826,7 +767,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<Criterion> criteria = new ArrayList<Criterion>();
|
List<Criterion> criteria = new ArrayList<>();
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -912,8 +853,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
}
|
}
|
||||||
// stmt.executeUpdate();
|
|
||||||
|
|
||||||
} catch (SQLException | IOException e) {
|
} catch (SQLException | IOException e) {
|
||||||
throw new PolicyManagerDAOException("Error occurred while inserting the criterion properties " +
|
throw new PolicyManagerDAOException("Error occurred while inserting the criterion properties " +
|
||||||
"to database", e);
|
"to database", e);
|
||||||
@ -928,7 +867,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<PolicyCriterion> criteria = new ArrayList<PolicyCriterion>();
|
List<PolicyCriterion> criteria = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT DPC.ID, DPC.CRITERIA_ID, DPCP.PROP_KEY, DPCP.PROP_VALUE, DPCP.CONTENT FROM " +
|
String query = "SELECT DPC.ID, DPC.CRITERIA_ID, DPCP.PROP_KEY, DPCP.PROP_VALUE, DPCP.CONTENT FROM " +
|
||||||
@ -1152,7 +1091,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<Policy> policies = new ArrayList<Policy>();
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1180,7 +1118,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<Integer> deviceIdList = new ArrayList<Integer>();
|
List<Integer> deviceIdList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?";
|
String query = "SELECT * FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?";
|
||||||
@ -1204,7 +1142,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<String> roleNames = new ArrayList<String>();
|
List<String> roleNames = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_ROLE_POLICY WHERE POLICY_ID = ?";
|
String query = "SELECT * FROM DM_ROLE_POLICY WHERE POLICY_ID = ?";
|
||||||
@ -1229,7 +1167,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
List<String> users = new ArrayList<String>();
|
List<String> users = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_USER_POLICY WHERE POLICY_ID = ?";
|
String query = "SELECT * FROM DM_USER_POLICY WHERE POLICY_ID = ?";
|
||||||
@ -1387,7 +1325,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<Integer> policyIds = new ArrayList<Integer>();
|
List<Integer> policyIds = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ? ";
|
String query = "SELECT * FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ? ";
|
||||||
@ -1411,7 +1349,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<Integer> policyIds = new ArrayList<Integer>();
|
List<Integer> policyIds = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_ROLE_POLICY WHERE ROLE_NAME = ? ";
|
String query = "SELECT * FROM DM_ROLE_POLICY WHERE ROLE_NAME = ? ";
|
||||||
@ -1435,7 +1373,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
List<Integer> policyIds = new ArrayList<Integer>();
|
List<Integer> policyIds = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_USER_POLICY WHERE USERNAME = ? ";
|
String query = "SELECT * FROM DM_USER_POLICY WHERE USERNAME = ? ";
|
||||||
@ -1563,16 +1501,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
|
|
||||||
// String userPolicy = "DELETE FROM DM_USER_POLICY WHERE POLICY_ID = ?";
|
|
||||||
// stmt = conn.prepareStatement(userPolicy);
|
|
||||||
// stmt.setInt(1, policyId);
|
|
||||||
// stmt.executeUpdate();
|
|
||||||
//
|
|
||||||
// String rolePolicy = "DELETE FROM DM_ROLE_POLICY WHERE POLICY_ID = ?";
|
|
||||||
// stmt = conn.prepareStatement(rolePolicy);
|
|
||||||
// stmt.setInt(1, policyId);
|
|
||||||
// stmt.executeUpdate();
|
|
||||||
|
|
||||||
String devicePolicy = "DELETE FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?";
|
String devicePolicy = "DELETE FROM DM_DEVICE_POLICY WHERE POLICY_ID = ?";
|
||||||
stmt = conn.prepareStatement(devicePolicy);
|
stmt = conn.prepareStatement(devicePolicy);
|
||||||
stmt.setInt(1, policyId);
|
stmt.setInt(1, policyId);
|
||||||
@ -1601,7 +1529,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws PolicyManagerDAOException {
|
private Connection getConnection() {
|
||||||
return PolicyManagementDAOFactory.getConnection();
|
return PolicyManagementDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1821,15 +1749,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// if (policy != null && log.isDebugEnabled()) {
|
|
||||||
// log.debug("Applied policy logging details started ------------------");
|
|
||||||
// log.debug("Applied policy name " + policy.getPolicyName() + "for the device id " + deviceId);
|
|
||||||
// log.debug(policy.getCompliance());
|
|
||||||
// log.debug(policy.getId());
|
|
||||||
// log.debug(policy.getPriorityId());
|
|
||||||
// log.debug("Applied policy logging details finished....");
|
|
||||||
// }
|
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,8 @@ import java.util.Map;
|
|||||||
public class DelegationTask implements Task {
|
public class DelegationTask implements Task {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DelegationTask.class);
|
private static final Log log = LogFactory.getLog(DelegationTask.class);
|
||||||
private PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration();
|
private PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance()
|
||||||
|
.getDeviceManagementConfig().getPolicyConfiguration();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProperties(Map<String, String> map) {
|
public void setProperties(Map<String, String> map) {
|
||||||
@ -73,21 +74,17 @@ public class DelegationTask implements Task {
|
|||||||
List<Device> toBeNotified;
|
List<Device> toBeNotified;
|
||||||
for (String deviceType : deviceTypes) {
|
for (String deviceType : deviceTypes) {
|
||||||
try {
|
try {
|
||||||
devices = new ArrayList<>();
|
|
||||||
toBeNotified = new ArrayList<>();
|
toBeNotified = new ArrayList<>();
|
||||||
devices.addAll(service.getAllDevices(deviceType, false));
|
devices = new ArrayList<>(service.getAllDevices(deviceType, false));
|
||||||
//HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
|
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
// if (deviceIdPolicy.containsKey(device.getId())) {
|
|
||||||
if (device != null && device.getEnrolmentInfo() != null
|
if (device != null && device.getEnrolmentInfo() != null
|
||||||
&& device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) {
|
&& device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) {
|
||||||
toBeNotified.add(device);
|
toBeNotified.add(device);
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
if (!toBeNotified.isEmpty()) {
|
if (!toBeNotified.isEmpty()) {
|
||||||
PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl
|
PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(
|
||||||
(toBeNotified, updatedPolicyDeviceList.getUpdatedPolicyIds());
|
toBeNotified, updatedPolicyDeviceList.getUpdatedPolicyIds());
|
||||||
enforcementDelegator.delegate();
|
enforcementDelegator.delegate();
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
|
|||||||
@ -122,7 +122,6 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return policy;
|
return policy;
|
||||||
//return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier);
|
|
||||||
} catch (PolicyEvaluationException | PolicyManagementException e) {
|
} catch (PolicyEvaluationException | PolicyManagementException e) {
|
||||||
String msg = "Error occurred while retrieving the effective policy for devices.";
|
String msg = "Error occurred while retrieving the effective policy for devices.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
@ -135,7 +134,7 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
|
|||||||
PolicyDelegationException {
|
PolicyDelegationException {
|
||||||
try {
|
try {
|
||||||
String type = null;
|
String type = null;
|
||||||
if (deviceIdentifiers.size() > 0) {
|
if (!deviceIdentifiers.isEmpty()) {
|
||||||
type = deviceIdentifiers.get(0).getType();
|
type = deviceIdentifiers.get(0).getType();
|
||||||
}
|
}
|
||||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
|
||||||
@ -161,7 +160,7 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
|
|||||||
public void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyDelegationException {
|
public void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyDelegationException {
|
||||||
try {
|
try {
|
||||||
String type = null;
|
String type = null;
|
||||||
if (deviceIdentifiers.size() > 0) {
|
if (!deviceIdentifiers.isEmpty()) {
|
||||||
type = deviceIdentifiers.get(0).getType();
|
type = deviceIdentifiers.get(0).getType();
|
||||||
}
|
}
|
||||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
|
||||||
|
|||||||
@ -34,10 +34,8 @@ import org.wso2.carbon.policy.mgt.common.*;
|
|||||||
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
|
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||||
@ -53,28 +51,18 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
|
|
||||||
private PolicyManager policyManager;
|
private PolicyManager policyManager;
|
||||||
private ProfileManager profileManager;
|
private ProfileManager profileManager;
|
||||||
private FeatureManager featureManager;
|
|
||||||
private PolicyCacheManager cacheManager;
|
|
||||||
private PolicyConfiguration policyConfiguration;
|
private PolicyConfiguration policyConfiguration;
|
||||||
// private PolicyEnforcementDelegator delegator;
|
|
||||||
|
|
||||||
public PolicyAdministratorPointImpl() {
|
public PolicyAdministratorPointImpl() {
|
||||||
this.policyManager = new PolicyManagerImpl();
|
this.policyManager = new PolicyManagerImpl();
|
||||||
this.profileManager = new ProfileManagerImpl();
|
this.profileManager = new ProfileManagerImpl();
|
||||||
this.featureManager = new FeatureManagerImpl();
|
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig()
|
||||||
this.cacheManager = PolicyCacheManagerImpl.getInstance();
|
.getPolicyConfiguration();
|
||||||
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration();
|
|
||||||
// this.delegator = new PolicyEnforcementDelegatorImpl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy addPolicy(Policy policy) throws PolicyManagementException {
|
public Policy addPolicy(Policy policy) throws PolicyManagementException {
|
||||||
Policy resultantPolicy = policyManager.addPolicy(policy);
|
Policy resultantPolicy = policyManager.addPolicy(policy);
|
||||||
// try {
|
|
||||||
// delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
|
|
||||||
// } catch (PolicyDelegationException e) {
|
|
||||||
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
|
|
||||||
// }
|
|
||||||
if (policyConfiguration.getCacheEnable()) {
|
if (policyConfiguration.getCacheEnable()) {
|
||||||
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
}
|
}
|
||||||
@ -84,11 +72,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
@Override
|
@Override
|
||||||
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
||||||
Policy resultantPolicy = policyManager.updatePolicy(policy);
|
Policy resultantPolicy = policyManager.updatePolicy(policy);
|
||||||
// try {
|
|
||||||
// delegator.delegate(resultantPolicy, resultantPolicy.getDevices());
|
|
||||||
// } catch (PolicyDelegationException e) {
|
|
||||||
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
|
|
||||||
// }
|
|
||||||
if (policyConfiguration.getCacheEnable()) {
|
if (policyConfiguration.getCacheEnable()) {
|
||||||
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
}
|
}
|
||||||
@ -190,7 +173,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (TaskException e) {
|
} catch (TaskException e) {
|
||||||
String msg = "Error occurred while creating the policy delegation task for tenant " +
|
String msg = "Error occurred while creating the policy delegation task for tenant " +
|
||||||
PrivilegedCarbonContext.
|
PrivilegedCarbonContext.
|
||||||
@ -198,42 +180,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new PolicyManagementException(msg, e);
|
throw new PolicyManagementException(msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// List<DeviceType> deviceTypes = policyManager.applyChangesMadeToPolicies();
|
|
||||||
//
|
|
||||||
// if(log.isDebugEnabled()) {
|
|
||||||
// log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size() );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!deviceTypes.isEmpty()) {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance()
|
|
||||||
// .getDeviceManagementService();
|
|
||||||
// List<Device> devices = new ArrayList<>();
|
|
||||||
// for (DeviceType deviceType : deviceTypes) {
|
|
||||||
// try {
|
|
||||||
// devices.addAll(service.getAllDevices(deviceType.getName()));
|
|
||||||
// } catch (DeviceManagementException e) {
|
|
||||||
// throw new PolicyManagementException("Error occurred while taking the devices", e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
|
|
||||||
// List<Device> toBeNotified = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// for (Device device : devices) {
|
|
||||||
// if (deviceIdPolicy.containsKey(device.getId())) {
|
|
||||||
// toBeNotified.add(device);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (!toBeNotified.isEmpty()) {
|
|
||||||
//
|
|
||||||
// // ExecutorService executorService = getExecutor();
|
|
||||||
// // PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
|
|
||||||
//// Thread thread = new Thread(new PolicyEnforcementDelegatorImpl(toBeNotified));
|
|
||||||
//// thread.start();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class PolicyFilterImpl implements PolicyFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Policy> temp = new ArrayList<Policy>();
|
List<Policy> temp = new ArrayList<>();
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
if (policy.isActive()) {
|
if (policy.isActive()) {
|
||||||
temp.add(policy);
|
temp.add(policy);
|
||||||
|
|||||||
@ -18,8 +18,6 @@
|
|||||||
package org.wso2.carbon.policy.mgt.core.mgt.bean;
|
package org.wso2.carbon.policy.mgt.core.mgt.bean;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,6 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
|||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceData;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceData;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||||
|
|||||||
@ -241,9 +241,9 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policy.getProfile().setUpdatedDate(currentTimestamp);
|
policy.getProfile().setUpdatedDate(currentTimestamp);
|
||||||
policy.setPriorityId(previousPolicy.getPriorityId());
|
policy.setPriorityId(previousPolicy.getPriorityId());
|
||||||
policy.setPolicyPayloadVersion(previousPolicy.getPolicyPayloadVersion());
|
policy.setPolicyPayloadVersion(previousPolicy.getPolicyPayloadVersion());
|
||||||
Policy updatedPolicy = policyDAO.updatePolicy(policy);
|
|
||||||
profileDAO.updateProfile(policy.getProfile());
|
|
||||||
|
|
||||||
|
policyDAO.updatePolicy(policy);
|
||||||
|
profileDAO.updateProfile(policy.getProfile());
|
||||||
featureDAO.updateProfileFeatures(existingFeaturesList, profileId);
|
featureDAO.updateProfileFeatures(existingFeaturesList, profileId);
|
||||||
if (!newFeaturesList.isEmpty()) {
|
if (!newFeaturesList.isEmpty()) {
|
||||||
featureDAO.addProfileFeatures(newFeaturesList, profileId);
|
featureDAO.addProfileFeatures(newFeaturesList, profileId);
|
||||||
@ -646,8 +646,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inactivatePolicy(int policyId) throws PolicyManagementException {
|
public void inactivatePolicy(int policyId) throws PolicyManagementException {
|
||||||
|
Policy policy = this.getPolicy(policyId);
|
||||||
try {
|
try {
|
||||||
Policy policy = this.getPolicy(policyId);
|
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
policyDAO.inactivatePolicy(policyId);
|
policyDAO.inactivatePolicy(policyId);
|
||||||
policyDAO.recordUpdatedPolicy(policy);
|
policyDAO.recordUpdatedPolicy(policy);
|
||||||
|
|||||||
@ -22,8 +22,6 @@ 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.policy.mgt.Profile;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
||||||
@ -41,17 +39,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ProfileManagerImpl implements ProfileManager {
|
public class ProfileManagerImpl implements ProfileManager {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(ProfileManagerImpl.class);
|
private static final Log log = LogFactory.getLog(ProfileManagerImpl.class);
|
||||||
private ProfileDAO profileDAO;
|
private ProfileDAO profileDAO;
|
||||||
private FeatureDAO featureDAO;
|
private FeatureDAO featureDAO;
|
||||||
// private DeviceDAO deviceDAO;
|
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
|
||||||
|
|
||||||
public ProfileManagerImpl() {
|
public ProfileManagerImpl() {
|
||||||
profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
||||||
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
||||||
// deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
||||||
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,19 +62,21 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
} catch (ProfileManagerDAOException e) {
|
} catch (ProfileManagerDAOException e) {
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
throw new ProfileManagementException("Error occurred while adding the profile (" +
|
String msg = "Error occurred while adding the profile (" + profile.getProfileName() + ")";
|
||||||
profile.getProfileName() + ")", e);
|
log.error(msg, e);
|
||||||
|
throw new ProfileManagementException(msg, e);
|
||||||
} catch (FeatureManagerDAOException e) {
|
} catch (FeatureManagerDAOException e) {
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
throw new ProfileManagementException("Error occurred while adding the profile features (" +
|
String msg = "Error occurred while adding the profile features (" + profile.getProfileName() + ")";
|
||||||
profile.getProfileName() + ")", e);
|
log.error(msg, e);
|
||||||
|
throw new ProfileManagementException(msg, e);
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
throw new ProfileManagementException("Error occurred while adding the profile (" +
|
String msg = "Error occurred while adding the profile (" + profile.getProfileName() + ") to the database";
|
||||||
profile.getProfileName() + ") to the database", e);
|
log.error(msg, e);
|
||||||
|
throw new ProfileManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +111,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteProfile(Profile profile) throws ProfileManagementException {
|
public boolean deleteProfile(Profile profile) throws ProfileManagementException {
|
||||||
boolean bool = true;
|
boolean bool;
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
featureDAO.deleteFeaturesOfProfile(profile);
|
featureDAO.deleteFeaturesOfProfile(profile);
|
||||||
@ -173,7 +169,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
|
|
||||||
for (Profile profile : profileList) {
|
for (Profile profile : profileList) {
|
||||||
|
|
||||||
List<ProfileFeature> list = new ArrayList<ProfileFeature>();
|
List<ProfileFeature> list = new ArrayList<>();
|
||||||
for (ProfileFeature profileFeature : featureList) {
|
for (ProfileFeature profileFeature : featureList) {
|
||||||
if (profile.getProfileId() == profileFeature.getProfileId()) {
|
if (profile.getProfileId() == profileFeature.getProfileId()) {
|
||||||
list.add(profileFeature);
|
list.add(profileFeature);
|
||||||
@ -204,7 +200,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
featureList = featureDAO.getAllProfileFeatures();
|
featureList = featureDAO.getAllProfileFeatures();
|
||||||
|
|
||||||
for (Profile profile : profileList) {
|
for (Profile profile : profileList) {
|
||||||
List<ProfileFeature> profileFeatureList = new ArrayList<ProfileFeature>();
|
List<ProfileFeature> profileFeatureList = new ArrayList<>();
|
||||||
for (ProfileFeature profileFeature : featureList) {
|
for (ProfileFeature profileFeature : featureList) {
|
||||||
if (profile.getProfileId() == profileFeature.getProfileId()) {
|
if (profile.getProfileId() == profileFeature.getProfileId()) {
|
||||||
profileFeatureList.add(profileFeature);
|
profileFeatureList.add(profileFeature);
|
||||||
@ -224,5 +220,4 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
}
|
}
|
||||||
return profileList;
|
return profileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class TaskScheduleServiceImpl implements TaskScheduleService {
|
public class TaskScheduleServiceImpl implements TaskScheduleService {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
|
private static final Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
|
||||||
private PolicyConfiguration policyConfiguration;
|
private PolicyConfiguration policyConfiguration;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user