|
|
@ -137,19 +137,15 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
if (policy.getUsers() != null) {
|
|
|
|
if (policy.getUsers() != null) {
|
|
|
|
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
|
|
|
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getRoles() != null) {
|
|
|
|
if (policy.getRoles() != null) {
|
|
|
|
policyDAO.addPolicyToRole(policy.getRoles(), policy);
|
|
|
|
policyDAO.addPolicyToRole(policy.getRoles(), policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getDevices() != null) {
|
|
|
|
if (policy.getDevices() != null) {
|
|
|
|
policyDAO.addPolicyToDevice(policy.getDevices(), policy);
|
|
|
|
policyDAO.addPolicyToDevice(policy.getDevices(), policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getDeviceGroups() != null && !policy.getDeviceGroups().isEmpty()) {
|
|
|
|
if (policy.getDeviceGroups() != null && !policy.getDeviceGroups().isEmpty()) {
|
|
|
|
policyDAO.addDeviceGroupsToPolicy(policy);
|
|
|
|
policyDAO.addDeviceGroupsToPolicy(policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getPolicyCriterias() != null) {
|
|
|
|
if (policy.getPolicyCriterias() != null) {
|
|
|
|
List<PolicyCriterion> criteria = policy.getPolicyCriterias();
|
|
|
|
List<PolicyCriterion> criteria = policy.getPolicyCriterias();
|
|
|
|
for (PolicyCriterion criterion : criteria) {
|
|
|
|
for (PolicyCriterion criterion : criteria) {
|
|
|
@ -174,12 +170,10 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
policyDAO.activatePolicy(policy.getId());
|
|
|
|
policyDAO.activatePolicy(policy.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the policy (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the policy (" +
|
|
|
|
policy.getId() + " - " + policy.getPolicyName() + ")", e);
|
|
|
|
policy.getId() + " - " + policy.getPolicyName() + ")", e);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (ProfileManagerDAOException e) {
|
|
|
|
} catch (ProfileManagerDAOException e) {
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the profile related to policy (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while adding the profile related to policy (" +
|
|
|
@ -196,7 +190,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
|
|
|
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Previous policy needs to be obtained before beginning the transaction
|
|
|
|
// Previous policy needs to be obtained before beginning the transaction
|
|
|
|
Policy previousPolicy = this.getPolicy(policy.getId());
|
|
|
|
Policy previousPolicy = this.getPolicy(policy.getId());
|
|
|
@ -205,7 +198,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
// This will keep track of the policies updated.
|
|
|
|
// This will keep track of the policies updated.
|
|
|
|
policyDAO.recordUpdatedPolicy(policy);
|
|
|
|
policyDAO.recordUpdatedPolicy(policy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ProfileFeature> existingFeaturesList = new ArrayList<>();
|
|
|
|
List<ProfileFeature> existingFeaturesList = new ArrayList<>();
|
|
|
|
List<ProfileFeature> newFeaturesList = new ArrayList<>();
|
|
|
|
List<ProfileFeature> newFeaturesList = new ArrayList<>();
|
|
|
|
List<ProfileFeature> featuresToDelete = new ArrayList<>();
|
|
|
|
List<ProfileFeature> featuresToDelete = new ArrayList<>();
|
|
|
@ -215,7 +207,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
Map<Integer, List<CorrectiveAction>> existingCorrectiveActionsMap = new HashMap<>();
|
|
|
|
Map<Integer, List<CorrectiveAction>> existingCorrectiveActionsMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
List<ProfileFeature> updatedFeatureList = policy.getProfile().getProfileFeaturesList();
|
|
|
|
List<ProfileFeature> updatedFeatureList = policy.getProfile().getProfileFeaturesList();
|
|
|
|
|
|
|
|
|
|
|
|
List<ProfileFeature> existingProfileFeaturesList = previousPolicy.getProfile().getProfileFeaturesList();
|
|
|
|
List<ProfileFeature> existingProfileFeaturesList = previousPolicy.getProfile().getProfileFeaturesList();
|
|
|
|
|
|
|
|
|
|
|
|
// Checks for the existing features
|
|
|
|
// Checks for the existing features
|
|
|
@ -257,27 +248,20 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
if (!newFeaturesList.isEmpty()) {
|
|
|
|
if (!newFeaturesList.isEmpty()) {
|
|
|
|
featureDAO.addProfileFeatures(newFeaturesList, profileId);
|
|
|
|
featureDAO.addProfileFeatures(newFeaturesList, profileId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!featuresToDelete.isEmpty()) {
|
|
|
|
if (!featuresToDelete.isEmpty()) {
|
|
|
|
for (ProfileFeature pf : featuresToDelete)
|
|
|
|
for (ProfileFeature pf : featuresToDelete)
|
|
|
|
featureDAO.deleteProfileFeatures(pf.getId());
|
|
|
|
featureDAO.deleteProfileFeatures(pf.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
policyDAO.deleteCriteriaAndDeviceRelatedConfigs(policy.getId());
|
|
|
|
policyDAO.deleteCriteriaAndDeviceRelatedConfigs(policy.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getUsers() != null) {
|
|
|
|
if (policy.getUsers() != null) {
|
|
|
|
policyDAO.updateUserOfPolicy(policy.getUsers(), previousPolicy);
|
|
|
|
policyDAO.updateUserOfPolicy(policy.getUsers(), previousPolicy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getRoles() != null) {
|
|
|
|
if (policy.getRoles() != null) {
|
|
|
|
policyDAO.updateRolesOfPolicy(policy.getRoles(), previousPolicy);
|
|
|
|
policyDAO.updateRolesOfPolicy(policy.getRoles(), previousPolicy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getDevices() != null) {
|
|
|
|
if (policy.getDevices() != null) {
|
|
|
|
policyDAO.addPolicyToDevice(policy.getDevices(), previousPolicy);
|
|
|
|
policyDAO.addPolicyToDevice(policy.getDevices(), previousPolicy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (policy.getDeviceGroups() != null && !policy.getDeviceGroups().isEmpty()) {
|
|
|
|
if (policy.getDeviceGroups() != null && !policy.getDeviceGroups().isEmpty()) {
|
|
|
|
policyDAO.addDeviceGroupsToPolicy(policy);
|
|
|
|
policyDAO.addDeviceGroupsToPolicy(policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -538,7 +522,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
|
|
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
|
|
|
boolean bool;
|
|
|
|
boolean bool;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// List<Policy> existingPolicies = this.getPolicies();
|
|
|
|
|
|
|
|
List<Policy> existingPolicies;
|
|
|
|
List<Policy> existingPolicies;
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
|
existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
@ -598,7 +581,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
|
|
|
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
|
|
|
boolean bool;
|
|
|
|
boolean bool;
|
|
|
|
|
|
|
|
|
|
|
|
List<Policy> policies = this.getPolicies();
|
|
|
|
List<Policy> policies = this.getPolicies();
|
|
|
|
Policy pol = null;
|
|
|
|
Policy pol = null;
|
|
|
|
for (Policy p : policies) {
|
|
|
|
for (Policy p : policies) {
|
|
|
@ -626,7 +608,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
featureDAO.deleteFeaturesOfProfile(policy.getProfileId());
|
|
|
|
featureDAO.deleteFeaturesOfProfile(policy.getProfileId());
|
|
|
|
|
|
|
|
|
|
|
|
profileDAO.deleteProfile(policy.getProfileId());
|
|
|
|
profileDAO.deleteProfile(policy.getProfileId());
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
return bool;
|
|
|
|
return bool;
|
|
|
@ -684,7 +665,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList,
|
|
|
|
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList,
|
|
|
|
Policy policy) throws PolicyManagementException {
|
|
|
|
Policy policy) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
@ -759,7 +739,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagementException {
|
|
|
|
public Policy addPolicyToUser(List<String> usernameList, Policy policy) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
if (policy.getId() == 0) {
|
|
|
|
if (policy.getId() == 0) {
|
|
|
@ -791,22 +770,17 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy getPolicyByProfileID(int profileId) throws PolicyManagementException {
|
|
|
|
public Policy getPolicyByProfileID(int profileId) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
Policy policy;
|
|
|
|
Policy policy;
|
|
|
|
Profile profile;
|
|
|
|
Profile profile;
|
|
|
|
List<Device> deviceList;
|
|
|
|
List<Device> deviceList;
|
|
|
|
List<String> roleNames;
|
|
|
|
List<String> roleNames;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policy = policyDAO.getPolicyByProfileID(profileId);
|
|
|
|
policy = policyDAO.getPolicyByProfileID(profileId);
|
|
|
|
|
|
|
|
|
|
|
|
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
|
|
|
|
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
|
|
|
|
profile = profileDAO.getProfile(profileId);
|
|
|
|
profile = profileDAO.getProfile(profileId);
|
|
|
|
policy.setProfile(profile);
|
|
|
|
policy.setProfile(profile);
|
|
|
|
policy.setRoles(roleNames);
|
|
|
|
policy.setRoles(roleNames);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policy related to profile ID (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policy related to profile ID (" +
|
|
|
|
profileId + ")", e);
|
|
|
|
profileId + ")", e);
|
|
|
@ -827,7 +801,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Policy getPolicy(int policyId) throws PolicyManagementException {
|
|
|
|
public Policy getPolicy(int policyId) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
Policy policy;
|
|
|
|
Policy policy;
|
|
|
|
List<Device> deviceList;
|
|
|
|
List<Device> deviceList;
|
|
|
|
List<String> roleNames;
|
|
|
|
List<String> roleNames;
|
|
|
@ -835,13 +808,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policy = policyDAO.getPolicy(policyId);
|
|
|
|
policy = policyDAO.getPolicy(policyId);
|
|
|
|
|
|
|
|
|
|
|
|
roleNames = policyDAO.getPolicyAppliedRoles(policyId);
|
|
|
|
roleNames = policyDAO.getPolicyAppliedRoles(policyId);
|
|
|
|
userNames = policyDAO.getPolicyAppliedUsers(policyId);
|
|
|
|
userNames = policyDAO.getPolicyAppliedUsers(policyId);
|
|
|
|
|
|
|
|
|
|
|
|
//Profile profile = profileDAO.getProfile(policy.getProfileId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policy.setRoles(roleNames);
|
|
|
|
policy.setRoles(roleNames);
|
|
|
|
policy.setUsers(userNames);
|
|
|
|
policy.setUsers(userNames);
|
|
|
|
|
|
|
|
|
|
|
@ -853,14 +821,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policy related to policy ID (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the policy related to policy ID (" +
|
|
|
|
policyId + ")", e);
|
|
|
|
policyId + ")", e);
|
|
|
|
// } catch (ProfileManagerDAOException e) {
|
|
|
|
|
|
|
|
// throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
|
|
|
|
|
|
|
|
// policyId + ")", e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
// } catch (ProfileManagementException e) {
|
|
|
|
|
|
|
|
// throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
|
|
|
|
|
|
|
|
// policyId + ")", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -909,7 +871,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Policy> getPolicies() throws PolicyManagementException {
|
|
|
|
public List<Policy> getPolicies() throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<Policy> policyList;
|
|
|
|
List<Policy> policyList;
|
|
|
|
List<Profile> profileList;
|
|
|
|
List<Profile> profileList;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -932,20 +893,16 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Following is done because connection close has been implemented in every method.
|
|
|
|
// Following is done because connection close has been implemented in every method.
|
|
|
|
|
|
|
|
|
|
|
|
for (Policy policy : policyList) {
|
|
|
|
for (Policy policy : policyList) {
|
|
|
|
policy.setDevices(this.getPolicyAppliedDevicesIds(policy.getId()));
|
|
|
|
policy.setDevices(this.getPolicyAppliedDevicesIds(policy.getId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return policyList;
|
|
|
|
return policyList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Policy> getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
public List<Policy> getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
Device device;
|
|
|
|
Device device;
|
|
|
@ -968,7 +925,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// List<Policy> tempPolicyList = this.getPolicies();
|
|
|
|
|
|
|
|
List<Policy> tempPolicyList;
|
|
|
|
List<Policy> tempPolicyList;
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
|
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
@ -991,9 +947,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Policy> getPoliciesOfDeviceType(String deviceTypeName) throws PolicyManagementException {
|
|
|
|
public List<Policy> getPoliciesOfDeviceType(String deviceTypeName) throws PolicyManagementException {
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName);
|
|
|
|
|
|
|
|
// List<Policy> allPolicies = this.getPolicies();
|
|
|
|
|
|
|
|
List<Policy> allPolicies;
|
|
|
|
List<Policy> allPolicies;
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
|
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
@ -1006,28 +959,14 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
policies.add(policy);
|
|
|
|
policies.add(policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// for (Profile profile : profileList) {
|
|
|
|
|
|
|
|
// for (Policy policy : allPolicies) {
|
|
|
|
|
|
|
|
// if (policy.getProfileId() == profile.getProfileId()) {
|
|
|
|
|
|
|
|
// policy.setProfile(profile);
|
|
|
|
|
|
|
|
// policies.add(policy);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
Collections.sort(policies);
|
|
|
|
Collections.sort(policies);
|
|
|
|
// } catch (ProfileManagementException e) {
|
|
|
|
|
|
|
|
// throw new PolicyManagementException("Error occurred while getting all the profile features.", e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
return policies;
|
|
|
|
return policies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Policy> getPoliciesOfRole(String roleName) throws PolicyManagementException {
|
|
|
|
public List<Policy> getPoliciesOfRole(String roleName) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policyIdList = policyDAO.getPolicyOfRole(roleName);
|
|
|
|
policyIdList = policyDAO.getPolicyOfRole(roleName);
|
|
|
@ -1039,7 +978,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// List<Policy> tempPolicyList = this.getPolicies();
|
|
|
|
|
|
|
|
List<Policy> tempPolicyList;
|
|
|
|
List<Policy> tempPolicyList;
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
|
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
@ -1060,10 +998,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Policy> getPoliciesOfUser(String username) throws PolicyManagementException {
|
|
|
|
public List<Policy> getPoliciesOfUser(String username) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
List<Policy> policies = new ArrayList<>();
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
List<Integer> policyIdList;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policyIdList = policyDAO.getPolicyOfUser(username);
|
|
|
|
policyIdList = policyDAO.getPolicyOfUser(username);
|
|
|
@ -1074,7 +1010,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// List<Policy> tempPolicyList = this.getPolicies();
|
|
|
|
|
|
|
|
List<Policy> tempPolicyList;
|
|
|
|
List<Policy> tempPolicyList;
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
|
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
@ -1095,7 +1030,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException {
|
|
|
|
public List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Integer> deviceIds;
|
|
|
|
List<Integer> deviceIds;
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
@ -1169,17 +1103,11 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public UpdatedPolicyDeviceListBean applyChangesMadeToPolicies() throws PolicyManagementException {
|
|
|
|
public UpdatedPolicyDeviceListBean applyChangesMadeToPolicies() throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
List<String> changedDeviceTypes = new ArrayList<>();
|
|
|
|
List<String> changedDeviceTypes = new ArrayList<>();
|
|
|
|
List<Policy> updatedPolicies = new ArrayList<>();
|
|
|
|
List<Policy> updatedPolicies = new ArrayList<>();
|
|
|
|
List<Integer> updatedPolicyIds = new ArrayList<>();
|
|
|
|
List<Integer> updatedPolicyIds = new ArrayList<>();
|
|
|
|
boolean transactionDone = false;
|
|
|
|
boolean transactionDone = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//HashMap<Integer, Integer> map = policyDAO.getUpdatedPolicyIdandDeviceTypeId();
|
|
|
|
|
|
|
|
// List<Policy> activePolicies = new ArrayList<>();
|
|
|
|
|
|
|
|
// List<Policy> inactivePolicies = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// List<Policy> allPolicies = this.getPolicies();
|
|
|
|
|
|
|
|
List<Policy> allPolicies;
|
|
|
|
List<Policy> allPolicies;
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
if (policyConfiguration.getCacheEnable()) {
|
|
|
|
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
|
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
|
|
@ -1194,11 +1122,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
changedDeviceTypes.add(policy.getProfile().getDeviceType());
|
|
|
|
changedDeviceTypes.add(policy.getProfile().getDeviceType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if (policy.isActive()) {
|
|
|
|
|
|
|
|
// activePolicies.add(policy);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// inactivePolicies.add(policy);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
transactionDone = true;
|
|
|
|
transactionDone = true;
|
|
|
@ -1282,7 +1205,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
boolean exist;
|
|
|
|
boolean exist;
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
@ -1309,7 +1231,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
.getInstance().getDeviceManagementService();
|
|
|
|
Device device;
|
|
|
|
Device device;
|
|
|
@ -1319,7 +1240,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
|
policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
@ -1373,7 +1293,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
public Policy getAppliedPolicyToDevice(Device device) throws PolicyManagementException {
|
|
|
|
public Policy getAppliedPolicyToDevice(Device device) throws PolicyManagementException {
|
|
|
|
Policy policy;
|
|
|
|
Policy policy;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//int policyId = policyDAO.getAppliedPolicyId(device.getId());
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
policy = policyDAO.getAppliedPolicy(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
|
policy = policyDAO.getAppliedPolicy(device.getId(), device.getEnrolmentInfo().getId());
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
@ -1425,8 +1344,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
private void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyManagementException {
|
|
|
|
private void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String type = null;
|
|
|
|
String type;
|
|
|
|
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,
|
|
|
|
this.getPolicyRevokeOperation(), deviceIdentifiers);
|
|
|
|
this.getPolicyRevokeOperation(), deviceIdentifiers);
|
|
|
@ -1478,11 +1397,9 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (Policy policy : policyList) {
|
|
|
|
for (Policy policy : policyList) {
|
|
|
|
policy.setDevices(this.getPolicyAppliedDevicesIds(policy.getId()));
|
|
|
|
policy.setDevices(this.getPolicyAppliedDevicesIds(policy.getId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return policyList;
|
|
|
|
return policyList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|