revert-70aa11f8
thusithakalugamage 8 years ago
commit 308eeb6cf8

@ -334,6 +334,16 @@ public interface DeviceDAO {
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
int tenantId) throws DeviceManagementDAOException; 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. * This method is used to retrieve current active enrollment of a given device and tenant id.
* *

@ -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 @Override
public EnrolmentInfo getActiveEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException { public EnrolmentInfo getActiveEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;

@ -927,6 +927,13 @@ public class OperationManagerImpl implements OperationManager {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
String user = this.getUser(); String user = this.getUser();
enrolmentInfo = deviceDAO.getEnrolment(deviceId, user, tenantId); 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) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" + throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getType() + "' device carrying the identifier '" +
@ -934,6 +941,10 @@ public class OperationManagerImpl implements OperationManager {
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "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 { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }

@ -29,4 +29,11 @@ public class OperationMgtConstants {
public static final String DEVICE_ID_SERVICE_NOT_FOUND = public static final String DEVICE_ID_SERVICE_NOT_FOUND =
"Issue in retrieving device management service instance for device found at %s"; "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";
}
} }

@ -86,7 +86,7 @@
{{#if deviceCount}} {{#if deviceCount}}
<div id="loading-content" class="col-centered"> <div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading devices . . . Loading devices . . .
<br> <br>
</div> </div>
@ -196,11 +196,11 @@
<div id="user-groups">Loading...</div> <div id="user-groups">Loading...</div>
<div class="buttons"> <div class="buttons">
<a href="#" id="group-device-yes-link" class="btn-operations"> <a href="#" id="group-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Assign&nbsp;&nbsp;&nbsp;&nbsp; Assign
</a> </a>
&nbsp;&nbsp;
<a href="#" id="group-device-cancel-link" class="btn-operations btn-default"> <a href="#" id="group-device-cancel-link" class="btn-operations btn-default">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -243,11 +243,11 @@
<div class="modal-footer"> <div class="modal-footer">
<div class="buttons"> <div class="buttons">
<a href="#" id="remove-device-yes-link" class="btn-operations"> <a href="#" id="remove-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp; Yes
</a> </a>
&nbsp;&nbsp;
<a href="#" id="remove-device-cancel-link" class="btn-operations"> <a href="#" id="remove-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -289,11 +289,11 @@
<div class="modal-footer"> <div class="modal-footer">
<div class="buttons"> <div class="buttons">
<a href="#" id="edit-device-yes-link" class="btn-operations"> <a href="#" id="edit-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Rename&nbsp;&nbsp;&nbsp;&nbsp; Rename
</a> </a>
&nbsp;&nbsp;
<a href="#" id="edit-device-cancel-link" class="btn-operations"> <a href="#" id="edit-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -332,7 +332,7 @@
<br /> <br />
<div class="buttons"> <div class="buttons">
<a href="#" id="device-400-link" class="btn-operations"> <a href="#" id="device-400-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>
@ -348,7 +348,7 @@
<br /> <br />
<div class="buttons"> <div class="buttons">
<a href="#" id="device-403-link" class="btn-operations"> <a href="#" id="device-403-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>
@ -365,11 +365,11 @@
<br /> <br />
<div class="buttons"> <div class="buttons">
<a href="{{@app.context}}/group/add" class="btn-operations"> <a href="{{@app.context}}/group/add" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Add New Group&nbsp;&nbsp;&nbsp;&nbsp; Add New Group
</a> </a>
&nbsp;&nbsp;
<a href="#" id="cancel-link" class="btn-operations"> <a href="#" id="cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -385,7 +385,7 @@
<br /> <br />
<div class="buttons"> <div class="buttons">
<a href="#" id="remove-device-409-link" class="btn-operations"> <a href="#" id="remove-device-409-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>

@ -48,9 +48,9 @@
<div class="wr-input-control"> <div class="wr-input-control">
<button class="wr-btn" id="add-group-btn"> <button class="wr-btn" id="add-group-btn">
&nbsp;&nbsp;&nbsp;&nbsp;Add&nbsp;&nbsp;&nbsp;&nbsp;</button> Add</button>
<button class="wr-btn" onclick="window.location = '{{@app.context}}/groups';return false;"> <button class="wr-btn" onclick="window.location = '{{@app.context}}/groups';return false;">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;</button> Cancel</button>
</div> </div>
</div> </div>
</div> </div>
@ -64,7 +64,7 @@
<br/> <br/>
<div class="buttons"> <div class="buttons">
<a href="#" id="group-unexpected-error-link" class="btn-operations"> <a href="#" id="group-unexpected-error-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>

@ -106,11 +106,11 @@
</div> </div>
<div class="buttons"> <div class="buttons">
<a href="#" id="share-group-next-link" class="btn-operations"> <a href="#" id="share-group-next-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Next&nbsp;&nbsp;&nbsp;&nbsp; Next
</a> </a>
&nbsp;&nbsp;
<a href="#" id="share-group-w1-cancel-link" class="btn-operations btn-default"> <a href="#" id="share-group-w1-cancel-link" class="btn-operations btn-default">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -127,11 +127,11 @@
<div id="user-roles">Loading...</div> <div id="user-roles">Loading...</div>
<div class="buttons"> <div class="buttons">
<a href="#" id="share-group-yes-link" class="btn-operations"> <a href="#" id="share-group-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;&nbsp; OK
</a> </a>
&nbsp;&nbsp;
<a href="#" id="share-group-w2-cancel-link" class="btn-operations btn-default"> <a href="#" id="share-group-w2-cancel-link" class="btn-operations btn-default">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -157,11 +157,11 @@
<div class="buttons"> <div class="buttons">
<a href="#" id="remove-group-yes-link" class="btn-operations"> <a href="#" id="remove-group-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp; Yes
</a> </a>
&nbsp;&nbsp;
<a href="#" id="remove-group-cancel-link" class="btn-operations btn-default"> <a href="#" id="remove-group-cancel-link" class="btn-operations btn-default">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -200,11 +200,11 @@
</div> </div>
<div class="buttons"> <div class="buttons">
<a href="#" id="edit-group-yes-link" class="btn-operations"> <a href="#" id="edit-group-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Update&nbsp;&nbsp;&nbsp;&nbsp; Update
</a> </a>
&nbsp;&nbsp;
<a href="#" id="edit-group-cancel-link" class="btn-operations btn-default"> <a href="#" id="edit-group-cancel-link" class="btn-operations btn-default">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp; Cancel
</a> </a>
</div> </div>
</div> </div>
@ -229,7 +229,7 @@
<h3 id="error-msg">Bad Request. Please contact your administrator.</h3> <h3 id="error-msg">Bad Request. Please contact your administrator.</h3>
<div class="buttons"> <div class="buttons">
<a href="#" id="group-400-link" class="btn-operations"> <a href="#" id="group-400-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>
@ -245,7 +245,7 @@
<div class="buttons"> <div class="buttons">
<a href="#" id="group-403-link" class="btn-operations"> <a href="#" id="group-403-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>
@ -261,7 +261,7 @@
<div class="buttons"> <div class="buttons">
<a href="#" id="group-404-link" class="btn-operations"> <a href="#" id="group-404-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>
@ -277,7 +277,7 @@
<div class="buttons"> <div class="buttons">
<a href="#" id="group-409-link" class="btn-operations"> <a href="#" id="group-409-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>
@ -293,7 +293,7 @@
<div class="buttons"> <div class="buttons">
<a href="#" id="group-unexpected-error-link" class="btn-operations"> <a href="#" id="group-unexpected-error-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp; Ok
</a> </a>
</div> </div>
</div> </div>

@ -437,7 +437,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
} }
} }
str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + allRoles[i] + '" value="' + allRoles[i] str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + allRoles[i] + '" value="' + allRoles[i]
+ '" ' + isChecked + '/>' + allRoles[i] + '</label>&nbsp;&nbsp;&nbsp;&nbsp;'; + '" ' + isChecked + '/>' + allRoles[i] + '</label>';
} }
$('#user-roles').html(str); $('#user-roles').html(str);

