Adding fix for policy application upon adding devices to group

revert-70ac1926
Ace 4 years ago
parent 4b58b46d8b
commit c1c736b607

@ -100,11 +100,8 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
device.getEnrolmentInfo().setDateOfLastUpdate(System.currentTimeMillis());
boolean status = dms.enrollDevice(device);
PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP();
List<DeviceIdentifier> deviceIdentifierList = new ArrayList<>();
DeviceIdentifier deviceId = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
deviceIdentifierList.add(deviceId);
Policy effectivePolicy = DeviceMgtAPIUtils.getPolicyManagementService().getPEP().getEffectivePolicy(deviceId);
pap.addPolicyToDevice(deviceIdentifierList, effectivePolicy);
DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceId);
pap.publishChanges();
return Response.status(Response.Status.OK).entity(status).build();
} catch (DeviceManagementException e) {
@ -118,9 +115,6 @@ public class DeviceAgentServiceImpl implements DeviceAgentService {
} catch (PolicyManagementException e) {
log.error("failed to add designated policies against newly enrolled device.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (PolicyEvaluationException e) {
log.error("failed while retrieving policies for newly enrolled device.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}

@ -48,6 +48,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import javax.ws.rs.core.Response;
@ -268,12 +269,11 @@ public class GroupManagementServiceImpl implements GroupManagementService {
DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers);
PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP();
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
Policy effectivePolicy = null;
for(DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
Device device = dms.getDevice(deviceIdentifier, false);
if(!device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) {
effectivePolicy = DeviceMgtAPIUtils.getPolicyManagementService().getPEP().getEffectivePolicy(deviceIdentifier);
pap.addPolicyToDevice(deviceIdentifiers, effectivePolicy);
pap.removePolicyUsed(deviceIdentifier);
DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceIdentifier);
}
}
pap.publishChanges();
@ -287,9 +287,9 @@ public class GroupManagementServiceImpl implements GroupManagementService {
} catch (PolicyManagementException e) {
log.error("Error occurred while adding policies against device(s).", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (PolicyEvaluationException e) {
log.error("Error occurred while retrieving policies against device(s).", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
// } catch (PolicyEvaluationException e) {
// log.error("Error occurred while retrieving policies against device(s).", e);
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (DeviceManagementException e) {
log.error("Error occurred while retrieving device information.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -302,12 +302,11 @@ public class GroupManagementServiceImpl implements GroupManagementService {
DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(groupId, deviceIdentifiers);
PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP();
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
Policy effectivePolicy = null;
for(DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
Device device = dms.getDevice(deviceIdentifier, false);
if(!device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) {
effectivePolicy = DeviceMgtAPIUtils.getPolicyManagementService().getPEP().getEffectivePolicy(deviceIdentifier);
pap.addPolicyToDevice(deviceIdentifiers, effectivePolicy);
pap.removePolicyUsed(deviceIdentifier);
DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceIdentifier);
}
}
pap.publishChanges();
@ -321,9 +320,6 @@ public class GroupManagementServiceImpl implements GroupManagementService {
}catch (PolicyManagementException e) {
log.error("Error occurred while adding policies against device(s).", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (PolicyEvaluationException e) {
log.error("Error occurred while retrieving policies against device(s).", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}catch (DeviceManagementException e) {
log.error("Error occurred while retrieving device information.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -339,8 +335,6 @@ public class GroupManagementServiceImpl implements GroupManagementService {
List<DeviceGroup> deviceGroups = service.getGroups(deviceToGroupsAssignment.getDeviceIdentifier(), false);
PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP();
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
Device device = null;
Policy effectivePolicy = null;
for (DeviceGroup group : deviceGroups) {
Integer groupId = group.getGroupId();
if (deviceToGroupsAssignment.getDeviceGroupIds().contains(groupId)) {
@ -352,8 +346,8 @@ public class GroupManagementServiceImpl implements GroupManagementService {
for (int groupId : deviceToGroupsAssignment.getDeviceGroupIds()) {
DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers);
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
effectivePolicy = DeviceMgtAPIUtils.getPolicyManagementService().getPEP().getEffectivePolicy(deviceIdentifier);
pap.addPolicyToDevice(deviceIdentifiers, effectivePolicy);
pap.removePolicyUsed(deviceIdentifier);
DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceIdentifier);
}
}
pap.publishChanges();
@ -367,9 +361,6 @@ public class GroupManagementServiceImpl implements GroupManagementService {
} catch (PolicyManagementException e) {
log.error("Failed to add policies for device assigned to group.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (PolicyEvaluationException e) {
log.error("Failed while retrieving policies device assigned to group.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}

@ -930,6 +930,7 @@ public class PolicyManagerImpl implements PolicyManager {
try {
device = deviceManagementService.getDevice(deviceIdentifier, false);
} catch (DeviceManagementException e) {
PolicyManagementDAOFactory.rollbackTransaction();
throw new PolicyManagementException("Error occurred while getting the device details (" +
deviceIdentifier.getId() + ")", e);
}

Loading…
Cancel
Save