|
|
@ -51,10 +51,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
public Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "INSERT INTO DM_DEVICE_TYPE_POLICY (DEVICE_TYPE_ID, POLICY_ID) VALUES (?, ?)";
|
|
|
|
String query = "INSERT INTO DM_DEVICE_TYPE_POLICY (DEVICE_TYPE_ID, POLICY_ID) VALUES (?, ?)";
|
|
|
@ -62,11 +60,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setInt(1, getDeviceTypeId(deviceType));
|
|
|
|
stmt.setInt(1, getDeviceTypeId(deviceType));
|
|
|
|
stmt.setInt(2, policy.getId());
|
|
|
|
stmt.setInt(2, policy.getId());
|
|
|
|
stmt.executeQuery();
|
|
|
|
stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while adding the device type policy to database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while adding the device type policy to database.", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,10 +71,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
public Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
|
|
|
|
String query = "INSERT INTO DM_ROLE_POLICY (ROLE_NAME, POLICY_ID) VALUES (?, ?)";
|
|
|
@ -90,11 +83,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.addBatch();
|
|
|
|
stmt.addBatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.executeBatch();
|
|
|
|
stmt.executeBatch();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while adding the role name with policy to database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while adding the role name with policy to database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,10 +93,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
public Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
|
|
|
|
String query = "INSERT INTO DM_USER_POLICY (POLICY_ID, USERNAME) VALUES (?, ?)";
|
|
|
@ -117,11 +105,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.addBatch();
|
|
|
|
stmt.addBatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.executeBatch();
|
|
|
|
stmt.executeBatch();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while adding the user name with policy to database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while adding the user name with policy to database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -130,10 +115,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
public Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "INSERT INTO DM_DEVICE_POLICY (DEVICE_ID, POLICY_ID) VALUES (?, ?)";
|
|
|
|
String query = "INSERT INTO DM_DEVICE_POLICY (DEVICE_ID, POLICY_ID) VALUES (?, ?)";
|
|
|
@ -145,9 +128,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.executeBatch();
|
|
|
|
stmt.executeBatch();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while adding the device ids with policy to database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while adding the device ids with policy to " +
|
|
|
|
log.error(msg, e);
|
|
|
|
"database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -156,7 +138,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException {
|
|
|
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
@ -173,11 +154,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.addBatch();
|
|
|
|
stmt.addBatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.executeBatch();
|
|
|
|
stmt.executeBatch();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while updating policy priorities in database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while updating policy priorities in database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -202,15 +180,12 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
generatedKeys = stmt.getGeneratedKeys();
|
|
|
|
generatedKeys = stmt.getGeneratedKeys();
|
|
|
|
|
|
|
|
|
|
|
|
while (generatedKeys.next()) {
|
|
|
|
while (generatedKeys.next()) {
|
|
|
|
criteria.setId(generatedKeys.getInt(1));
|
|
|
|
criteria.setId(generatedKeys.getInt(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while inserting the criterion (" + criteria.getName() + ") to database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while inserting the criterion (" + criteria.getName() +
|
|
|
|
log.error(msg, e);
|
|
|
|
") to database.", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -219,11 +194,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Criterion updateCriterion(Criterion criteria) throws PolicyManagerDAOException {
|
|
|
|
public Criterion updateCriterion(Criterion criteria) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "UPDATE DM_CRITERIA SET NAME = ? WHERE ID = ? AND TENANT_ID = ?";
|
|
|
|
String query = "UPDATE DM_CRITERIA SET NAME = ? WHERE ID = ? AND TENANT_ID = ?";
|
|
|
@ -232,11 +205,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setInt(2, criteria.getId());
|
|
|
|
stmt.setInt(2, criteria.getId());
|
|
|
|
stmt.setInt(3, tenantId);
|
|
|
|
stmt.setInt(3, tenantId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while inserting the criterion (" + criteria.getName() + ") to database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while inserting the criterion (" + criteria.getName() +
|
|
|
|
log.error(msg, e);
|
|
|
|
") to database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -245,7 +216,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Criterion getCriterion(int id) throws PolicyManagerDAOException {
|
|
|
|
public Criterion getCriterion(int id) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
@ -265,26 +235,20 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
criterion.setName(resultSet.getString("NAME"));
|
|
|
|
criterion.setName(resultSet.getString("NAME"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return criterion;
|
|
|
|
return criterion;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the policies from the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Criterion getCriterion(String name) throws PolicyManagerDAOException {
|
|
|
|
public Criterion getCriterion(String name) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
Criterion criterion = new Criterion();
|
|
|
|
Criterion criterion = new Criterion();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_CRITERIA WHERE NAME= ? AND TENANT_ID = ?";
|
|
|
|
String query = "SELECT * FROM DM_CRITERIA WHERE NAME= ? AND TENANT_ID = ?";
|
|
|
@ -298,26 +262,20 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
criterion.setName(resultSet.getString("NAME"));
|
|
|
|
criterion.setName(resultSet.getString("NAME"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return criterion;
|
|
|
|
return criterion;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the policies from the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkCriterionExists(String name) throws PolicyManagerDAOException {
|
|
|
|
public boolean checkCriterionExists(String name) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
boolean exist = false;
|
|
|
|
boolean exist = false;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_CRITERIA WHERE NAME = ? AND TENANT_ID = ?";
|
|
|
|
String query = "SELECT * FROM DM_CRITERIA WHERE NAME = ? AND TENANT_ID = ?";
|
|
|
@ -325,25 +283,24 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setString(1, name);
|
|
|
|
stmt.setString(1, name);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
exist = resultSet.next();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resultSet.next()) {
|
|
|
|
|
|
|
|
//TODO: FIXME
|
|
|
|
|
|
|
|
exist = resultSet.getBoolean(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while checking whether criterion (" + name + ") exists.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while checking whether criterion (" + name +
|
|
|
|
log.error(msg, e);
|
|
|
|
") exists", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exist;
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteCriterion(Criterion criteria) throws PolicyManagerDAOException {
|
|
|
|
public boolean deleteCriterion(Criterion criteria) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "DELETE FROM DM_CRITERIA WHERE ID = ?";
|
|
|
|
String query = "DELETE FROM DM_CRITERIA WHERE ID = ?";
|
|
|
@ -356,9 +313,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Unable to delete the policy (" + criteria.getName() + ") from database.";
|
|
|
|
throw new PolicyManagerDAOException("Unable to delete the policy (" + criteria.getName() +
|
|
|
|
log.error(msg);
|
|
|
|
") from database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -366,13 +322,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Criterion> getAllPolicyCriteria() throws PolicyManagerDAOException {
|
|
|
|
public List<Criterion> getAllPolicyCriteria() throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
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<Criterion>();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_CRITERIA WHERE TENANT_ID = ?";
|
|
|
|
String query = "SELECT * FROM DM_CRITERIA WHERE TENANT_ID = ?";
|
|
|
@ -387,14 +341,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
criteria.add(criterion);
|
|
|
|
criteria.add(criterion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return criteria;
|
|
|
|
return criteria;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the policies from the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -441,11 +391,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addPolicyCriteriaProperties(List<PolicyCriterion> policyCriteria) throws PolicyManagerDAOException {
|
|
|
|
public boolean addPolicyCriteriaProperties(List<PolicyCriterion> policyCriteria) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, PROP_KEY, PROP_VALUE, " +
|
|
|
|
String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, PROP_KEY, PROP_VALUE, " +
|
|
|
@ -453,7 +400,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
|
|
|
|
|
|
|
|
for (PolicyCriterion criterion : policyCriteria) {
|
|
|
|
for (PolicyCriterion criterion : policyCriteria) {
|
|
|
|
|
|
|
|
|
|
|
|
Properties prop = criterion.getProperties();
|
|
|
|
Properties prop = criterion.getProperties();
|
|
|
|
for (String name : prop.stringPropertyNames()) {
|
|
|
|
for (String name : prop.stringPropertyNames()) {
|
|
|
|
|
|
|
|
|
|
|
@ -467,30 +413,21 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// stmt.executeUpdate();
|
|
|
|
// stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException | IOException e) {
|
|
|
|
String msg = "Error occurred while inserting the criterion properties to database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while inserting the criterion properties " +
|
|
|
|
log.error(msg, e);
|
|
|
|
"to database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while inserting the criterion properties to database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<PolicyCriterion> getPolicyCriteria(int policyId) throws PolicyManagerDAOException {
|
|
|
|
public List<PolicyCriterion> getPolicyCriteria(int policyId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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<PolicyCriterion>();
|
|
|
|
|
|
|
|
|
|
|
|
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 " +
|
|
|
@ -522,14 +459,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
prop.setProperty(resultSet.getString("PROP_KEY"), resultSet.getString("PROP_VALUE"));
|
|
|
|
prop.setProperty(resultSet.getString("PROP_KEY"), resultSet.getString("PROP_VALUE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the criteria related to policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the criteria related to policies from " +
|
|
|
|
log.error(msg, e);
|
|
|
|
"the database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return criteria;
|
|
|
|
return criteria;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -555,9 +489,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while updating policy (" + policy.getPolicyName() + ") in database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while updating policy (" + policy.getPolicyName() +
|
|
|
|
log.error(msg, e);
|
|
|
|
") in database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -566,13 +499,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy getPolicy(int policyId) throws PolicyManagerDAOException {
|
|
|
|
public Policy getPolicy(int policyId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
Policy policy = new Policy();
|
|
|
|
Policy policy = new Policy();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_POLICY WHERE ID= ? AND TENANT_ID = ? ";
|
|
|
|
String query = "SELECT * FROM DM_POLICY WHERE ID= ? AND TENANT_ID = ? ";
|
|
|
@ -592,19 +523,15 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
return policy;
|
|
|
|
return policy;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the policies from the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy getPolicyByProfileID(int profileId) throws PolicyManagerDAOException {
|
|
|
|
public Policy getPolicyByProfileID(int profileId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
@ -620,7 +547,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
@ -628,20 +554,15 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
policy.setCompliance(resultSet.getString("COMPLIANCE"));
|
|
|
|
policy.setCompliance(resultSet.getString("COMPLIANCE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return policy;
|
|
|
|
return policy;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the policies from the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Policy> getAllPolicies() throws PolicyManagerDAOException {
|
|
|
|
public List<Policy> getAllPolicies() throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
@ -657,7 +578,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
Policy policy = new Policy();
|
|
|
|
Policy policy = new Policy();
|
|
|
|
|
|
|
|
|
|
|
|
policy.setId(resultSet.getInt("ID"));
|
|
|
|
policy.setId(resultSet.getInt("ID"));
|
|
|
|
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
|
|
|
|
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
|
|
|
|
policy.setPolicyName(resultSet.getString("NAME"));
|
|
|
|
policy.setPolicyName(resultSet.getString("NAME"));
|
|
|
@ -668,14 +588,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
policies.add(policy);
|
|
|
|
policies.add(policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return policies;
|
|
|
|
return policies;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the policies from the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -686,12 +602,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Integer> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagerDAOException {
|
|
|
|
public List<Integer> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
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<Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
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 = ?";
|
|
|
@ -700,28 +614,21 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
|
|
|
|
|
|
|
deviceIdList.add(resultSet.getInt("DEVICE_ID"));
|
|
|
|
deviceIdList.add(resultSet.getInt("DEVICE_ID"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deviceIdList;
|
|
|
|
return deviceIdList;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while getting the device related to policies.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while getting the device related to policies", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException {
|
|
|
|
public List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
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<String>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
@ -731,18 +638,13 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
|
|
|
|
|
|
|
roleNames.add(resultSet.getString("ROLE_NAME"));
|
|
|
|
roleNames.add(resultSet.getString("ROLE_NAME"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return roleNames;
|
|
|
|
return roleNames;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while getting the roles related to policies.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while getting the roles related to policies", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -761,30 +663,23 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
|
|
|
|
|
|
|
users.add(resultSet.getString("USERNAME"));
|
|
|
|
users.add(resultSet.getString("USERNAME"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return users;
|
|
|
|
return users;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while getting the roles related to policies.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while getting the roles related to policies", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addEffectivePolicyToDevice(int deviceId, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
public void addEffectivePolicyToDevice(int deviceId, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
|
|
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED (DEVICE_ID, POLICY_ID, POLICY_CONTENT, " +
|
|
|
|
String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED (DEVICE_ID, POLICY_ID, POLICY_CONTENT, " +
|
|
|
@ -796,17 +691,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setTimestamp(4, currentTimestamp);
|
|
|
|
stmt.setTimestamp(4, currentTimestamp);
|
|
|
|
stmt.setTimestamp(5, currentTimestamp);
|
|
|
|
stmt.setTimestamp(5, currentTimestamp);
|
|
|
|
stmt.setInt(6, tenantId);
|
|
|
|
stmt.setInt(6, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException | IOException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while adding the evaluated feature list to device", e);
|
|
|
|
String msg = "Error occurred while adding the evaluated feature list to device.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while adding the evaluated feature list to device.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -815,12 +702,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setPolicyApplied(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
public void setPolicyApplied(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
|
|
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? AND" +
|
|
|
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? AND" +
|
|
|
@ -830,13 +715,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setBoolean(2, true);
|
|
|
|
stmt.setBoolean(2, true);
|
|
|
|
stmt.setInt(3, deviceId);
|
|
|
|
stmt.setInt(3, deviceId);
|
|
|
|
stmt.setInt(4, tenantId);
|
|
|
|
stmt.setInt(4, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while updating applied policy to device (" + deviceId + ")";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while updating applied policy to device (" +
|
|
|
|
log.error(msg, e);
|
|
|
|
deviceId + ")", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -844,14 +726,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateEffectivePolicyToDevice(int deviceId, Policy policy)
|
|
|
|
public void updateEffectivePolicyToDevice(int deviceId, Policy policy) throws PolicyManagerDAOException {
|
|
|
|
throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
|
|
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
|
|
|
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
|
|
|
@ -865,29 +744,21 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setInt(6, tenantId);
|
|
|
|
stmt.setInt(6, tenantId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException | IOException e) {
|
|
|
|
String msg = "Error occurred while updating the evaluated feature list to device.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while updating the evaluated feature list " +
|
|
|
|
log.error(msg, e);
|
|
|
|
"to device", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the evaluated feature list to device.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
public boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
boolean exist = false;
|
|
|
|
boolean exist = false;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
@ -896,26 +767,21 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
exist = resultSet.next();
|
|
|
|
exist = resultSet.next();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while checking whether device (" + deviceId + ") has a policy to apply.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while checking whether device (" + deviceId +
|
|
|
|
log.error(msg, e);
|
|
|
|
") has a policy to apply", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exist;
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Integer> getPolicyIdsOfDevice(Device device) throws PolicyManagerDAOException {
|
|
|
|
public List<Integer> getPolicyIdsOfDevice(Device device) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
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<Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
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 = ? ";
|
|
|
@ -926,26 +792,20 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
policyIds.add(resultSet.getInt("POLICY_ID"));
|
|
|
|
policyIds.add(resultSet.getInt("POLICY_ID"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the device policy table.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the device policy table", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return policyIds;
|
|
|
|
return policyIds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Integer> getPolicyOfRole(String roleName) throws PolicyManagerDAOException {
|
|
|
|
public List<Integer> getPolicyOfRole(String roleName) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
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<Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
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 = ? ";
|
|
|
@ -956,26 +816,20 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
policyIds.add(resultSet.getInt("POLICY_ID"));
|
|
|
|
policyIds.add(resultSet.getInt("POLICY_ID"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the role policy table.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the role policy table", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return policyIds;
|
|
|
|
return policyIds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Integer> getPolicyOfUser(String username) throws PolicyManagerDAOException {
|
|
|
|
public List<Integer> getPolicyOfUser(String username) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
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<Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
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 = ? ";
|
|
|
@ -986,25 +840,19 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
policyIds.add(resultSet.getInt("POLICY_ID"));
|
|
|
|
policyIds.add(resultSet.getInt("POLICY_ID"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the user policy table.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the user policy table", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return policyIds;
|
|
|
|
return policyIds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deletePolicy(Policy policy) throws PolicyManagerDAOException {
|
|
|
|
public boolean deletePolicy(Policy policy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "DELETE FROM DM_POLICY WHERE ID = ? AND TENANT_ID = ?";
|
|
|
|
String query = "DELETE FROM DM_POLICY WHERE ID = ? AND TENANT_ID = ?";
|
|
|
@ -1018,9 +866,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Unable to delete the policy (" + policy.getPolicyName() + ") from database.";
|
|
|
|
throw new PolicyManagerDAOException("Unable to delete the policy (" + policy.getPolicyName() +
|
|
|
|
log.error(msg);
|
|
|
|
") from database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1028,11 +875,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deletePolicy(int policyId) throws PolicyManagerDAOException {
|
|
|
|
public boolean deletePolicy(int policyId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "DELETE FROM DM_POLICY WHERE ID = ? AND TENANT_ID = ?";
|
|
|
|
String query = "DELETE FROM DM_POLICY WHERE ID = ? AND TENANT_ID = ?";
|
|
|
@ -1046,9 +891,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Unable to delete the policy (" + policyId + ") from database.";
|
|
|
|
throw new PolicyManagerDAOException("Unable to delete the policy (" + policyId + ") from database", e);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1056,10 +899,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteAllPolicyRelatedConfigs(int policyId) throws PolicyManagerDAOException {
|
|
|
|
public boolean deleteAllPolicyRelatedConfigs(int policyId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
|
|
|
@ -1073,27 +914,23 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
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);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String deleteCriteria = "DELETE FROM DM_POLICY_CRITERIA WHERE POLICY_ID = ?";
|
|
|
|
String deleteCriteria = "DELETE FROM DM_POLICY_CRITERIA WHERE POLICY_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(deleteCriteria);
|
|
|
|
stmt = conn.prepareStatement(deleteCriteria);
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
stmt.setInt(1, policyId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Policy (" + policyId + ") related configs deleted from database.");
|
|
|
|
log.debug("Policy (" + policyId + ") related configs deleted from database.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Unable to delete the policy (" + policyId + ") related configs from database.";
|
|
|
|
throw new PolicyManagerDAOException("Unable to delete the policy (" + policyId +
|
|
|
|
log.error(msg);
|
|
|
|
") related configs from database", e);
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1103,17 +940,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
return PolicyManagementDAOFactory.getConnection();
|
|
|
|
return PolicyManagementDAOFactory.getConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void closeConnection() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
|
|
|
|
log.warn("Unable to close the database connection.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Policy persistPolicy(Policy policy) throws PolicyManagerDAOException {
|
|
|
|
private Policy persistPolicy(Policy policy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet generatedKeys = null;
|
|
|
|
ResultSet generatedKeys = null;
|
|
|
@ -1149,9 +976,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while adding policy to the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while adding policy to the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1167,7 +992,6 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
* @throws PolicyManagerDAOException
|
|
|
|
* @throws PolicyManagerDAOException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private int getDeviceTypeId(String deviceType) throws PolicyManagerDAOException {
|
|
|
|
private int getDeviceTypeId(String deviceType) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
@ -1182,21 +1006,16 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
deviceTypeId = resultSet.getInt("ID");
|
|
|
|
deviceTypeId = resultSet.getInt("ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while selecting the device type id.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while selecting the device type id", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deviceTypeId;
|
|
|
|
return deviceTypeId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int readHighestPriorityOfPolicies() throws PolicyManagerDAOException {
|
|
|
|
private int readHighestPriorityOfPolicies() throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
@ -1216,11 +1035,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Priority of the new policy added is (" + priority + ")");
|
|
|
|
log.debug("Priority of the new policy added is (" + priority + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the highest priority of the policies.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the highest priority of the policies", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1229,13 +1045,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getPolicyCount() throws PolicyManagerDAOException {
|
|
|
|
public int getPolicyCount() throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int policyCount = 0;
|
|
|
|
int policyCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT COUNT(ID) AS POLICY_COUNT FROM DM_POLICY WHERE TENANT_ID = ?";
|
|
|
|
String query = "SELECT COUNT(ID) AS POLICY_COUNT FROM DM_POLICY WHERE TENANT_ID = ?";
|
|
|
@ -1247,25 +1061,19 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
policyCount = resultSet.getInt("POLICY_COUNT");
|
|
|
|
policyCount = resultSet.getInt("POLICY_COUNT");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return policyCount;
|
|
|
|
return policyCount;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while reading the policies from the database.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while reading the policies from the database", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getAppliedPolicyId(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
public int getAppliedPolicyId(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
@ -1277,28 +1085,21 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
return resultSet.getInt("POLICY_ID");
|
|
|
|
return resultSet.getInt("POLICY_ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while getting the applied policy id.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while getting the applied policy id", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy getAppliedPolicy(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
public Policy getAppliedPolicy(int deviceId) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
Policy policy = null;
|
|
|
|
Policy policy = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
@ -1336,20 +1137,13 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while getting the applied policy.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while getting the applied policy", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
String msg = "Unable to read the byte stream for content";
|
|
|
|
throw new PolicyManagerDAOException("Unable to read the byte stream for content", e);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
String msg = "Class not found while converting the object";
|
|
|
|
throw new PolicyManagerDAOException("Class not found while converting the object", e);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// if (policy != null && log.isDebugEnabled()) {
|
|
|
|
// if (policy != null && log.isDebugEnabled()) {
|
|
|
@ -1365,14 +1159,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public HashMap<Integer, Integer> getAppliedPolicyIds(List<Integer> deviceIds) throws PolicyManagerDAOException {
|
|
|
|
public HashMap<Integer, Integer> getAppliedPolicyIds(List<Integer> deviceIds) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
|
|
|
|
HashMap<Integer, Integer> devicePolicyIds = new HashMap<>();
|
|
|
|
HashMap<Integer, Integer> devicePolicyIds = new HashMap<>();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
@ -1384,16 +1175,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
devicePolicyIds.put(resultSet.getInt("DEVICE_ID"), resultSet.getInt("POLICY_ID"));
|
|
|
|
devicePolicyIds.put(resultSet.getInt("DEVICE_ID"), resultSet.getInt("POLICY_ID"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String msg = "Error occurred while getting the applied policy.";
|
|
|
|
throw new PolicyManagerDAOException("Error occurred while getting the applied policy", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
this.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return devicePolicyIds;
|
|
|
|
return devicePolicyIds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|