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