diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
index cc1219c3a1..c688b5997f 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java
@@ -334,6 +334,16 @@ public interface DeviceDAO {
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
int tenantId) throws DeviceManagementDAOException;
+ /**
+ * This method is used to retrieve current enrollment of a given device.
+ *
+ * @param deviceId device id.
+ * @param tenantId tenant id.
+ * @return returns EnrolmentInfo object.
+ * @throws DeviceManagementDAOException
+ */
+ EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException;
+
/**
* This method is used to retrieve current active enrollment of a given device and tenant id.
*
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
index 648c7e2a42..f127f26022 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
@@ -794,6 +794,37 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
}
}
+ @Override
+ public EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException {
+ Connection conn;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ EnrolmentInfo enrolmentInfo = null;
+ try {
+ conn = this.getConnection();
+ String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
+ "DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
+ "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
+ "AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
+ "AND TENANT_ID = ?";
+ stmt = conn.prepareStatement(sql);
+ stmt.setString(1, deviceId.getId());
+ stmt.setString(2, deviceId.getType());
+ stmt.setInt(3, tenantId);
+ stmt.setInt(4, tenantId);
+ rs = stmt.executeQuery();
+ if (rs.next()) {
+ enrolmentInfo = DeviceManagementDAOUtil.loadMatchingEnrolment(rs);
+ }
+ return enrolmentInfo;
+ } catch (SQLException e) {
+ throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
+ "of device '" + deviceId + "'", e);
+ } finally {
+ DeviceManagementDAOUtil.cleanupResources(stmt, rs);
+ }
+ }
+
@Override
public EnrolmentInfo getActiveEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException {
Connection conn;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
index 9465918956..50407a85f4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java
@@ -927,6 +927,13 @@ public class OperationManagerImpl implements OperationManager {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
String user = this.getUser();
enrolmentInfo = deviceDAO.getEnrolment(deviceId, user, tenantId);
+ if (enrolmentInfo == null) {
+ boolean isAdminUser = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
+ isDeviceAdminUser();
+ if (isAdminUser) {
+ enrolmentInfo = deviceDAO.getEnrolment(deviceId, tenantId);
+ }
+ }
} catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
deviceId.getType() + "' device carrying the identifier '" +
@@ -934,6 +941,10 @@ public class OperationManagerImpl implements OperationManager {
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
+ } catch (DeviceAccessAuthorizationException e) {
+ throw new OperationManagementException("Error occurred while checking the device access permissions for '" +
+ deviceId.getType() + "' device carrying the identifier '" +
+ deviceId.getId() + "'", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java
index 24bb47c090..cd39b73060 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationMgtConstants.java
@@ -29,4 +29,11 @@ public class OperationMgtConstants {
public static final String DEVICE_ID_SERVICE_NOT_FOUND =
"Issue in retrieving device management service instance for device found at %s";
}
+
+ public final class OperationCodes {
+ private OperationCodes() {
+ throw new AssertionError();
+ }
+ public static final String POLICY_REVOKE = "POLICY_REVOKE";
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs
index bbaf402251..c7de8aac7e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs
@@ -86,7 +86,7 @@
{{#if deviceCount}}
-
+
Loading devices . . .
@@ -196,11 +196,11 @@
Loading...
@@ -243,11 +243,11 @@
@@ -289,11 +289,11 @@
@@ -332,7 +332,7 @@
@@ -348,7 +348,7 @@
@@ -365,11 +365,11 @@
@@ -385,7 +385,7 @@
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs
index bcf105493b..fe9663f24f 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs
@@ -48,9 +48,9 @@
+ Add
+ Cancel
@@ -64,7 +64,7 @@
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs
index 6f686d4a5f..7ad04791e1 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs
@@ -106,11 +106,11 @@
@@ -127,11 +127,11 @@
Loading...
@@ -157,11 +157,11 @@
@@ -200,11 +200,11 @@
@@ -229,7 +229,7 @@
Bad Request. Please contact your administrator.
@@ -245,7 +245,7 @@
@@ -261,7 +261,7 @@
@@ -277,7 +277,7 @@
@@ -293,7 +293,7 @@
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
index 8ac28822d9..bec491c017 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
@@ -437,7 +437,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
}
}
str += ' ';
+ + '" ' + isChecked + '/>' + allRoles[i] + '';
}
$('#user-roles').html(str);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js
index 6ac6050de2..19056e28f6 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js
@@ -131,14 +131,14 @@ function loadRoles() {
class: "fade-edge",
data: "name",
render: function (name, type, row, meta) {
- return ' ' + name + ' role
';
+ return '' + name + 'role
';
}
},
{
class: "text-right content-fill text-left-on-grid-view no-wrap",
data: null,
render: function (data, type, row, meta) {
- return ' ' +
+ return '' +
'' +
'' +
'' +
- ' Edit' +
+ 'Edit' +
'' +
- ' ' +
@@ -165,16 +165,16 @@ function loadRoles() {
'' +
'' +
'' +
- ' Edit Permission' +
+ 'Edit Permission' +
'' +
- ' ' +
'' +
'' +
'' +
'' +
- ' Remove' +
+ 'Remove' +
'';
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.details/details.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.details/details.hbs
index 5d64021462..ae0ec631b8 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.details/details.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.details/details.hbs
@@ -20,7 +20,7 @@
-
+
Loading Device Details . . .
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js
index ea45adaf37..269f503a52 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/public/js/listing.js
@@ -148,7 +148,7 @@ function loadDevices(searchType, searchParam){
'' +
' ' +
- ' Quick Startup Guide');
+ 'Quick Startup Guide');
}
$(".icon .text").res_text(0.2);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.hbs
index 5a9a302a77..1252ce7565 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.hbs
@@ -98,9 +98,9 @@
-
+
-
+
Loading Policies . . .
@@ -129,9 +129,9 @@
-
+
-
+
Loading Policy Compliance . . .
@@ -168,9 +168,9 @@
-
+
-
+
Loading Operations Log . . .
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs
index b9b97f1822..c960d9e158 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs
@@ -138,12 +138,12 @@
@@ -220,9 +220,9 @@
-
+
- Loading platform features . . .
+ Loading platform features . . .
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs
index 1b99826718..e03d228846 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs
@@ -19,7 +19,7 @@
- Policy List by priority order
+ Policy List by priority order
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs
index 60ac43c41e..8d8e73dbb1 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs
@@ -53,7 +53,7 @@
- Change password
+ Change password
@@ -100,7 +100,7 @@
- Password has been successfully updated
+ Password has been successfully updated
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs
index aa18aaf814..3a700a0713 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.modal/modal.hbs
@@ -17,7 +17,6 @@
}}
{{#zone "content"}}
-
-
-
{{/zone}}
{{#zone "topJs"}}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java
index 81ccf0eca4..96d7aac4d2 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java
@@ -77,5 +77,5 @@ public interface PolicyManagerService {
ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
- boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
+ boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java
index a3079fcb4c..da127b70a9 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java
@@ -201,7 +201,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
}
@Override
- public boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
- return monitoringManager.isCompliance(deviceIdentifier);
+ public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
+ return monitoringManager.isCompliant(deviceIdentifier);
}
}
\ No newline at end of file
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java
index 9a7eab1c6d..dea10f5fac 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java
@@ -64,32 +64,33 @@ public class DelegationTask implements Task {
if (!deviceTypes.isEmpty()) {
DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance()
.getDeviceManagementService();
- List
devices = new ArrayList<>();
+ List devices;
+ List toBeNotified;
for (String deviceType : deviceTypes) {
try {
+ devices = new ArrayList<>();
+ toBeNotified = new ArrayList<>();
devices.addAll(service.getAllDevices(deviceType));
+ //HashMap deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
+ for (Device device : devices) {
+ // if (deviceIdPolicy.containsKey(device.getId())) {
+ toBeNotified.add(device);
+ // }
+ }
+ if (!toBeNotified.isEmpty()) {
+ PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
+ enforcementDelegator.delegate();
+ }
} catch (DeviceManagementException e) {
- throw new PolicyManagementException("Error occurred while taking the devices", e);
+ throw new PolicyManagementException("Error occurred while fetching the devices", e);
+ } catch (PolicyDelegationException e) {
+ throw new PolicyManagementException("Error occurred while running the delegation task on " +
+ "device-type : " + deviceType, e);
}
}
-// HashMap deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
- List toBeNotified = new ArrayList<>();
-
- for (Device device : devices) {
-// if (deviceIdPolicy.containsKey(device.getId())) {
- toBeNotified.add(device);
-// }
- }
- if (!toBeNotified.isEmpty()) {
- PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
- enforcementDelegator.delegate();
- }
}
-
} catch (PolicyManagementException e) {
log.error("Error occurred while getting the policies applied to devices.", e);
- } catch (PolicyDelegationException e) {
- log.error("Error occurred while running the delegation task.", e);
}
}
}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java
index 218fe0398e..e782308c06 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegator.java
@@ -31,4 +31,6 @@ public interface PolicyEnforcementDelegator {
void addPolicyOperation(List deviceIdentifiers, Policy policy) throws PolicyDelegationException;
+ void addPolicyRevokeOperation(List deviceIdentifiers) throws PolicyDelegationException;
+
}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java
index 4e2051e8b1..90f7acd875 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java
@@ -23,14 +23,18 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
+import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
+import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
+import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.util.ArrayList;
@@ -58,7 +62,6 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
@Override
public void delegate() throws PolicyDelegationException {
-
for (Device device : devices) {
DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setId(device.getDeviceIdentifier());
@@ -70,14 +73,17 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
List deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(identifier);
this.addPolicyOperation(deviceIdentifiers, policy);
+ } else {
+ //This means all the applicable policies have been removed. Hence sending policy-revoke operation.
+ List deviceIdentifiers = new ArrayList<>();
+ deviceIdentifiers.add(identifier);
+ this.addPolicyRevokeOperation(deviceIdentifiers);
}
-
}
}
@Override
public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException {
-
try {
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl();
return policyManagerService.getPEP().getEffectivePolicy(identifier);
@@ -96,11 +102,13 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
@Override
public void addPolicyOperation(List deviceIdentifiers, Policy policy) throws
PolicyDelegationException {
-
try {
- //ToDo Need to fix this to fetch OSGi service
- OperationManager operationManager = new OperationManagerImpl();
- operationManager.addOperation(PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers);
+ String type = null;
+ if (deviceIdentifiers.size() > 0) {
+ type = deviceIdentifiers.get(0).getType();
+ }
+ PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
+ PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers);
} catch (InvalidDeviceException e) {
String msg = "Invalid DeviceIdentifiers found.";
log.error(msg, e);
@@ -110,7 +118,33 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
log.error(msg, e);
throw new PolicyDelegationException(msg, e);
}
+ }
+ @Override
+ public void addPolicyRevokeOperation(List deviceIdentifiers) throws PolicyDelegationException {
+ try {
+ String type = null;
+ if (deviceIdentifiers.size() > 0) {
+ type = deviceIdentifiers.get(0).getType();
+ }
+ PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
+ this.getPolicyRevokeOperation(), deviceIdentifiers);
+ } catch (InvalidDeviceException e) {
+ String msg = "Invalid DeviceIdentifiers found.";
+ log.error(msg, e);
+ throw new PolicyDelegationException(msg, e);
+ } catch (OperationManagementException e) {
+ String msg = "Error occurred while adding the operation to device.";
+ log.error(msg, e);
+ throw new PolicyDelegationException(msg, e);
+ }
}
+ private Operation getPolicyRevokeOperation() {
+ CommandOperation policyRevokeOperation = new CommandOperation();
+ policyRevokeOperation.setEnabled(true);
+ policyRevokeOperation.setCode(OperationMgtConstants.OperationCodes.POLICY_REVOKE);
+ policyRevokeOperation.setType(Operation.Type.COMMAND);
+ return policyRevokeOperation;
+ }
}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java
index b96e8f1cd7..1f82cb780b 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java
@@ -114,7 +114,13 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@Override
public boolean deletePolicy(int policyId) throws PolicyManagementException {
boolean bool =policyManager.deletePolicy(policyId);
- PolicyCacheManagerImpl.getInstance().rePopulateCache();
+ PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance();
+ policyCacheManager.rePopulateCache();
+ List appliedPolicies = policyCacheManager.getAllPolicies();
+ //This means all the policies have been deleted. Hence triggering publishChanges to take immediate effect.
+ if (appliedPolicies.isEmpty()) {
+ this.publishChanges();
+ }
return bool;
}
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java
index 2b6e7d5eae..3eb809d2ae 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java
@@ -33,7 +33,7 @@ public interface MonitoringManager {
throws PolicyComplianceException;
- boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
+ boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
index 71da91c839..58783e97fb 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
+++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java
@@ -171,7 +171,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
}
@Override
- public boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
+ public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try {
DeviceManagementProviderService service =
PolicyManagementDataHolder.getInstance().getDeviceManagementService();