@ -131,14 +131,14 @@ function loadRoles() {
class: "fade-edge", class: "fade-edge",
data: "name", data: "name",
render: function (name, type, row, meta) { render: function (name, type, row, meta) {
return '<h4>&nbsp;&nbsp;' + name + '&nbsp;role</h4>'; return '<h4>' + name + 'role</h4>';
} }
}, },
{ {
class: "text-right content-fill text-left-on-grid-view no-wrap", class: "text-right content-fill text-left-on-grid-view no-wrap",
data: null, data: null,
render: function (data, type, row, meta) { render: function (data, type, row, meta) {
return '&nbsp;' + return '' +
'<a onclick="javascript:loadRoleBasedActionURL(\'edit\', \'' + data.name + '\')" ' + '<a onclick="javascript:loadRoleBasedActionURL(\'edit\', \'' + data.name + '\')" ' +
'data-role="' + data.name + '" ' + 'data-role="' + data.name + '" ' +
'data-click-event="edit-form" ' + 'data-click-event="edit-form" ' +
@ -151,9 +151,9 @@ function loadRoles() {
'<i class="fw fw-circle fw-stack-2x"></i><i class="fw fw-edit fw-stack-1x fw-inverse"></i>' + '<i class="fw fw-circle fw-stack-2x"></i><i class="fw fw-edit fw-stack-1x fw-inverse"></i>' +
'</span>' + '</span>' +
'</span>' + '</span>' +
'<span class="hidden-xs hidden-on-grid-view">&nbsp;&nbsp;Edit</span>' + '<span class="hidden-xs hidden-on-grid-view">Edit</span>' +
'</a>' + '</a>' +
'&nbsp;<a onclick="javascript:loadRoleBasedActionURL(\'edit-permission\', \'' + data.name + '\')" ' + '<a onclick="javascript:loadRoleBasedActionURL(\'edit-permission\', \'' + data.name + '\')" ' +
'data-role="' + data.name + '" ' + 'data-role="' + data.name + '" ' +
'data-click-event="edit-form" ' + 'data-click-event="edit-form" ' +
'class="btn padding-reduce-on-grid-view edit-permission-link">' + 'class="btn padding-reduce-on-grid-view edit-permission-link">' +
@ -165,16 +165,16 @@ function loadRoles() {
'<i class="fw fw-circle fw-stack-2x"></i><i class="fw fw-edit fw-stack-1x fw-inverse"></i>' + '<i class="fw fw-circle fw-stack-2x"></i><i class="fw fw-edit fw-stack-1x fw-inverse"></i>' +
'</span>' + '</span>' +
'</span>' + '</span>' +
'<span class="hidden-xs hidden-on-grid-view">&nbsp;&nbsp;Edit Permission</span>' + '<span class="hidden-xs hidden-on-grid-view">Edit Permission</span>' +
'</a>' + '</a>' +
'&nbsp;<a data-role="' + data.name + '" ' + '<a data-role="' + data.name + '" ' +
'data-click-event="remove-form" ' + 'data-click-event="remove-form" ' +
'class="btn padding-reduce-on-grid-view remove-role-link">' + 'class="btn padding-reduce-on-grid-view remove-role-link">' +
'<span class="fw-stack">' + '<span class="fw-stack">' +
'<i class="fw fw-ring fw-stack-2x"></i>' + '<i class="fw fw-ring fw-stack-2x"></i>' +
'<i class="fw fw-delete fw-stack-1x"></i>' + '<i class="fw fw-delete fw-stack-1x"></i>' +
'</span>' + '</span>' +
'<span class="hidden-xs hidden-on-grid-view">&nbsp;&nbsp;Remove</span>' + '<span class="hidden-xs hidden-on-grid-view">Remove</span>' +
'</a>'; '</a>';
} }
} }

@ -20,7 +20,7 @@
<br> <br>
<br> <br>
<i class="fw fw-settings fw-spin fw-2x"></i> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Device Details . . . Loading Device Details . . .
<br> <br>
</div> </div>

@ -148,7 +148,7 @@ function loadDevices(searchType, searchParam){
'<a href="https://docs.wso2.com/display/IoTS100/Quick+Start+Guide" target="_blank" ' + '<a href="https://docs.wso2.com/display/IoTS100/Quick+Start+Guide" target="_blank" ' +
'class="btn-operations btn-default"><span class="fw-stack">' + 'class="btn-operations btn-default"><span class="fw-stack">' +
'<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-document fw-stack-1x"></i></span>' + '<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-document fw-stack-1x"></i></span>' +
'&nbsp;&nbsp;Quick Startup Guide</a></div>'); 'Quick Startup Guide</a></div>');
} }
$(".icon .text").res_text(0.2); $(".icon .text").res_text(0.2);

