From 295921b2897929ed7b6bd420b1e363a6023b7df2 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 3 Jan 2017 11:35:08 +0530 Subject: [PATCH 01/10] Fixed following issues: https://wso2.org/jira/browse/IOTS-218 https://wso2.org/jira/browse/IOTS-236 https://wso2.org/jira/browse/IOTS-263 https://wso2.org/jira/browse/IOTS-173 --- .../jaxrs/beans/DeviceToGroupsAssignment.java | 56 ++++++ .../service/api/GroupManagementService.java | 112 ++++++++++++ .../impl/GroupManagementServiceImpl.java | 47 ++++- .../app/pages/cdmf.page.devices/devices.hbs | 12 +- .../cdmf.page.devices/public/js/listing.js | 165 +++++++++++------- .../listing.hbs | 56 ++++-- .../cdmf.unit.device.types.listing/listing.js | 3 + .../public/js/listing.js | 7 - 8 files changed, 359 insertions(+), 99 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/DeviceToGroupsAssignment.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/DeviceToGroupsAssignment.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/DeviceToGroupsAssignment.java new file mode 100644 index 0000000000..ef696f0c27 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/DeviceToGroupsAssignment.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.jaxrs.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.jaxrs.beans.BasePaginatedResult; + +import java.util.ArrayList; +import java.util.List; + +public class DeviceToGroupsAssignment extends BasePaginatedResult { + + @ApiModelProperty(value = "List of device group ids.") + @JsonProperty("deviceGroupIds") + private List deviceGroupIds = new ArrayList<>(); + + @ApiModelProperty(value = "Device identifier of the device needed to be assigned with group") + @JsonProperty("deviceIdentifier") + private DeviceIdentifier deviceIdentifier; + + + public List getDeviceGroupIds() { + return deviceGroupIds; + } + + public void setDeviceGroupIds(List deviceGroupIds) { + this.deviceGroupIds = deviceGroupIds; + } + + public DeviceIdentifier getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index a982a3c3d5..9d1b255e96 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -37,6 +37,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; +import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceToGroupsAssignment; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; @@ -774,4 +775,115 @@ public interface GroupManagementService { required = true) @Valid List deviceIdentifiers); + @Path("/device/assign") + @POST + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_POST, + value = "Assign devices to groups", + notes = "Add existing device to device groups.", + tags = "Device Group Management", + authorizations = { + @Authorization( + value = "permission", + scopes = {@AuthorizationScope(scope = "/device-mgt/groups/devices/add", + description = "Add devices")} + ) + } + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK. \n Successfully assign the device to groups.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of " + + "the requested resource."), + @ApiResponse( + code = 404, + message = "No groups found.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while adding devices to the group.", + response = ErrorResponse.class) + }) + Response updateDeviceAssigningToGroups( + @ApiParam( + name = "deviceToGroupsAssignment", + value = "Device to groups assignment", + required = true) + @Valid DeviceToGroupsAssignment deviceToGroupsAssignment); + + @Path("/device") + @GET + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_GET, + value = "List of groups that have the device", + notes = "List of groups that have the device.", + tags = "Device Group Management", + authorizations = { + @Authorization( + value = "permission", + scopes = {@AuthorizationScope(scope = "/device-mgt/groups/devices/view", + description = "Add devices")} + ) + } + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of " + + "the requested resource."), + @ApiResponse( + code = 404, + message = "No groups found.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred.", + response = ErrorResponse.class) + }) + Response getGroups( + @ApiParam( + name = "deviceId", + value = "Id of the device.") + @QueryParam("deviceId") String deviceId, + @ApiParam( + name = "deviceType", + value = "Type of the device.") + @QueryParam("deviceType") String deviceType); + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java index 4d7f4319fa..4811e9b902 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; @@ -35,12 +36,14 @@ import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; +import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceToGroupsAssignment; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.core.Response; +import java.util.ArrayList; import java.util.List; public class GroupManagementServiceImpl implements GroupManagementService { @@ -243,7 +246,8 @@ public class GroupManagementServiceImpl implements GroupManagementService { } } - @Override public Response removeDevicesFromGroup(int groupId, List deviceIdentifiers) { + @Override + public Response removeDevicesFromGroup(int groupId, List deviceIdentifiers) { try { DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(groupId, deviceIdentifiers); return Response.status(Response.Status.OK).build(); @@ -256,4 +260,45 @@ public class GroupManagementServiceImpl implements GroupManagementService { } } + @Override + public Response updateDeviceAssigningToGroups(DeviceToGroupsAssignment deviceToGroupsAssignment) { + try { + List deviceIdentifiers = new ArrayList<>(); + deviceIdentifiers.add(deviceToGroupsAssignment.getDeviceIdentifier()); + GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService(); + List deviceGroups = service.getGroups(deviceToGroupsAssignment.getDeviceIdentifier()); + for (DeviceGroup group : deviceGroups) { + Integer groupId = group.getGroupId(); + if (deviceToGroupsAssignment.getDeviceGroupIds().contains(groupId)) { + deviceToGroupsAssignment.getDeviceGroupIds().remove(groupId); + } else if (!CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(group.getOwner())) { + DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(groupId, deviceIdentifiers); + } + } + for (int groupId : deviceToGroupsAssignment.getDeviceGroupIds()) { + DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers); + } + return Response.status(Response.Status.OK).build(); + } catch (GroupManagementException e) { + String msg = "Error occurred while assigning device to groups."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (DeviceNotFoundException e) { + return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); + } + } + + @Override + public Response getGroups(String deviceId, String deviceType) { + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType); + List deviceGroups = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroups(deviceIdentifier); + return Response.status(Response.Status.OK).entity(deviceGroups).build(); + } catch (GroupManagementException e) { + String msg = "Error occurred while removing devices from group."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + } 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 2b50aa21c3..863c85842f 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 @@ -233,17 +233,7 @@ - - -
- diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index 9121f1d3a9..d5457db01f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -261,7 +261,7 @@ function loadDevices(searchType, searchParam) { return '
'; + row.deviceType) + '"/>
'; } }, { @@ -347,31 +347,31 @@ function loadDevices(searchType, searchParam) { if ((!groupName || !groupId) && groupingEnabled(row.deviceType)) { html += - '' + - '' + - ''; + '' + + '' + + ''; } html += - '' + - '' + - '' + - ''; + '' + + '' + + '' + + ''; html += - '' + - '' + - '' + - ''; + '' + + '' + + '' + + ''; } return html; } @@ -427,16 +427,16 @@ function loadDevices(searchType, searchParam) { $(data.devices).each(function (index) { objects.push( - { - model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"), - vendor: getPropertyValue(data.devices[index].properties, "VENDOR"), - user: data.devices[index].enrolmentInfo.owner, - status: data.devices[index].enrolmentInfo.status, - ownership: data.devices[index].enrolmentInfo.ownership, - deviceType: data.devices[index].type, - deviceIdentifier: data.devices[index].deviceIdentifier, - name: data.devices[index].name - } + { + model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"), + vendor: getPropertyValue(data.devices[index].properties, "VENDOR"), + user: data.devices[index].enrolmentInfo.owner, + status: data.devices[index].enrolmentInfo.status, + ownership: data.devices[index].enrolmentInfo.ownership, + deviceType: data.devices[index].type, + deviceIdentifier: data.devices[index].deviceIdentifier, + name: data.devices[index].name + } ); }); @@ -449,20 +449,20 @@ function loadDevices(searchType, searchParam) { }; $('#device-grid').datatables_extended_serverside_paging( - null, - serviceURL, - dataFilter, - columns, - fnCreatedRow, - function () { - $(".icon .text").res_text(0.2); - $('#device-grid').removeClass('hidden'); - $("#loading-content").remove(); - attachDeviceEvents(); - }, { - "placeholder": "Search By Device Name", - "searchKey": "name" - } + null, + serviceURL, + dataFilter, + columns, + fnCreatedRow, + function () { + $(".icon .text").res_text(0.2); + $('#device-grid').removeClass('hidden'); + $("#loading-content").remove(); + attachDeviceEvents(); + }, { + "placeholder": "Search By Device Name", + "searchKey": "name" + } ); $(deviceCheckbox).click(function () { @@ -556,6 +556,34 @@ function hidePopup() { $('.modal-backdrop').remove(); } +function markAlreadyAssignedGroups(deviceId, deviceType) { + var successCallback = function (data, textStatus, xhr) { + data = JSON.parse(data); + if (xhr.status == 200) { + if (data.length > 0) { + for (var i = 0; i < data.length; i++) { + $('.groupCheckBoxes').each( + function () { + if (data[i].id == $(this).data('groupid')) { + $(this).attr('checked', true); + } + } + ); + } + } else { + return; + } + } else { + displayErrors(xhr); + } + }; + + invokerUtil.get("/api/device-mgt/v1.0/groups/device?deviceId=" + deviceId + "&deviceType=" + deviceType, + successCallback, function (message) { + displayErrors(message); + }); +} + /** * Following functions should be triggered after AJAX request is made. */ @@ -572,33 +600,48 @@ function attachDeviceEvents() { var deviceType = $(this).data("devicetype"); $(modalPopupContent).html($('#group-device-modal-content').html()); $('#user-groups').html( - '
'); + '
'); $("a#group-device-yes-link").hide(); showPopup(); var serviceURL; if ($.hasPermission("LIST_ALL_GROUPS")) { - serviceURL = "/api/device-mgt/v1.0/groups"; + serviceURL = "/api/device-mgt/v1.0/admin/groups?limit=100"; } else if ($.hasPermission("LIST_GROUPS")) { //Get authenticated users groups - serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all"; + serviceURL = "/api/device-mgt/v1.0/groups?limit=100"; } invokerUtil.get(serviceURL, function (data) { var groups = JSON.parse(data); - var str = '
' + + '' + groups.deviceGroups[i].name + + ''; + } } - str += ''; - $('#user-groups').html(str); + $('#user-groups').html(html); + markAlreadyAssignedGroups(deviceId, deviceType); $("a#group-device-yes-link").show(); $("a#group-device-yes-link").click(function () { - var selectedGroup = $('#assign-group-selector').val(); - serviceURL = "/api/device-mgt/v1.0/groups/id/" + selectedGroup + "/devices/add"; - var deviceIdentifiers = [{"id": deviceId, "type": deviceType}]; - invokerUtil.post(serviceURL, deviceIdentifiers, function (data) { + var deviceIdentifier = {"id": deviceId, "type": deviceType}; + var deviceGroupIds = []; + $('.modal .groupCheckBoxes').each( + function () { + if ($(this).is(':checked')) { + deviceGroupIds.push($(this).data('groupid')); + } + } + ); + var deviceToGroupsAssignment = { + deviceIdentifier: deviceIdentifier, + deviceGroupIds: deviceGroupIds + }; + serviceURL = "/api/device-mgt/v1.0/groups/device/assign"; + invokerUtil.post(serviceURL, deviceToGroupsAssignment, function (data) { $(modalPopupContent).html($('#group-associate-device-200-content').html()); setTimeout(function () { hidePopup(); @@ -640,8 +683,8 @@ function attachDeviceEvents() { showPopup(); $("a#remove-device-yes-link").click(function () { - if(groupId && groupName) { - var deviceIdentifiers = [{"id": deviceId,"type": deviceType}]; + if (groupId && groupName) { + var deviceIdentifiers = [{"id": deviceId, "type": deviceType}]; serviceURL = "/api/device-mgt/v1.0/groups/id/" + groupId + "/devices/remove"; invokerUtil.post(serviceURL, deviceIdentifiers, function (message) { $(modalPopupContent).html($('#remove-device-from-group-200-content').html()); @@ -733,6 +776,6 @@ function displayDeviceErrors(jqXHR) { function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), - results = regex.exec(location.search); + results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.hbs index 08ab1c8095..5069d083d4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.hbs @@ -16,26 +16,44 @@ under the License. }} -
-
- Device Types +{{#if virtualDeviceTypesList}} +
+
+ Device Types +
-
- -
- - - - - - - - - - -
By Device Type
-
+
+ + + + + + + + + + +
By Device Type
+
+{{else}} +
+{{/if}}
{{#if virtualDeviceTypesList}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js index 62ca011b0b..1e1cefcb83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js @@ -29,6 +29,9 @@ function onRequest(context) { if (typesListResponse["status"] == "success") { var deviceTypes = typesListResponse.content.deviceTypes; if (deviceTypes) { + if (deviceTypes.length > 0){ + viewModel.hasDeviceTypes = true; + } var deviceTypesList = [], virtualDeviceTypesList = []; for (var i = 0; i < deviceTypes.length; i++) { var deviceType = deviceTypes[i]; 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 1fbbe479c2..ba9a4be94a 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 @@ -142,13 +142,6 @@ function loadDevices(searchType, searchParam){ } } else { $('#device-type-grid').addClass('hidden'); - $('#device-listing-status-msg').html( - '

' + - '

No device type is available to be displayed.

' + - '' + - ' ' + - 'Quick Startup Guide
'); } $(".icon .text").res_text(0.2); From f6f99ed06a5f69909599eb0e22851629c1396724 Mon Sep 17 00:00:00 2001 From: charitha Date: Wed, 4 Jan 2017 15:09:36 +0530 Subject: [PATCH 02/10] Fixed following issues: https://wso2.org/jira/browse/IOTS-271 --- .../app/modules/business-controllers/group.js | 29 ++++++ .../pages/cdmf.page.dashboard/dashboard.hbs | 2 +- .../app/pages/cdmf.page.devices/devices.hbs | 83 +++++++++++++--- .../app/pages/cdmf.page.devices/devices.js | 15 +-- .../cdmf.page.devices/public/js/listing.js | 27 ++++-- .../cdmf.page.group.analytics/analytics.hbs | 2 +- .../cdmf.page.group.analytics/analytics.js | 7 +- .../cdmf.page.group.analytics/analytics.json | 2 +- .../cdmf.page.groups/public/js/listing.js | 96 ++++++++++++------- 9 files changed, 192 insertions(+), 71 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js index fefd73bd0b..de20da586d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js @@ -105,4 +105,33 @@ var groupModule = {}; ); }; + groupModule.getGroup = function (groupId) { + return serviceInvokers.XMLHttp.get( + deviceServiceEndpoint + "/groups/id/" + groupId, function (responsePayload) { + return JSON.parse(responsePayload.responseText); + }, + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + + groupModule.getRolesOfGroup = function (groupId) { + return serviceInvokers.XMLHttp.get( + deviceServiceEndpoint + "/groups/id/" + groupId + "/roles", function (responsePayload) { + var data = JSON.parse(responsePayload.responseText); + if(data) { + return data.roles; + } else { + return []; + } + }, + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + }(groupModule)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs index 6b466d90a3..a294732b26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs @@ -171,7 +171,7 @@ {{/if}} - + 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 863c85842f..8a32659700 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 @@ -26,7 +26,7 @@ - {{#if groupName}} + {{#if group}}
  • Groups @@ -34,7 +34,7 @@
  • - {{groupName}} + {{group.name}}
  • {{else}} @@ -47,7 +47,7 @@ {{/zone}} {{#zone "navbarActions"}} - {{#if groupName}} + {{#if group}}
  • @@ -57,6 +57,15 @@ Assign from My Devices
  • +
  • + + + + + + View Analytics + +
  • {{else}} {{#if permissions.enroll}}
  • @@ -73,6 +82,55 @@ {{/zone}} {{#zone "content"}} + {{#if group}} +

    + {{group.name}} group +

    +
    +
    +
    +
    +
    + +
    +
    +
    +
    + Overview +
    + + + + + + + + + + + + + + + + + + + +
    Owner{{group.owner}}
    Shared with roles + {{#each roles}} + {{this}}
    + {{/each}} +
    Device Count{{deviceCount}}
    Description{{group.description}}
    +
    +
    +
    +
    +
    +

    + Devices in {{group.name}} group +

    + {{/if}}
    @@ -82,7 +140,6 @@ {{#if deviceCount}}
    - Loading devices . . .
    @@ -157,7 +214,7 @@

    You don't have any device - {{#if groupName}} + {{#if group}} assigned to this group {{else}} enrolled @@ -165,7 +222,7 @@ at the moment.

    - {{#if groupName}} + {{#if group}} @@ -208,20 +265,16 @@ -
    -

    - Please select group -
    -
    Loading...
    -

    -
    +
    Loading...

  • - + {{groupName}}
  • diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js index 19f783ed56..6a34a26b0c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js @@ -19,8 +19,8 @@ function onRequest(context) { var utility = require("/app/modules/utility.js").utility; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; - var groupName = context.uriParams.name; var groupId = context.uriParams.id; + var group = groupModule.getGroup(groupId); var devices = []; var deviceResponse = groupModule.getGroupDevices(groupId).responseText; @@ -29,8 +29,9 @@ function onRequest(context) { devices = deviceResponseObj.devices; } var page = { - "groupName": groupName, - "title": groupName + " Analytics" + "groupId": groupId, + "groupName": group.name, + "title": group.name + " Analytics" }; if (devices) { var deviceTypes = []; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json index 2e2fea333e..8535dab982 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json @@ -1,5 +1,5 @@ { "version": "1.0.0", - "uri": "/group/{name}/{id}/analytics", + "uri": "/group/{id}/analytics", "layout": "cdmf.layout.default" } \ No newline at end of file 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 4597a71297..6661e775b4 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 @@ -16,18 +16,41 @@ * under the License. */ +/** + * Following function would execute + * when a user clicks on the list item + * initial mode and with out select mode. + */ +function InitiateViewOption(url) { + if ($(".select-enable-btn").text() == "Select") { + $(location).attr('href', url); + } +} + +(function () { + var cache = {}; + var validateAndReturn = function (value) { + return (value == undefined || value == null) ? "Unspecified" : value; + }; + Handlebars.registerHelper("deviceMap", function (device) { + device.owner = validateAndReturn(device.owner); + device.ownership = validateAndReturn(device.ownership); + var arr = device.properties; + if (arr) { + device.properties = arr.reduce(function (total, current) { + total[current.name] = validateAndReturn(current.value); + return total; + }, {}); + } + }); +})(); + /* * Setting-up global variables. */ var groupCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var assetContainer = "#ast-container"; -function InitiateViewOption() { - if ($(".select-enable-btn").text() == "Select") { - $(location).attr('href', $(this).data("url")); - } -} - /* * On Select All Groups button click function. * @@ -118,9 +141,9 @@ function loadGroups() { }); var json = { "recordsTotal": data.count, + "recordsFiltered": data.count, "data": objects - } - + }; return JSON.stringify(json); }; @@ -129,7 +152,14 @@ function loadGroups() { data: 'id', class: 'remove-padding icon-only content-fill', render: function (data, type, row, meta) { - return '
    '; + if ($.hasPermission("VIEW_GROUP_DEVICES")) { + return '
    '; + } else { + return '
    '; + } } }, { @@ -154,13 +184,7 @@ function loadGroups() { render: function (id, type, row, meta) { var html = ''; if ($.hasPermission("VIEW_GROUP_DEVICES")) { - html = '' + - '' - + - ''; - - html += '' + '' + @@ -224,21 +248,23 @@ function loadGroups() { }); }; - $('#group-grid').datatables_extended_serverside_paging( - null, - serviceURL, - dataFilter, - columns, - fnCreatedRow, - function (oSettings) { - $(".icon .text").res_text(0.2); - attachEvents(); - }, - { - "placeholder": "Search By Group Name", - "searchKey": "name" - }); + null, + serviceURL, + dataFilter, + columns, + fnCreatedRow, + function (oSettings) { + $(".icon .text").res_text(0.2); + attachEvents(); + var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + thisTable.removeClass("table-selectable"); + }, + { + "placeholder": "Search By Group Name", + "searchKey": "name" + } + ); $(groupCheckbox).click(function () { addGroupSelectedClass(this); }); @@ -257,6 +283,11 @@ function openCollapsedNav() { * DOM ready functions. */ $(document).ready(function () { + /* Adding selected class for selected devices */ + $(groupCheckbox).each(function () { + addGroupSelectedClass(this); + }); + var permissionSet = {}; //This method is used to setup permission for device listing @@ -278,11 +309,6 @@ $(document).ready(function () { loadGroups(); //$('#device-grid').datatables_extended(); - /* Adding selected class for selected devices */ - $(groupCheckbox).each(function () { - addGroupSelectedClass(this); - }); - /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover( { From c4a2ba0cead693b49d072bcd9536f4518d410009 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Wed, 4 Jan 2017 16:54:46 +0530 Subject: [PATCH 03/10] adding http api publisher for Android agent to work out of the box --- .../wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java index 6d1bc7695b..99b625504b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java @@ -280,7 +280,7 @@ public class APIPublisherUtil { log.debug("'managed-api-transports' attribute is not configured. Therefore using the default, " + "which is 'https'"); } - transports = "https"; + transports = "https,http"; } apiConfig.setTransports(transports); From e5062abcc2f6d17846c9e2024023fb3802ad4371 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 4 Jan 2017 00:18:28 +0530 Subject: [PATCH 04/10] Removed unneccesary configs --- .../jaggeryapps/devicemgt/app/conf/config.json | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index 6c11194110..b74f3d4518 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -1,7 +1,5 @@ { "appContext": "/devicemgt/", - "webAgentContext" : "/emm-web-agent/", - "apiContext": "api", "httpsURL" : "%https.ip%", "httpURL" : "%http.ip%", "httpsWebURL" : "%https.ip%", @@ -33,17 +31,6 @@ "adminUserTenantId":"-1234", "adminRole":"admin", "usernameLength":30, - "pageSize":10, - "ssoConfiguration" : { - "enabled" : false, - "issuer" : "devicemgt", - "appName" : "devicemgt", - "identityProviderURL" : "%https.ip%/sso/samlsso.jag", - "responseSigningEnabled" : "true", - "keyStorePassword" : "wso2carbon", - "identityAlias" : "wso2carbon", - "keyStoreName" : "/repository/resources/security/wso2carbon.jks" - }, "userValidationConfig" : { "usernameJSRegEx" : "^[\\S]{3,30}$", "usernameRegExViolationErrorMsg" : "Provided username is invalid.", From 2a7e62f857b8768933daa5b5b3943df8baad3764 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 4 Jan 2017 22:15:01 +0530 Subject: [PATCH 05/10] config.json [apimgt-gateway] renamed to [gatewayEnabled] --- .../main/resources/jaggeryapps/devicemgt/app/conf/config.json | 2 +- .../jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index b74f3d4518..d0a421755a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -13,7 +13,7 @@ "iOSConfigRoot" : "%https.ip%/ios-enrollment/", "iOSAPIRoot" : "%https.ip%/ios/", "adminService": "%https.ip%", - "apimgt-gateway": false, + "gatewayEnabled": false, "oauthProvider": { "appRegistration": { "appType": "webapp", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js index 9c969f4ab1..d9d51101c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js @@ -138,7 +138,7 @@ var handlers = function () { "client credentials to session context. No username of logged in user is found as " + "input - setUpEncodedTenantBasedClientAppCredentials(x)"); } else { - if (devicemgtProps["apimgt-gateway"]) { + if (devicemgtProps["gatewayEnabled"]) { var tenantBasedClientAppCredentials = tokenUtil.getTenantBasedClientAppCredentials(username); if (!tenantBasedClientAppCredentials) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant " + @@ -176,7 +176,7 @@ var handlers = function () { "client credentials to session context. No username of logged in user is found as " + "input - setUpEncodedTenantBasedWebSocketClientAppCredentials(x)"); } else { - if (devicemgtProps["apimgt-gateway"]) { + if (devicemgtProps["gatewayEnabled"]) { var tenantBasedWebSocketClientAppCredentials = tokenUtil.getTenantBasedWebSocketClientAppCredentials(username); if (!tenantBasedWebSocketClientAppCredentials) { From 235b41c9df39169741c67738eb25d920c8daebfb Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Wed, 4 Jan 2017 22:28:13 +0530 Subject: [PATCH 06/10] config.json [usernameLength] moved to [userValidationConfig][usernameLength] --- .../main/resources/jaggeryapps/devicemgt/api/user-api.jag | 6 +++--- .../resources/jaggeryapps/devicemgt/app/conf/config.json | 2 +- .../app/pages/cdmf.page.certificate.create/create.js | 2 +- .../devicemgt/app/pages/cdmf.page.user.create/create.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag index 7303a5ee8c..9d12aa9360 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag @@ -121,9 +121,9 @@ if (uriMatcher.match("/{context}/api/user/authenticate")) { } else { userRoles = String(addUserFormData.userRoles).split(","); } - if (username.length < devicemgtProps.usernameLength) { - log.error("Username Must be between 1 and " + devicemgtProps.usernameLength + " characters long"); - result = "Username Must be between 1 and " + devicemgtProps.usernameLength + " characters long"; + if (username.length < devicemgtProps.userValidationConfig.usernameLength) { + log.error("Username Must be between 1 and " + devicemgtProps.userValidationConfig.usernameLength + " characters long"); + result = "Username Must be between 1 and " + devicemgtProps.userValidationConfig.usernameLength + " characters long"; } else { try { result = userModule.addUser(username, firstname, lastname, emailAddress, userRoles); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index d0a421755a..e9e1d99ce6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -30,8 +30,8 @@ "adminUser":"admin@carbon.super", "adminUserTenantId":"-1234", "adminRole":"admin", - "usernameLength":30, "userValidationConfig" : { + "usernameLength":30, "usernameJSRegEx" : "^[\\S]{3,30}$", "usernameRegExViolationErrorMsg" : "Provided username is invalid.", "usernameHelpMsg" : "Should be in minimum 3 characters long and do not include any whitespaces.", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificate.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificate.create/create.js index 6099b8a845..32f427090a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificate.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificate.create/create.js @@ -33,7 +33,7 @@ function onRequest(context) { viewModel["roles"] = response["content"]; } - viewModel["charLimit"] = mdmProps["usernameLength"]; + viewModel["charLimit"] = mdmProps["userValidationConfig"]["usernameLength"]; viewModel["usernameJSRegEx"] = mdmProps["userValidationConfig"]["usernameJSRegEx"]; viewModel["usernameHelpText"] = mdmProps["userValidationConfig"]["usernameHelpMsg"]; viewModel["usernameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["usernameRegExViolationErrorMsg"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js index e1c4b583bd..a05bcc6e7f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js @@ -40,7 +40,7 @@ function onRequest() { } var userStores = userModule.getSecondaryUserStores(); page["userStores"] = userStores; - page["charLimit"] = devicemgtProps["usernameLength"]; + page["charLimit"] = devicemgtProps["userValidationConfig"]["usernameLength"]; page["usernameJSRegEx"] = devicemgtProps["userValidationConfig"]["usernameJSRegEx"]; page["usernameHelpMsg"] = devicemgtProps["userValidationConfig"]["usernameHelpMsg"]; page["usernameRegExViolationErrorMsg"] = devicemgtProps["userValidationConfig"]["usernameRegExViolationErrorMsg"]; From 0fb5a577b87681931b148aed7c8dbefe8975f666 Mon Sep 17 00:00:00 2001 From: Maninda Date: Thu, 5 Jan 2017 11:47:09 +0530 Subject: [PATCH 07/10] Fixed some issues found in FindBugs security analysis. --- .../extension/api/filter/ApiPermissionFilter.java | 2 +- .../mgt/jaxrs/api/common/GsonMessageBodyHandler.java | 6 +----- .../mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java | 6 +----- .../device/mgt/jaxrs/common/GsonMessageBodyHandler.java | 6 +----- .../carbon/device/mgt/common/device/details/DeviceInfo.java | 2 +- .../device/mgt/common/device/details/DeviceLocation.java | 2 +- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java index bc7dab7053..9c1dfac4bd 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/filter/ApiPermissionFilter.java @@ -119,7 +119,7 @@ public class ApiPermissionFilter implements Filter { .getThreadLocalCarbonContext().getTenantId()); return userRealm.getAuthorizationManager().isUserAuthorized(username, permission, action); } catch (UserStoreException e) { - String errorMsg = String.format("Unable to authorize the user : %s", username, e); + String errorMsg = String.format("Unable to authorize the user : %s", username); log.error(errorMsg, e); return false; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java index 9cd6c3190a..91b3283e68 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/src/main/java/org/wso2/carbon/certificate/mgt/jaxrs/api/common/GsonMessageBodyHandler.java @@ -83,11 +83,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); try { - Type jsonType = null; - if (type.equals(type)) { - jsonType = type; - } - getGson().toJson(object, jsonType, writer); + getGson().toJson(object, type, writer); } finally { writer.close(); } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java index 6abb296c17..7ca13eb59f 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/common/GsonMessageBodyHandler.java @@ -83,11 +83,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); try { - Type jsonType = null; - if (type.equals(type)) { - jsonType = type; - } - getGson().toJson(object, jsonType, writer); + getGson().toJson(object, type, writer); } finally { writer.close(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java index f069edee75..a25fb84833 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/common/GsonMessageBodyHandler.java @@ -83,11 +83,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); try { - Type jsonType = null; - if (type.equals(type)) { - jsonType = type; - } - getGson().toJson(object, jsonType, writer); + getGson().toJson(object, type, writer); } finally { writer.close(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java index 343add988e..b7f5a5b14c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java @@ -370,7 +370,7 @@ public class DeviceInfo implements Serializable { } public Date getUpdatedTime() { - if(updatedTime.equals(null)){ + if(updatedTime == null){ updatedTime = new Date(); } return updatedTime; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java index 5223b0f047..f1107091b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java @@ -137,7 +137,7 @@ public class DeviceLocation implements Serializable { } public Date getUpdatedTime() { - if(updatedTime.equals(null)){ + if(updatedTime == null ){ updatedTime = new Date(); } return updatedTime; From 00a5a07373773ee1443b40bfaf1c98b0334313e1 Mon Sep 17 00:00:00 2001 From: Maninda Date: Thu, 5 Jan 2017 14:28:30 +0530 Subject: [PATCH 08/10] Fixed some security issues found after running FindBugs security scan. --- .../mgt/common/push/notification/NotificationContext.java | 4 ++++ .../framework/authenticator/JWTAuthenticator.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationContext.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationContext.java index 546e4fcf29..617525c579 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationContext.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/push/notification/NotificationContext.java @@ -48,6 +48,10 @@ public class NotificationContext { return properties; } + public void setProperties(Map propertiesMap) { + properties = propertiesMap; + } + public Operation getOperation() { return operation; } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java index 9184682d3a..b269f7c285 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java @@ -90,6 +90,9 @@ public class JWTAuthenticator implements WebappAuthenticator { if (requestUri == null || "".equals(requestUri)) { authenticationInfo.setStatus(Status.CONTINUE); } + if (requestUri == null) { + requestUri = ""; + } StringTokenizer tokenizer = new StringTokenizer(requestUri, "/"); String context = tokenizer.nextToken(); if (context == null || "".equals(context)) { From 0a6ef8daf7bfba026d8866826eee6bd7ac86786f Mon Sep 17 00:00:00 2001 From: Maninda Date: Thu, 5 Jan 2017 14:51:13 +0530 Subject: [PATCH 09/10] Added some security fixes for issues reported by FindBugs --- .../pom.xml | 1 + .../device/type/deployer/util/DeviceTypeConfigUtil.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index df0314173c..b50459eb15 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -91,6 +91,7 @@ javax.naming, javax.sql, + javax.xml, javax.xml.bind, javax.xml.bind.annotation, javax.xml.parsers; version="${javax.xml.parsers.import.pkg.version}", diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java index bdf3bd861e..495a72b48d 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java @@ -21,8 +21,10 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util; import org.w3c.dom.Document; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException; +import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import java.io.File; /** @@ -34,8 +36,12 @@ public class DeviceTypeConfigUtil { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + return null; } catch (Exception e) { throw new DeviceTypeConfigurationException("Error occurred while parsing file, while converting " + "to a org.w3c.dom.Document", e); From 25a35dcf20fda16371b15a1291384d8fb11a7d2d Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 5 Jan 2017 16:43:48 +0530 Subject: [PATCH 10/10] Changing title [WSO2 IoT] into [WSO2 IoT Server] --- .../devicemgt/app/units/cdmf.unit.ui.header.logo/logo.hbs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.logo/logo.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.logo/logo.hbs index ae5febf40f..070ed3088a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.logo/logo.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.logo/logo.hbs @@ -15,4 +15,5 @@ specific language governing permissions and limitations under the License. }} -{{#zone "productName"}}WSO2 IoT{{/zone}} \ No newline at end of file +{{#zone "productName"}}WSO2 IoT Server{{/zone}} +{{#zone "productNameResponsive"}}WSO2 IoT Server{{/zone}} \ No newline at end of file