diff --git a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.cdmf.analytics/pom.xml b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.cdmf.analytics/pom.xml index 4ee294a12..f10f81b9f 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.cdmf.analytics/pom.xml +++ b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.cdmf.analytics/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt-plugins iot-analytics - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml index 4c50a5411..e5ffd7f03 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml +++ b/components/analytics/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt-plugins iot-analytics - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/analytics/iot-analytics/org.wso2.carbon.iot.device.statistics.dashboard/pom.xml b/components/analytics/iot-analytics/org.wso2.carbon.iot.device.statistics.dashboard/pom.xml index 4c0a8b64c..dde4dd550 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.iot.device.statistics.dashboard/pom.xml +++ b/components/analytics/iot-analytics/org.wso2.carbon.iot.device.statistics.dashboard/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt-plugins iot-analytics - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/pom.xml b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/pom.xml index c9000bce6..d4862c812 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/pom.xml +++ b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt-plugins iot-analytics - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/analytics/iot-analytics/pom.xml b/components/analytics/iot-analytics/pom.xml index 50552e32d..6d923429d 100644 --- a/components/analytics/iot-analytics/pom.xml +++ b/components/analytics/iot-analytics/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins analytics - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/analytics/pom.xml b/components/analytics/pom.xml index e10d73010..3b4c4d9d2 100644 --- a/components/analytics/pom.xml +++ b/components/analytics/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins carbon-device-mgt-plugins-parent - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml index 902b425bf..b9285404d 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/pom.xml @@ -21,7 +21,7 @@ androidsense-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml index 8279ef9c7..da85955b0 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml @@ -3,7 +3,7 @@ androidsense-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml index 9fd2ec148..46dfd7ade 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/pom.xml @@ -22,7 +22,7 @@ androidsense-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.realtime.analytics-view/public/js/device-stats.js b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.realtime.analytics-view/public/js/device-stats.js index 8ef8638ad..4b92faf6c 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.realtime.analytics-view/public/js/device-stats.js +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.realtime.analytics-view/public/js/device-stats.js @@ -75,6 +75,7 @@ var rotation_yData = []; var rotation_zData = []; var graphMap = {}; +var graphSettingsMap = {}; var palette = new Rickshaw.Color.Palette({scheme: "munin"}); @@ -83,21 +84,21 @@ var elemTop; $(window).load(function () { graphMap["battery"]=lineGraph("battery", batteryData); - graphMap["light"]=lineGraph("light", lightData); - graphMap["pressure"]=lineGraph("pressure", pressureData); - graphMap["proximity"]=lineGraph("proximity", proximityData); - graphMap["accelerometer"]=threeDlineGraph("accelerometer", accelerometer_xData, accelerometer_yData, accelerometer_zData); - graphMap["magnetic"]=threeDlineGraph("magnetic", magnetic_xData, magnetic_yData, magnetic_zData); - graphMap["gyroscope"]=threeDlineGraph("gyroscope", gyroscope_xData, gyroscope_yData, gyroscope_zData); - graphMap["gravity"]=threeDlineGraph("gravity", gravity_xData, gravity_yData, gravity_zData); - graphMap["rotation"]=threeDlineGraph("rotation", rotation_xData, rotation_yData, rotation_zData); - - var websocketUrl = $("#stat-section").data("websocketurl"); + graphMap["light"]=lineGraph("light", lightData); + graphMap["pressure"]=lineGraph("pressure", pressureData); + graphMap["proximity"]=lineGraph("proximity", proximityData); + graphMap["accelerometer"]=threeDlineGraph("accelerometer", accelerometer_xData, accelerometer_yData, accelerometer_zData); + graphMap["magnetic"]=threeDlineGraph("magnetic", magnetic_xData, magnetic_yData, magnetic_zData); + graphMap["gyroscope"]=threeDlineGraph("gyroscope", gyroscope_xData, gyroscope_yData, gyroscope_zData); + graphMap["gravity"]=threeDlineGraph("gravity", gravity_xData, gravity_yData, gravity_zData); + graphMap["rotation"]=threeDlineGraph("rotation", rotation_xData, rotation_yData, rotation_zData); + + var websocketUrl = $("#stat-section").data("websocketurl"); connect(websocketUrl) }); window.onbeforeunload = function() { - disconnect(); + disconnect(); }; function threeDlineGraph(type, xChartData, yChartData, zChartData) { @@ -121,10 +122,10 @@ function threeDlineGraph(type, xChartData, yChartData, zChartData) { var graph = new Rickshaw.Graph({ element: $elem[0], - width: $elem.width() - 100, + width: $elem.width() - 100, height: 300, renderer: "line", - interpolation: "linear", + interpolation: "linear", padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2}, xScale: d3.time.scale(), series: [ @@ -140,26 +141,26 @@ function threeDlineGraph(type, xChartData, yChartData, zChartData) { xAxis.render(); - new Rickshaw.Graph.Axis.Y({ - graph: graph, - orientation: 'left', - height: 300, - tickFormat: Rickshaw.Fixtures.Number.formatKMBT, - element: document.getElementById("y-axis-"+type) - }); + new Rickshaw.Graph.Axis.Y({ + graph: graph, + orientation: 'left', + height: 300, + tickFormat: Rickshaw.Fixtures.Number.formatKMBT, + element: document.getElementById("y-axis-"+type) + }); new Rickshaw.Graph.Legend({ graph: graph, element: document.getElementById('legend-' + type) - }); + }); var detail = new Rickshaw.Graph.HoverDetail({ graph: graph }); - graph.render(); + graph.render(); - return graph; + return graph; } function lineGraph(type, chartData) { @@ -171,15 +172,15 @@ function lineGraph(type, chartData) { }); } - var $elem = $("#chart-" + type); + var $elem = $("#chart-" + type); - var graph = new Rickshaw.Graph({ - element: $elem[0], - width: $elem.width() - 100, + var graph = new Rickshaw.Graph({ + element: $elem[0], + width: $elem.width() - 100, height: 300, renderer: "line", - interpolation: "linear", - padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2}, + interpolation: "linear", + padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2}, xScale: d3.time.scale(), series: [{ 'color': palette.color(), @@ -205,7 +206,7 @@ function lineGraph(type, chartData) { new Rickshaw.Graph.Legend({ graph: graph, element: document.getElementById('legend-' + type) - }); + }); new Rickshaw.Graph.HoverDetail({ graph: graph, @@ -216,9 +217,9 @@ function lineGraph(type, chartData) { } }); - graph.render(); + graph.render(); - return graph; + return graph; } //websocket connection @@ -231,7 +232,7 @@ function connect(target) { console.log('WebSocket is not supported by this browser.'); } if (ws) { - ws.onmessage = function (event) { + ws.onmessage = function (event) { var dataPoint = JSON.parse(event.data); if (dataPoint) { @@ -242,50 +243,50 @@ function connect(target) { break; case "light": - graphUpdate(lightData, time, dataPoint[lightId], graphMap["light"]); + graphUpdate(lightData, time, dataPoint[lightId], graphMap["light"]); break; case "pressure": - graphUpdate(pressureData, time, dataPoint[pressureId], graphMap["pressure"]); + graphUpdate(pressureData, time, dataPoint[pressureId], graphMap["pressure"]); break; case "proximity": - graphUpdate(proximityData, time, dataPoint[proximityId], graphMap["proximity"]); + graphUpdate(proximityData, time, dataPoint[proximityId], graphMap["proximity"]); break; case "accelerometer": - dataUpdate(accelerometer_xData, time, dataPoint[accelerometer_xId]); + dataUpdate(accelerometer_xData, time, dataPoint[accelerometer_xId]); dataUpdate(accelerometer_yData, time, dataPoint[accelerometer_yId]); dataUpdate(accelerometer_zData, time, dataPoint[accelerometer_zId]); - graphMap["accelerometer"].update(); + graphMap["accelerometer"].update(); break; case "magnetic": - dataUpdate(magnetic_xData, time, dataPoint[magnetic_xId]); + dataUpdate(magnetic_xData, time, dataPoint[magnetic_xId]); dataUpdate(magnetic_yData, time, dataPoint[magnetic_yId]); dataUpdate(magnetic_zData, time, dataPoint[magnetic_zId]); - graphMap["magnetic"].update(); - break; + graphMap["magnetic"].update(); + break; case "gyroscope": - dataUpdate(gyroscope_xData, time, dataPoint[gyroscope_xId]); + dataUpdate(gyroscope_xData, time, dataPoint[gyroscope_xId]); dataUpdate(gyroscope_yData, time, dataPoint[gyroscope_yId]); dataUpdate(gyroscope_zData, time, dataPoint[gyroscope_zId]); - graphMap["gyroscope"].update(); + graphMap["gyroscope"].update(); break; case "rotation": - dataUpdate(magnetic_xData, time, dataPoint[rotation_xId]); + dataUpdate(magnetic_xData, time, dataPoint[rotation_xId]); dataUpdate(magnetic_yData, time, dataPoint[rotation_yId]); dataUpdate(magnetic_zData, time, dataPoint[rotation_zId]); - graphMap["rotation"].update(); + graphMap["rotation"].update(); break; case "gravity": - dataUpdate(gravity_xData, time, dataPoint[gravity_xId]); + dataUpdate(gravity_xData, time, dataPoint[gravity_xId]); dataUpdate(gravity_yData, time, dataPoint[gravity_yId]); dataUpdate(gravity_zData, time, dataPoint[gravity_zId]); - graphMap["gravity"].update(); + graphMap["gravity"].update(); break; } } @@ -318,53 +319,55 @@ function disconnect() { } function maximizeGraph(graph, width,height){ - graph.configure({ - width: width*2, - height: height*2 + graphSettingsMap[graph.element.id] = {'width': graph.width, 'height': graph.height}; + graph.configure({ + width: width*2, + height: height*2 - }); - graph.update(); + }); + graph.update(); } function minimizeGraph(graph){ - graph.configure({ - width: 366, - height: 300 - }); - graph.update(); + var graphSettings = graphSettingsMap[graph.element.id]; + graph.configure({ + width: graphSettings.width, + height: graphSettings.height + }); + graph.update(); } //maximize minimize functionality $(".fw-expand").click(function(e) { - var innerGraph= graphMap[e.target.nextElementSibling.innerHTML]; - var width = $(".chartWrapper").width(); - var height = $(".chartWrapper").height(); - - if($(this).hasClass("default-view")){ - elemTop = $('#'+innerGraph.element.id).parents('.graph')[0].offsetTop; - $(this).removeClass("default-view"); - $(this).removeClass("fw-expand"); - $(this).addClass("fw-contract"); - maximizeGraph(innerGraph,width,height); - $(this).parent().parent().addClass("max"); - $(this).closest(".graph").siblings().addClass("max_hide"); - $(this).closest(".graph").parent().siblings().addClass("max_hide"); - }else{ - $(this).addClass("default-view"); - $(this).addClass("fw-expand"); - $(this).removeClass("fw-contract"); - minimizeGraph(innerGraph); - $(this).parent().parent().removeClass("max"); - $(this).closest(".graph").siblings().removeClass("max_hide"); - $(this).closest(".graph").parent().siblings().removeClass("max_hide"); - focusToArea() - } + var innerGraph= graphMap[e.target.nextElementSibling.innerHTML]; + var width = $(".chartWrapper").width(); + var height = $(".chartWrapper").height(); + + if($(this).hasClass("default-view")){ + elemTop = $('#'+innerGraph.element.id).parents('.graph')[0].offsetTop; + $(this).removeClass("default-view"); + $(this).removeClass("fw-expand"); + $(this).addClass("fw-contract"); + maximizeGraph(innerGraph,width,height); + $(this).parent().parent().addClass("max"); + $(this).closest(".graph").siblings().addClass("max_hide"); + $(this).closest(".graph").parent().siblings().addClass("max_hide"); + }else{ + $(this).addClass("default-view"); + $(this).addClass("fw-expand"); + $(this).removeClass("fw-contract"); + minimizeGraph(innerGraph); + $(this).parent().parent().removeClass("max"); + $(this).closest(".graph").siblings().removeClass("max_hide"); + $(this).closest(".graph").parent().siblings().removeClass("max_hide"); + focusToArea() + } }); //graph focusing function function focusToArea(){ var container = $("body"); - container.animate({ + container.animate({ scrollTop: elemTop - }); + }); } diff --git a/components/device-types/androidsense-plugin/pom.xml b/components/device-types/androidsense-plugin/pom.xml index 300e3ae47..30a1e401d 100644 --- a/components/device-types/androidsense-plugin/pom.xml +++ b/components/device-types/androidsense-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins device-types - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml index d1b953e7d..99ed2b7ce 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/pom.xml @@ -21,7 +21,7 @@ arduino-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml index 369b72f7d..a8ec02a11 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/pom.xml @@ -21,7 +21,7 @@ arduino-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml index 8ffeed67d..1894bdda7 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/pom.xml @@ -23,7 +23,7 @@ arduino-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.realtime.analytics-view/analytics-view.hbs b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.realtime.analytics-view/analytics-view.hbs index 4463eaf8a..be691a2b5 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.realtime.analytics-view/analytics-view.hbs +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.arduino.realtime.analytics-view/analytics-view.hbs @@ -30,10 +30,7 @@ - - - - View Device Analytics + View Device Analytics {{#zone "bottomJs"}} diff --git a/components/device-types/arduino-plugin/pom.xml b/components/device-types/arduino-plugin/pom.xml index 40346ff81..4aae0ea90 100644 --- a/components/device-types/arduino-plugin/pom.xml +++ b/components/device-types/arduino-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins device-types - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/pom.xml b/components/device-types/pom.xml index 3aaaa0a90..a46097a25 100644 --- a/components/device-types/pom.xml +++ b/components/device-types/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins carbon-device-mgt-plugins-parent - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml diff --git a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml index b4e2041c9..75613fd70 100644 --- a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml +++ b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics/pom.xml @@ -21,7 +21,7 @@ raspberrypi-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml index 7d8697a39..ac5270f05 100644 --- a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml +++ b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/pom.xml @@ -21,7 +21,7 @@ raspberrypi-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml index d391627f3..5c8741e75 100644 --- a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml +++ b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/pom.xml @@ -23,7 +23,7 @@ raspberrypi-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.realtime.analytics-view/analytics-view.hbs b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.realtime.analytics-view/analytics-view.hbs index 4463eaf8a..be691a2b5 100644 --- a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.realtime.analytics-view/analytics-view.hbs +++ b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.raspberrypi.realtime.analytics-view/analytics-view.hbs @@ -30,10 +30,7 @@ - - - - View Device Analytics + View Device Analytics {{#zone "bottomJs"}} diff --git a/components/device-types/raspberrypi-plugin/pom.xml b/components/device-types/raspberrypi-plugin/pom.xml index 3288f270d..1b73f5a4e 100644 --- a/components/device-types/raspberrypi-plugin/pom.xml +++ b/components/device-types/raspberrypi-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins device-types - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml index 1f500e0be..01b52ac94 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/pom.xml @@ -23,7 +23,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml index 50253019b..1bb450812 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml @@ -21,7 +21,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml index 92d9451c6..651d600c2 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml @@ -21,7 +21,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml index 14717dba4..5e2f91189 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/pom.xml @@ -23,7 +23,7 @@ virtual-fire-alarm-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.hbs b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.hbs index 3c6c98445..e78ca68b4 100755 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.hbs +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.hbs @@ -30,10 +30,7 @@ - - - - View Device Analytics + View Device Analytics {{#zone "bottomJs"}} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json index 5252c8694..997094474 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.type-view/private/config.json @@ -8,7 +8,23 @@ ], "features": { "buzz": { - "icon" : "fw-dial-up" + "icon" : "fw-dial-up", + "formParams": [ + { + "type": "radio", + "id": "buz_on", + "label": "Buzzer On", + "name": "state", + "value":"ON" + }, + { + "type": "radio", + "id": "buz_off", + "label": "Buzzer Off", + "name": "state", + "value":"OFF" + } + ] } } } diff --git a/components/device-types/virtual-fire-alarm-plugin/pom.xml b/components/device-types/virtual-fire-alarm-plugin/pom.xml index ec2255826..768a6ec16 100644 --- a/components/device-types/virtual-fire-alarm-plugin/pom.xml +++ b/components/device-types/virtual-fire-alarm-plugin/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins device-types - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml index 079df93d9..d658f7973 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml @@ -18,7 +18,7 @@ org.wso2.carbon.devicemgt-plugins appm-connector - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml index 76993f53e..cb104c4ec 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/pom.xml @@ -18,7 +18,7 @@ org.wso2.carbon.devicemgt-plugins appm-connector - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml @@ -67,6 +67,7 @@ feign.gson, org.json.simple.*, org.wso2.carbon.appmgt.mobile.beans, + org.wso2.carbon.base, org.wso2.carbon.context, javax.net.ssl, feign.slf4j diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/ApplicationOperationsImpl.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/ApplicationOperationsImpl.java index a049c3fab..1f5399bca 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/ApplicationOperationsImpl.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/ApplicationOperationsImpl.java @@ -47,17 +47,15 @@ import org.wso2.carbon.appmgt.mobile.mdm.App; import org.wso2.carbon.appmgt.mobile.mdm.Device; import org.wso2.carbon.appmgt.mobile.utils.MobileApplicationException; import org.wso2.carbon.appmgt.mobile.utils.MobileConfigurations; +import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.context.PrivilegedCarbonContext; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -286,16 +284,21 @@ public class ApplicationOperationsImpl implements ApplicationOperations { } } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -318,4 +321,63 @@ public class ApplicationOperationsImpl implements ApplicationOperations { } } + //FIXME - I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + + } \ No newline at end of file diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java index 925f158d5..1ff87e7e6 100755 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.restconnector/src/main/java/org/wso2/carbon/appmgt/mdm/restconnector/authorization/client/OAuthRequestInterceptor.java @@ -40,16 +40,14 @@ import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.ApiRegi import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.TokenIssuerService; import org.wso2.carbon.appmgt.mdm.restconnector.config.AuthorizationConfigurationManager; import org.wso2.carbon.appmgt.mdm.restconnector.internal.AuthorizationDataHolder; +import org.wso2.carbon.base.ServerConfiguration; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; /** * This is a request interceptor to add oauth token header. @@ -131,16 +129,21 @@ public class OAuthRequestInterceptor implements RequestInterceptor { template.header(Constants.RestConstants.AUTHORIZATION, headerValue); } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -163,4 +166,62 @@ public class OAuthRequestInterceptor implements RequestInterceptor { } } + //FIXME - I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + } diff --git a/components/extensions/appm-connector/pom.xml b/components/extensions/appm-connector/pom.xml index 9b1565f19..86d59464b 100644 --- a/components/extensions/appm-connector/pom.xml +++ b/components/extensions/appm-connector/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/pom.xml index 0e9c995c1..60b32a335 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/pom.xml index 09f3d18a6..87c907d78 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml @@ -165,6 +165,7 @@ org.wso2.carbon.identity.oauth2.*, org.wso2.carbon.utils, org.wso2.carbon.utils.multitenancy, + org.wso2.carbon.base, javax.net.ssl, feign.slf4j diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/DeviceAuthorizer.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/DeviceAuthorizer.java index c6e195254..ed6124868 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/DeviceAuthorizer.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/DeviceAuthorizer.java @@ -29,6 +29,7 @@ import feign.jaxrs.JAXRSContract; import feign.slf4j.Slf4jLogger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.OAuthRequestInterceptor; import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.AuthorizationRequest; import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.DeviceAccessAuthorizationAdminService; @@ -38,15 +39,12 @@ import org.wso2.carbon.device.mgt.input.adapter.http.util.AuthenticationInfo; import org.wso2.carbon.device.mgt.input.adapter.http.util.PropertyUtils; import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -112,16 +110,21 @@ public class DeviceAuthorizer { return deviceMgtServerUrl; } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -144,4 +147,62 @@ public class DeviceAuthorizer { } } + //FIXME - I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + } \ No newline at end of file diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/client/OAuthRequestInterceptor.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/client/OAuthRequestInterceptor.java index 35afcd267..e1d87ae14 100755 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/client/OAuthRequestInterceptor.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.http/src/main/java/org/wso2/carbon/device/mgt/input/adapter/http/authorization/client/OAuthRequestInterceptor.java @@ -29,6 +29,7 @@ import feign.jaxrs.JAXRSContract; import feign.slf4j.Slf4jLogger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.AccessTokenInfo; import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.ApiApplicationKey; import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.ApiApplicationRegistrationService; @@ -37,15 +38,12 @@ import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.To import org.wso2.carbon.device.mgt.input.adapter.http.util.PropertyUtils; import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; import java.util.Map; /** @@ -183,16 +181,21 @@ public class OAuthRequestInterceptor implements RequestInterceptor { return refreshTimeOffset; } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -214,4 +217,63 @@ public class OAuthRequestInterceptor implements RequestInterceptor { return null; } } + + //FIXME - I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + } diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/pom.xml index 1d49d99d4..aa538a761 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml index 3c8244e2e..477180121 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.xmpp/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.xmpp/pom.xml index 6411ee193..73c7739b9 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.xmpp/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.xmpp/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/pom.xml b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/pom.xml index cdb0163b4..597957357 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/pom.xml +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/pom.xml b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/pom.xml index cca26dc1a..a3dfb8ebf 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/pom.xml +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/pom.xml b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/pom.xml index e565e5c47..7c7f379d2 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/pom.xml +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/DeviceAuthorizer.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/DeviceAuthorizer.java index 775ea200f..8352e375f 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/DeviceAuthorizer.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/DeviceAuthorizer.java @@ -29,6 +29,7 @@ import feign.jaxrs.JAXRSContract; import feign.slf4j.Slf4jLogger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.device.mgt.output.adapter.websocket.authentication.AuthenticationInfo; import org.wso2.carbon.device.mgt.output.adapter.websocket.authorization.client.OAuthRequestInterceptor; import org.wso2.carbon.device.mgt.output.adapter.websocket.authorization.client.dto.AuthorizationRequest; @@ -40,16 +41,13 @@ import org.wso2.carbon.device.mgt.output.adapter.websocket.util.PropertyUtils; import org.wso2.carbon.device.mgt.output.adapter.websocket.util.WebSocketSessionRequest; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; import javax.websocket.Session; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -125,16 +123,21 @@ public class DeviceAuthorizer implements Authorizer { return deviceMgtServerUrl; } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -156,4 +159,63 @@ public class DeviceAuthorizer implements Authorizer { return null; } } + + //FIXME - I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + } \ No newline at end of file diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/client/OAuthRequestInterceptor.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/client/OAuthRequestInterceptor.java index dedb95371..97219526e 100755 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/client/OAuthRequestInterceptor.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/authorization/client/OAuthRequestInterceptor.java @@ -29,6 +29,7 @@ import feign.jaxrs.JAXRSContract; import feign.slf4j.Slf4jLogger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.device.mgt.output.adapter.websocket.authorization.client.dto.AccessTokenInfo; import org.wso2.carbon.device.mgt.output.adapter.websocket.authorization.client.dto.ApiApplicationKey; import org.wso2.carbon.device.mgt.output.adapter.websocket.authorization.client.dto.ApiApplicationRegistrationService; @@ -37,15 +38,13 @@ import org.wso2.carbon.device.mgt.output.adapter.websocket.authorization.client. import org.wso2.carbon.device.mgt.output.adapter.websocket.util.PropertyUtils; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; + +import javax.net.ssl.*; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; import java.util.Map; /** @@ -185,16 +184,21 @@ public class OAuthRequestInterceptor implements RequestInterceptor { return refreshTimeOffset; } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -217,4 +221,62 @@ public class OAuthRequestInterceptor implements RequestInterceptor { } } + //FIXME - (line 223 - 280 block) I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore, String keyStorePassword, KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + } diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.xmpp/pom.xml b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.xmpp/pom.xml index 0fc220f12..3fac85146 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.xmpp/pom.xml +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.xmpp/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml diff --git a/components/extensions/cdmf-transport-adapters/pom.xml b/components/extensions/cdmf-transport-adapters/pom.xml index cf40fc867..886c0d1a7 100644 --- a/components/extensions/cdmf-transport-adapters/pom.xml +++ b/components/extensions/cdmf-transport-adapters/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml index 142a878c9..a04cdf533 100644 --- a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml +++ b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins mb-extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java index ef79add18..c32ee0055 100644 --- a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java +++ b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java @@ -42,6 +42,7 @@ import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.config.Aut import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.internal.AuthorizationDataHolder; import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.util.AuthorizationCacheKey; import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; @@ -49,15 +50,12 @@ import org.wso2.carbon.user.api.UserStoreException; import javax.cache.Cache; import javax.cache.CacheConfiguration; import javax.cache.Caching; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -258,16 +256,21 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { } } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -290,4 +293,62 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { } } + //FIXME - I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + } \ No newline at end of file diff --git a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/client/OAuthRequestInterceptor.java b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/client/OAuthRequestInterceptor.java index 802adb19e..1cde68b66 100755 --- a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/client/OAuthRequestInterceptor.java +++ b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/client/OAuthRequestInterceptor.java @@ -37,16 +37,14 @@ import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.client.dto import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.client.dto.ApiRegistrationProfile; import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.client.dto.TokenIssuerService; import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.config.AuthorizationConfigurationManager; +import org.wso2.carbon.base.ServerConfiguration; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import javax.net.ssl.*; +import java.io.FileInputStream; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; +import java.io.InputStream; +import java.security.*; +import java.security.cert.CertificateException; /** * This is a request interceptor to add oauth token header. @@ -129,16 +127,21 @@ public class OAuthRequestInterceptor implements RequestInterceptor { tokenIssuerService = null; } - private static Client getSSLClient() { - return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }); + public static Client getSSLClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); + if(isIgnoreHostnameVerification) { + return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }); + }else { + return new Client.Default(getTrustedSSLSocketFactory(), null); + } } - private static SSLSocketFactory getTrustedSSLSocketFactory() { + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @@ -161,4 +164,62 @@ public class OAuthRequestInterceptor implements RequestInterceptor { } } + //FIXME - I know hard-cording values is a bad practice , this code is repeating in + // several class, so this hard-coding strings will be removed once this code block is moved into a central location + // this should be done after the 3.1.0 release. + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + + KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,"JKS"); + KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); + return initSSLConnection(keyStore,keyStorePassword,trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + |CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, + KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance("SSLv3"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + + return loadKeyStore(trustStorePath,tsPassword,"JKS"); + } + } diff --git a/components/extensions/mb-extensions/pom.xml b/components/extensions/mb-extensions/pom.xml index 87fed4aea..7c5426928 100644 --- a/components/extensions/mb-extensions/pom.xml +++ b/components/extensions/mb-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/pom.xml b/components/extensions/pom.xml index 20bfe24df..5a7e07234 100644 --- a/components/extensions/pom.xml +++ b/components/extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins carbon-device-mgt-plugins-parent - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../../pom.xml diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml index 6c96f39e6..59812709c 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins pull-notification-listeners - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/pull-notification-listeners/pom.xml b/components/extensions/pull-notification-listeners/pom.xml index d5e450eb7..c2a4ef4a8 100644 --- a/components/extensions/pull-notification-listeners/pom.xml +++ b/components/extensions/pull-notification-listeners/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.execution.json/pom.xml b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.execution.json/pom.xml index 9e25d0374..ee463c842 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.execution.json/pom.xml +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.execution.json/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins siddhi-extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/siddhi-extensions/org.wso2.gpl.siddhi.extension.geo.script/pom.xml b/components/extensions/siddhi-extensions/org.wso2.gpl.siddhi.extension.geo.script/pom.xml index 44338827d..24c1a8b1a 100644 --- a/components/extensions/siddhi-extensions/org.wso2.gpl.siddhi.extension.geo.script/pom.xml +++ b/components/extensions/siddhi-extensions/org.wso2.gpl.siddhi.extension.geo.script/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt-plugins siddhi-extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/extensions/siddhi-extensions/pom.xml b/components/extensions/siddhi-extensions/pom.xml index fd71147c5..0afff7d44 100644 --- a/components/extensions/siddhi-extensions/pom.xml +++ b/components/extensions/siddhi-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins extensions - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml index 0a6bfa4de..4a5c167a4 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/pom.xml @@ -21,7 +21,7 @@ android-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/pom.xml index 0e0864b96..9b56f10f0 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/pom.xml @@ -21,7 +21,7 @@ android-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml index 48b0043f4..0116df0b7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/pom.xml @@ -23,13 +23,13 @@ android-plugin org.wso2.carbon.devicemgt-plugins - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.mobile.android.ui - 4.0.18-SNAPSHOT + 4.0.29-SNAPSHOT WSO2 Carbon - Mobile Android UI pom diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk index ea20c879f..772d2f3ee 100644 Binary files a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk and b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk differ diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js index ef84b0c0f..76b097605 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js @@ -84,49 +84,30 @@ function onRequest(context) { viewModel["model"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_MODEL"]; } if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]) { - if (deviceType == "android") { viewModel["BatteryLevel"] = {}; viewModel["BatteryLevel"]["value"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["BATTERY_LEVEL"]; viewModel["internalMemory"] = {}; - viewModel["internalMemory"]["total"] = Math. - round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 100) / 100; + viewModel["internalMemory"]["total"] = replaceNaNVal(Math. + round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 100) / 100); if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] != 0) { - viewModel["internalMemory"]["usage"] = Math. - round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] - - filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_AVAILABLE_MEMORY"]) - / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 10000) / 100; + viewModel["internalMemory"]["usage"] = replaceNaNVal(Math.round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] - + filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_AVAILABLE_MEMORY"]) * 100) / 100); } else { viewModel["internalMemory"]["usage"] = 0; } viewModel["externalMemory"] = {}; - viewModel["externalMemory"]["total"] = Math. - round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 100) / 100; + viewModel["externalMemory"]["total"] = replaceNaNVal(Math. + round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 100) / 100); if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] != 0) { - viewModel["externalMemory"]["usage"] = Math. + viewModel["externalMemory"]["usage"] = replaceNaNVal(Math. round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] - filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_AVAILABLE_MEMORY"]) - / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 10000) / 100; + / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 10000) / 100); } else { viewModel["externalMemory"]["usage"] = 0; } - } else if (deviceType == "ios") { - viewModel["BatteryLevel"] = {}; - viewModel["BatteryLevel"]["value"] = Math. round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["BatteryLevel"] * 10000) / 100; - - viewModel["internalMemory"] = {}; - viewModel["internalMemory"]["total"] = Math. - round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 100) / 100; - if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] != 0) { - viewModel["internalMemory"]["usage"] = Math. - round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] - - filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["AvailableDeviceCapacity"]) - / filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 10000) / 100; - } else { - viewModel["internalMemory"]["usage"] = 0; - } - } } } } @@ -160,34 +141,32 @@ function onRequest(context) { viewModel["ramUsage"] = {}; if (filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] != 0) { - viewModel["ramUsage"]["value"] = Math. + viewModel["ramUsage"]["value"] = replaceNaNVal(Math. round((filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] - filteredDeviceData["latestDeviceInfo"]["availableRAMMemory"]) - / filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] * 10000) / 100; + / filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] * 10000) / 100); } else { viewModel["ramUsage"]["value"] = 0; } viewModel["internalMemory"] = {}; - viewModel["internalMemory"]["total"] = Math. - round(filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 100) / 100; + viewModel["internalMemory"]["total"] = replaceNaNVal(Math. + round(filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 100) / 100); if (filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] != 0) { - viewModel["internalMemory"]["usage"] = Math. - round((filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] - - filteredDeviceData["latestDeviceInfo"]["internalAvailableMemory"]) - / filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 10000) / 100; + viewModel["internalMemory"]["usage"] = replaceNaNVal(Math.round((filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] - + filteredDeviceData["latestDeviceInfo"]["internalAvailableMemory"]) * 100) / 100); } else { viewModel["internalMemory"]["usage"] = 0; } viewModel["externalMemory"] = {}; - viewModel["externalMemory"]["total"] = Math. - round(filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 100) / 100; + viewModel["externalMemory"]["total"] = replaceNaNVal(Math. + round(filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 100) / 100); if (filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] != 0) { - viewModel["externalMemory"]["usage"] = Math. + viewModel["externalMemory"]["usage"] = replaceNaNVal(Math. round((filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] - filteredDeviceData["latestDeviceInfo"]["externalAvailableMemory"]) - / filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 10000) / 100; + / filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 10000) / 100); } else { viewModel["externalMemory"]["usage"] = 0; } @@ -220,4 +199,11 @@ function onRequest(context) { deviceViewData["isCloud"] = devicemgtProps['isCloud']; deviceViewData["anchor"] = encodeURI(JSON.stringify({ "device" : { "id" : deviceId, "type" : deviceType}})); return deviceViewData; + + function replaceNaNVal(val){ + if(isNaN(val)){ + return "N/A"; + } + return val; + } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.hbs index a3b324a77..8cf7a0d74 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.hbs @@ -36,7 +36,7 @@ } {{#each controlOperations}} - + {{#if iconFont}} {{else}} @@ -132,7 +132,7 @@

- + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.js index 588380a8e..52e11e8e2 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/operation-bar.js @@ -24,7 +24,7 @@ function onRequest(context) { var device = context.unit.params.device; var autoCompleteParams = context.unit.params.autoCompleteParams; var encodedFeaturePayloads = context.unit.params.encodedFeaturePayloads; - var allControlOps = operationModule.getControlOperations(device.type); + var allControlOps = operationModule.getControlOperations(device); var filteredControlOps = []; var queryParams = []; var formParams = []; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js index 66fb22ec9..8b0df72d0 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js @@ -76,6 +76,7 @@ function submitForm(formId) { var defaultStatusClasses = "fw fw-stack-1x"; var content = $("#operation-response-template").find(".content"); var title = content.find("#title"); + title.attr("class","center-block text-center"); var statusIcon = content.find("#status-icon"); var description = content.find("#description"); description.html(""); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs index a6cb40a00..b75f6d9f7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs @@ -85,7 +85,8 @@ class="fw fw-success"> - + @@ -109,7 +110,8 @@ class="fw fw-success"> - + @@ -157,7 +159,8 @@

Enforce a configured passcode policy on Android devices. - Once this profile is applied, the device owners won't be able to modify the password settings on their devices. + Once this profile is applied, the device owners won't be able to modify the password settings on + their devices.
Restrict predefined settings on Android devices. - Once this profile is applied, the device owners won't be able to modify the configured settings on their devices. + Once this profile is applied, the device owners won't be able to modify the configured settings + on their devices.
work-profile owner or device owner.
+
-
-