@ -98,9 +98,9 @@
<div class="panel-body"> <div class="panel-body">
<div id="policy-spinner" class="wr-advance-operations-init hidden"> <div id="policy-spinner" class="wr-advance-operations-init hidden">
<br> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policies . . . Loading Policies . . .
<br> <br>
<br> <br>
@ -129,9 +129,9 @@
<div id="policy-spinner" <div id="policy-spinner"
class="wr-advance-operations-init hidden"> class="wr-advance-operations-init hidden">
<br> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policy Compliance . . . Loading Policy Compliance . . .
<br> <br>
<br> <br>
@ -168,9 +168,9 @@
<div id="operations-spinner" <div id="operations-spinner"
class="wr-advance-operations-init hidden"> class="wr-advance-operations-init hidden">
<br> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Operations Log . . . Loading Operations Log . . .
<br> <br>
<br> <br>

@ -138,12 +138,12 @@
<label class="wr-input-control radio light"> <label class="wr-input-control radio light">
<input id="user-roles-radio-btn" type="radio" name="select-users-radio-btn" <input id="user-roles-radio-btn" type="radio" name="select-users-radio-btn"
class="select-users-radio" checked/> class="select-users-radio" checked/>
<span class="helper">&nbsp;Set user role(s)</span> <span class="helper">Set user role(s)</span>
</label> </label>
<label class="wr-input-control radio light" rel="assetfilter"> <label class="wr-input-control radio light" rel="assetfilter">
<input id="users-radio-btn" type="radio" name="select-users-radio-btn" <input id="users-radio-btn" type="radio" name="select-users-radio-btn"
class="select-users-radio"/> class="select-users-radio"/>
<span class="helper">&nbsp;Set user(s)</span> <span class="helper">Set user(s)</span>
</label> </label>
</div> </div>
<div id="user-roles-select-field" class="select-users"> <div id="user-roles-select-field" class="select-users">
@ -220,9 +220,9 @@
<div class="wr-advance-operations"> <div class="wr-advance-operations">
<div class="wr-advance-operations-init"> <div class="wr-advance-operations-init">
<br> <br>
&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;Loading platform features . . . Loading platform features . . .
<br> <br>
<br> <br>
</div> </div>

