|
|
@ -307,14 +307,14 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
throws OperationManagementException {
|
|
|
|
throws OperationManagementException {
|
|
|
|
PaginationResult paginationResult = null;
|
|
|
|
PaginationResult paginationResult = null;
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
|
|
|
|
String owner = request.getOwner();
|
|
|
|
if (!isActionAuthorized(deviceId)) {
|
|
|
|
if (!isActionAuthorized(deviceId)) {
|
|
|
|
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
|
|
|
|
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
|
|
|
|
deviceId.getType() + "' device, which carries the identifier '" +
|
|
|
|
deviceId.getType() + "' device, which carries the identifier '" +
|
|
|
|
deviceId.getId() + "'");
|
|
|
|
deviceId.getId() + "' of owner '" + owner + "'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId);
|
|
|
|
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId, owner);
|
|
|
|
if (enrolmentInfo == null) {
|
|
|
|
if (enrolmentInfo == null) {
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
"Identifier:" + deviceId.getId() + " and given type" +
|
|
|
|
"Identifier:" + deviceId.getId() + " and given type" +
|
|
|
@ -923,31 +923,33 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
return enrolmentId;
|
|
|
|
return enrolmentId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private EnrolmentInfo getEnrolmentInfo(DeviceIdentifier deviceId) throws OperationManagementException {
|
|
|
|
private EnrolmentInfo getEnrolmentInfo(DeviceIdentifier deviceId, String owner) throws OperationManagementException {
|
|
|
|
EnrolmentInfo enrolmentInfo;
|
|
|
|
EnrolmentInfo enrolmentInfo = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
String user = this.getUser();
|
|
|
|
String user = this.getUser();
|
|
|
|
enrolmentInfo = deviceDAO.getEnrolment(deviceId, user, tenantId);
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
if (enrolmentInfo == null) {
|
|
|
|
if (this.isSameUser(user, owner)) {
|
|
|
|
|
|
|
|
enrolmentInfo = deviceDAO.getEnrolment(deviceId, owner, tenantId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
boolean isAdminUser = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
boolean isAdminUser = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
isDeviceAdminUser();
|
|
|
|
isDeviceAdminUser();
|
|
|
|
if (isAdminUser) {
|
|
|
|
if (isAdminUser) {
|
|
|
|
enrolmentInfo = deviceDAO.getEnrolment(deviceId, tenantId);
|
|
|
|
enrolmentInfo = deviceDAO.getEnrolment(deviceId, owner, tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO : Add a check for group admin if this fails
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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 '" +
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
deviceId.getId() + "' of owner '" + owner + "'", e);
|
|
|
|
} 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) {
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
throw new OperationManagementException("Error occurred while checking the device access permissions for '" +
|
|
|
|
throw new OperationManagementException("Error occurred while checking the device access permissions for '" +
|
|
|
|
deviceId.getType() + "' device carrying the identifier '" +
|
|
|
|
deviceId.getType() + "' device carrying the identifier '" +
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
deviceId.getId() + "' of owner '" + owner + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1021,4 +1023,8 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isSameUser(String user, String owner) {
|
|
|
|
|
|
|
|
return user.equalsIgnoreCase(owner);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|