@ -19,7 +19,7 @@
<div class="row wr-device-board"> <div class="row wr-device-board">
<div class="col-lg-12 wr-secondary-bar"> <div class="col-lg-12 wr-secondary-bar">
<span class="page-sub-title"> <span class="page-sub-title">
&nbsp;Policy List by priority order Policy List by priority order
</span> </span>
</div> </div>
<div class="row"> <div class="row">

@ -53,7 +53,7 @@
<i class="fw fw-edit fw-stack-1x fw-inverse"></i> <i class="fw fw-edit fw-stack-1x fw-inverse"></i>
</span> </span>
</span> </span>
&nbsp;&nbsp;Change password Change password
</h4> </h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
class="fw fw-cancel"></i></button> class="fw fw-cancel"></i></button>
@ -100,7 +100,7 @@
<i class="fw fw-circle fw-stack-2x fw-stroke text-success"></i> <i class="fw fw-circle fw-stack-2x fw-stroke text-success"></i>
<i class="fw fw-check fw-stack-1x fw-inverse"></i> <i class="fw fw-check fw-stack-1x fw-inverse"></i>
</span> </span>
&nbsp;&nbsp;Password has been successfully updated Password has been successfully updated
</h4> </h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
class="fw fw-cancel"></i></button> class="fw fw-cancel"></i></button>

@ -17,7 +17,6 @@
}} }}
{{#zone "content"}} {{#zone "content"}}
<div id="basic-modal-view" class="hidden modal modal-content"> <div id="basic-modal-view" class="hidden modal modal-content">
<div class="modal-header"> <div class="modal-header">
<h3 class="pull-left modal-title"> <h3 class="pull-left modal-title">
@ -42,8 +41,6 @@
<div id="modal-footer-content" class="modal-footer"> <div id="modal-footer-content" class="modal-footer">
</div> </div>
</div> </div>
{{/zone}} {{/zone}}
{{#zone "topJs"}} {{#zone "topJs"}}

@ -77,5 +77,5 @@ public interface PolicyManagerService {
ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
} }

@ -201,7 +201,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
} }
@Override @Override
public boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
return monitoringManager.isCompliance(deviceIdentifier); return monitoringManager.isCompliant(deviceIdentifier);
} }
} }

@ -64,32 +64,33 @@ public class DelegationTask implements Task {
if (!deviceTypes.isEmpty()) { if (!deviceTypes.isEmpty()) {
DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance() DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance()
.getDeviceManagementService(); .getDeviceManagementService();
List<Device> devices = new ArrayList<>(); List<Device> devices;
List<Device> toBeNotified;
for (String deviceType : deviceTypes) { for (String deviceType : deviceTypes) {
try { try {
devices = new ArrayList<>();
toBeNotified = new ArrayList<>();
devices.addAll(service.getAllDevices(deviceType)); devices.addAll(service.getAllDevices(deviceType));
} catch (DeviceManagementException e) { //HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
throw new PolicyManagementException("Error occurred while taking the devices", e);
}
}
// HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
List<Device> toBeNotified = new ArrayList<>();
for (Device device : devices) { for (Device device : devices) {
// if (deviceIdPolicy.containsKey(device.getId())) { // if (deviceIdPolicy.containsKey(device.getId())) {
toBeNotified.add(device); toBeNotified.add(device);
// } // }
} }
if (!toBeNotified.isEmpty()) { if (!toBeNotified.isEmpty()) {
PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified); PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
enforcementDelegator.delegate(); enforcementDelegator.delegate();
} }
} catch (DeviceManagementException 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);
}
}
} }
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
log.error("Error occurred while getting the policies applied to devices.", 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);
} }
} }
} }

@ -31,4 +31,6 @@ public interface PolicyEnforcementDelegator {
void addPolicyOperation(List<DeviceIdentifier> deviceIdentifiers, Policy policy) throws PolicyDelegationException; void addPolicyOperation(List<DeviceIdentifier> deviceIdentifiers, Policy policy) throws PolicyDelegationException;
void addPolicyRevokeOperation(List<DeviceIdentifier> deviceIdentifiers) throws PolicyDelegationException;
} }

@ -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.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; 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.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; 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.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.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl; 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 org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -58,7 +62,6 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
@Override @Override
public void delegate() throws PolicyDelegationException { public void delegate() throws PolicyDelegationException {
for (Device device : devices) { for (Device device : devices) {
DeviceIdentifier identifier = new DeviceIdentifier(); DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setId(device.getDeviceIdentifier()); identifier.setId(device.getDeviceIdentifier());
@ -70,14 +73,17 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(identifier); deviceIdentifiers.add(identifier);
this.addPolicyOperation(deviceIdentifiers, policy); this.addPolicyOperation(deviceIdentifiers, policy);
} else {
//This means all the applicable policies have been removed. Hence sending policy-revoke operation.
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(identifier);
this.addPolicyRevokeOperation(deviceIdentifiers);
} }
} }
} }
@Override @Override
public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException { public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException {
try { try {
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl(); PolicyManagerService policyManagerService = new PolicyManagerServiceImpl();
return policyManagerService.getPEP().getEffectivePolicy(identifier); return policyManagerService.getPEP().getEffectivePolicy(identifier);
@ -96,11 +102,13 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
@Override @Override
public void addPolicyOperation(List<DeviceIdentifier> deviceIdentifiers, Policy policy) throws public void addPolicyOperation(List<DeviceIdentifier> deviceIdentifiers, Policy policy) throws
PolicyDelegationException { PolicyDelegationException {
try { try {
//ToDo Need to fix this to fetch OSGi service String type = null;
OperationManager operationManager = new OperationManagerImpl(); if (deviceIdentifiers.size() > 0) {
operationManager.addOperation(PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers); type = deviceIdentifiers.get(0).getType();
}
PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type,
PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers);
} catch (InvalidDeviceException e) { } catch (InvalidDeviceException e) {
String msg = "Invalid DeviceIdentifiers found."; String msg = "Invalid DeviceIdentifiers found.";
log.error(msg, e); log.error(msg, e);
@ -110,7 +118,33 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
log.error(msg, e); log.error(msg, e);
throw new PolicyDelegationException(msg, e); throw new PolicyDelegationException(msg, e);
} }
}
@Override
public void addPolicyRevokeOperation(List<DeviceIdentifier> 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;
}
} }

@ -114,7 +114,13 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@Override @Override
public boolean deletePolicy(int policyId) throws PolicyManagementException { public boolean deletePolicy(int policyId) throws PolicyManagementException {
boolean bool =policyManager.deletePolicy(policyId); boolean bool =policyManager.deletePolicy(policyId);
PolicyCacheManagerImpl.getInstance().rePopulateCache(); PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance();
policyCacheManager.rePopulateCache();
List<Policy> 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; return bool;
} }

@ -33,7 +33,7 @@ public interface MonitoringManager {
throws PolicyComplianceException; throws PolicyComplianceException;
boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;

@ -171,7 +171,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
} }
@Override @Override
public boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
try { try {
DeviceManagementProviderService service = DeviceManagementProviderService service =
PolicyManagementDataHolder.getInstance().getDeviceManagementService(); PolicyManagementDataHolder.getInstance().getDeviceManagementService();

Loading…
Cancel
Save