diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag index 34eadba2..093c794e 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag @@ -33,27 +33,88 @@ var carbonHttpsServletTransport = carbon.server.address('https'); var result; -if (uriMatcher.match("/{context}/api/device/sketch/download")) { - sketchType = request.getParameter("sketchType"); - deviceType = request.getParameter("deviceType"); +if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) { + downloadId = uriMatcher.elements().downloadId; + if(downloadId){ + //Just download the already created zip archive + var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils; + var sketchFolder = "repository/resources/sketches"; + var archivesPath = "file://"+CarbonUtils.getCarbonHome() + "/" + sketchFolder + "/archives/" + downloadId + ".zip"; + var zipFile = new File(archivesPath); + response.addHeader('Content-type', "application/zip, application/octet-stream"); + response.addHeader('Cache-Control', 'public,max-age=12960000'); + response.addHeader("Content-Disposition", "attachment; filename=\"" + downloadId + ".zip\""); + + try { + zipFile.open('r'); + var stream = zipFile.getStream(); + print(stream); + }catch(err){ + + }finally{ + if(zipFile!=null) { + zipFile.close(); + } + } - if (!sketchType) { - log.error("Sketch Type is empty"); - } + }else { + //Create a new zip archive and register user calling endpoint - var user = session.get(constants.USER_SESSION_KEY); - if (!user) { - response.sendRedirect(dcProps.appContext + "login?#login-required"); - exit(); + /* This should match with $CARBON_HOME/repository/resources/sketches/{sketchType} */ + sketchType = request.getParameter("sketchType"); + /* This should be registered device type of the CDMF(Connected Device Management Framework) */ + deviceType = request.getParameter("deviceType"); + + if (!sketchType) { + log.error("Sketch Type is empty!"); + // http status code 400 refers to - Bad request. + result = 400; + } else { + var user = session.get(constants.USER_SESSION_KEY); + + if (!user) { + response.sendRedirect(dcProps.appContext + "login?#login-required"); + exit(); + } + + //URL: https://localhost:9443/{deviceType}/download?owner={username} + deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager"; + + sketchDownloadEndPoint = deviceManagerService + "/device/" + sketchType + "/download"; + response.sendRedirect(sketchDownloadEndPoint + "?owner=" + user.username); + exit();//stop execution + + } } - //URL: https://localhost:9443/{deviceType}/download?owner={username} - deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager"; - sketchDownloadEndPoint = deviceManagerService + "/device/" + sketchType + "/download"; - response.sendRedirect(sketchDownloadEndPoint + "?owner=" + user.username); - exit();//stop execution +} else if (uriMatcher.match("/{context}/api/device/sketch/generate_link")) { + + var contents = request.getContent(); + sketchType = contents.sketchType; + deviceType = contents.deviceType; + generateLink = contents.generateLink; + + if (!sketchType) { + log.error("Sketch Type is empty!"); + // http status code 400 refers to - Bad request. + result = 400; + } else { + var user = session.get(constants.USER_SESSION_KEY); + + if (!user) { + result = 403; + }else { + //URL: https://localhost:9443/{deviceType}/download?owner={username} + deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager"; + + sketchGenerateLinkEndPoint = deviceManagerService + "/device/" + sketchType + "/generate_link"; + var fileId = get(sketchGenerateLinkEndPoint + "?owner=" + user.username, null, "text"); + result = carbonHttpsServletTransport + constants.WEB_APP_CONTEXT + "/api/device/sketch/download/" + fileId.data; + } + } } else if (uriMatcher.match("/{context}/api/devices/all")) { + var user = session.get(constants.USER_SESSION_KEY); if (!user) { response.sendRedirect(dcProps.appContext + "login?#login-required"); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag new file mode 100755 index 00000000..4fa85bfc --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag @@ -0,0 +1,31 @@ +<% +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var uri = request.getRequestURI(); +var uriMatcher = new URIMatcher(String(uri)); + +var log = new Log("api/operation-api.jag"); + +var deviceModule = require("/modules/device.js").deviceModule; + +if (uriMatcher.match("/{context}/api/operation")) { + payload = request.getContent(); + result = deviceModule.performOperation(payload.devices, payload.operation); +} +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag new file mode 100755 index 00000000..5615c877 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag @@ -0,0 +1,49 @@ +<% +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var uri = request.getRequestURI(); +var uriMatcher = new URIMatcher(String(uri)); + +var log = new Log("api/policy-api.jag"); + +var constants = require("/modules/constants.js"); +var dcProps = require('/config/dc-props.js').config(); +var policyModule = require("/modules/policy.js").policyModule; + +var result; +if (uriMatcher.match("/{context}/api/policies/update")) { + payload = request.getContent(); + policyModule.updatePolicyPriorities(payload); +} else if (uriMatcher.match("/{context}/api/policies/{id}/delete")) { + elements = uriMatcher.elements(); + policyId = elements.id; + try { + result = policyModule.deletePolicy(policyId); + } catch (e) { + log.error("Exception occurred while trying to delete policy for id:" + policyId, e); + // http status code 500 refers to - Internal Server Error. + result = 500; + } +} + +// returning the result. +if (result) { + response.content = result; +} +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag index 95d29d05..c1af157b 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag @@ -128,7 +128,7 @@ function getSensorData(table, column, user, deviceId, from, to) { try { fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to); }catch(error){ - log.info(error); + log.error(error); } var sensorData = []; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag index 8586730a..2b5e8184 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag @@ -25,7 +25,8 @@ var log = new Log("api/user-api.jag"); var constants = require("/modules/constants.js"); var dcProps = require('/config/dc-props.js').config(); var userModule = require("/modules/user.js").userModule; -var utility = require("/modules/utility.js").utility; +var deviceModule = require("/modules/device.js").deviceModule; +var deviceManagementService = utility.getDeviceManagementService(); var result; @@ -40,7 +41,15 @@ if (uriMatcher.match("/{context}/api/user/login/")) { if (log.isDebugEnabled()) { log.debug("User Logged In : " + user); } - response.sendRedirect(constants.WEB_APP_CONTEXT); + + var hasDevcies = (deviceManagementService.getDeviceListOfUser(username).size() >= 1); + + if(hasDevcies){ + response.sendRedirect(constants.WEB_APP_CONTEXT+"/devices"); + }else{ + response.sendRedirect(constants.WEB_APP_CONTEXT); + } + }, function () { response.sendRedirect(dcProps.appContext + "login?#auth-failed"); }); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js b/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js index d492ae79..5fd208f2 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js @@ -25,4 +25,4 @@ var carbonServer = new carbonModule.server.Server({ application.put("carbonServer", carbonServer); var userModule = require("/modules/user.js").userModule; var utility = require("/modules/utility.js").utility; -utility.insertAppPermissions(userModule, "init"); \ No newline at end of file +utility.insertAppPermissions(userModule, "init"); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf old mode 100644 new mode 100755 index 9d723c35..420fe87e --- a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf @@ -3,17 +3,25 @@ "logLevel": "info", "initScripts": ["/config/init.js"], "urlMappings": [ + { + "url" : "/testb/*", + "path" : "test.jag" + }, { "url" : "/test/*", "path" : "test/testExecutor.jag" }, { - "url": "/api/device/*", - "path": "/api/device-api.jag" + "url": "/api/device/*", + "path": "/api/device-api.jag" + }, + { + "url": "/api/devices/*", + "path": "/api/device-api.jag" }, { - "url": "/api/devices/*", - "path": "/api/device-api.jag" + "url": "/api/operation/*", + "path": "/api/operation-api.jag" }, { "url": "/api/user/*", @@ -27,6 +35,10 @@ "url": "/api/stats/*", "path": "/api/stats-api.jag" }, + { + "url": "/api/policies/*", + "path": "/api/policy-api.jag" + }, { "url": "/sso/login", "path": "/lib/login.jag" @@ -44,4 +56,4 @@ "path": "/lib/fuse.jag" } ] -} \ No newline at end of file +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/enrollment.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/enrollment.hbs old mode 100644 new mode 100755 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs new file mode 100755 index 00000000..6c9436ce --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs @@ -0,0 +1,44 @@ + + + + + {{ defineZone "title"}} + {{ defineZone "topCss"}} + + + + + +
+
+
+ {{ defineZone "content"}} +
+
+ +
+ + + + + diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs old mode 100644 new mode 100755 index 3065855a..6cedfaad --- a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs @@ -1,14 +1,15 @@ - - - - - - - {{ defineZone "title"}} - {{ defineZone "topLibCss"}} - {{ defineZone "topCss"}} - {{ defineZone "topJs"}} + + + + + + {{defineZone "favicon"}} + + {{ defineZone "title"}} + + {{ defineZone "topLibCss"}} + {{ defineZone "topCss"}}
@@ -32,6 +33,7 @@ {{ defineZone "body"}} {{ defineZone "footer"}}
+ {{ defineZone "bottomjquery" }} {{ defineZone "bottomLibJs" }} {{ defineZone "bottomJs" }} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/nav-fluid.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/nav-fluid.hbs old mode 100644 new mode 100755 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag old mode 100644 new mode 100755 index 147c20a2..8aae7961 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag @@ -22,6 +22,8 @@ var sso = require('/modules/sso.js').sso; var constants = require('/modules/constants.js'); var carbonModule = require("carbon"); var log = new Log(); +var apiWrapperUtil = require("/modules/api-wrapper-util.js").apiWrapperUtil; +var userModule = require("/modules/user.js").userModule; var keyStoreParams = { keyStoreName: dataConfig.ssoConfiguration.keyStoreName, keyStorePassword: dataConfig.ssoConfiguration.keyStorePassword, @@ -31,14 +33,18 @@ sso.configure(dataConfig.ssoConfiguration.issuer, dataConfig.ssoConfiguration.appName, keyStoreParams, dataConfig.ssoConfiguration.identityProviderURL); sso.acs( - function(loggedInUser) { + function(loggedInUser, samlResponse) { var carbonUser = carbonModule.server.tenantUser(loggedInUser); session.put(constants.USER_SESSION_KEY, carbonUser); var username = carbonUser.username; if(log.isDebugEnabled()){ log.debug("User logged in: "+username); } - response.sendRedirect(dataConfig.appContext); + var permissions = userModule.getUIPermissions(); + if (permissions.DASHBOARD_VIEW){ + apiWrapperUtil.setupAccessTokenPair("saml", samlResponse); + response.sendRedirect(dataConfig.appContext + "/device-mgt"); + } }, function() { if(log.isDebugEnabled()){ log.debug("User logged out"); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js old mode 100644 new mode 100755 index 6ab63dc1..7aab77d7 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js @@ -82,41 +82,8 @@ var route; }; var renderStatic = function (unit, path) { - var unitModel = null; - var unitName = ""; - var parts = (unit + path).split("/"); - - //'unitName' name can be "unitA" or "categoryA/unitA" or "categoryA/categoryAb/unitB"...etc - //incrementally trying to resolve a unit using url path parts. - for (var i = 0; i < parts.length; i++) { - - if (unitName == "") { - unitName = parts[i]; - } else { - unitName += "/" + parts[i]; - } - - try { - var model = fuse.getUnitDefinition(unitName); - if (model) { - unitModel = { - name: model.name, - path: parts.splice(i + 1).join("/") - }; - break; - } - } catch (err) { - //unit not found, ignore error - } - } - - if (unitModel == null) { - log.error("unit `"+unit+"` not found!"); - return false; - } - - var staticFile = fuse.getFile(unitModel.name, 'public' + "/" + unitModel.path); - + log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a static file "' + path + '"'); + var staticFile = fuse.getFile(unit, 'public' + path); if (staticFile.isExists() && !staticFile.isDirectory()) { response.addHeader('Content-type', getMime(path)); response.addHeader('Cache-Control', 'public,max-age=12960000'); @@ -139,7 +106,7 @@ var route; if (jagFile.isExists()) { include(jagFile.getPath()); return true; - } else { + }else{ return false; } }; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag old mode 100644 new mode 100755 index a16cebfb..748d82ed --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag @@ -1,17 +1,10 @@ <% -var getPath = File.prototype.getPath; -File.prototype.getPath = function() { - var path = getPath.call(this); - path = path.replace(/\\/g, '/'); - return path; -}; - //global object to pass request stat among fuse framework files. var fuseState = { zones: {}, appName: '', - zoneStack: [], + currentZone: [], //TODO: rename to zone Stack currentUnit: null }; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js old mode 100644 new mode 100755 index fcc26c74..3dd87fc2 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js @@ -15,7 +15,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, for (var i = 0; i < definitions.length; i++) { var definition = definitions[i]; lookUpTable[definition.name] = i; - //log.info("initLookUp()"+definition.name+"<-"+i); } } }; @@ -46,7 +45,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, }; var getAncestorModels = function (unit) { - //log.info('[' + requestId + '] getAncestorModels()'+unit); var unitModel = getUnitDefinition(unit); var ancestors = [unitModel]; var parentName; @@ -150,12 +148,11 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, }; getUnitDefinition = function (unit) { - //log.info('[' + requestId + '] getUnitDefinition()'+unit); var definitions = getUnitDefinitions(); initLookUp(definitions); - //log.info('[' + requestId + '] lookUpTable[unit]:'+unit); var model = definitions[lookUpTable[unit]]; if (!model) { + log.warn('[' + requestId + '] unit "' + unit + '" does not exits'); throw '[' + requestId + '] unit "' + unit + '" does not exits'; } return model; @@ -208,7 +205,7 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, var unitDir = unitDirs[i]; if (unitDir.isDirectory()) { var unitName = unitDir.getName(); - //log.info("reading: "+unitName + " basePath:'" + basePath + "'"); + //log.info("reading: "+unitName + " basePath:"+basePath); var definitionFile = new File(fuse.getUnitPath(basePath+unitName) + '/' + unitName + '.json'); if(definitionFile.isExists()) { @@ -384,7 +381,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, * @returns {File} */ getFile = function (unitName, path, opt_suffix) { - //log.info("getFile() unitName:"+unitName+", path:"+path+", opt_suffix:"+opt_suffix); var slashPath = ((path[0] === '/') ? '' : '/') + path; var selfFileName = ''; var fileName = ''; @@ -403,10 +399,8 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, var unitDef = getUnitDefinition(unitName); if (unitDef.path.indexOf('.hbs', unitDef.path.length - 4) !== -1) { if (opt_suffix.indexOf('.hbs', opt_suffix.length - 4) !== -1) { - //log.info("1:"+unitDef.path); return new File(unitDef.path); } else { - //log.info("2:"+unitDef.path.replace(/.hbs$/, opt_suffix)); return new File(unitDef.path.replace(/.hbs$/, opt_suffix)); } } @@ -417,7 +411,7 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, '[' + requestId + '] for unit "' + unitName + '" file resolved : "' + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' ); - //log.info("3:"+getUnitPath(unitName) + slashPath + selfFileName); + return selfFile; } @@ -437,7 +431,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, '[' + requestId + '] for unit "' + unitName + '" file resolved : "' + slashPath + selfFileName + '" -> "' + file.getPath() + '"' ); - //log.info("4:"+getUnitPath(ancestorName) + slashPath + fileName); return file; } } @@ -445,7 +438,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, '[' + requestId + '] for unit "' + unitName + '" (non-excising) file resolved : "' + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' ); - //log.info("5:"+getUnitPath(unitName) + slashPath + selfFileName); return selfFile; }; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js old mode 100644 new mode 100755 index 9ea058b2..8c915700 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js @@ -56,7 +56,7 @@ Handlebars.innerZonesFromUnit = null; Handlebars.registerHelper('defineZone', function (zoneName, zoneContent) { var result = ''; var zone = Handlebars.Utils.escapeExpression(zoneName); - fuseState.zoneStack.push(zone); + fuseState.currentZone.push(zone); var unitsToRender = fuseState.zones[zone] || []; if (Handlebars.innerZones.length > 0) { @@ -92,12 +92,12 @@ Handlebars.registerHelper('defineZone', function (zoneName, zoneContent) { return result; } - fuseState.zoneStack.pop(); + fuseState.currentZone.pop(); return new Handlebars.SafeString(result); }); Handlebars.registerHelper('zone', function (zoneName, zoneContent) { - var currentZone = fuseState.zoneStack[fuseState.zoneStack.length - 1]; + var currentZone = fuseState.currentZone[fuseState.currentZone.length - 1]; if (currentZone == null) { return 'zone_' + zoneName + ' '; } @@ -113,7 +113,7 @@ Handlebars.registerHelper('zone', function (zoneName, zoneContent) { }); Handlebars.registerHelper('layout', function (layoutName) { - var currentZone = fuseState.zoneStack[fuseState.zoneStack.length - 1]; + var currentZone = fuseState.currentZone[fuseState.currentZone.length - 1]; if (currentZone == null) { return 'layout_' + layoutName; } else { @@ -122,7 +122,7 @@ Handlebars.registerHelper('layout', function (layoutName) { }); Handlebars.registerHelper('authorized', function () { - var currentZone = fuseState.zoneStack[fuseState.zoneStack.length - 1]; + var currentZone = fuseState.currentZone[fuseState.currentZone.length - 1]; if (currentZone == null) { return ''; } else { @@ -155,11 +155,11 @@ Handlebars.registerHelper('unit', function (unitName,options) { log.error('unit does not have a main zone'); } //TODO warn when unspecified decencies are included. - fuseState.zoneStack.push('main'); + fuseState.currentZone.push('main'); var template = fuse.getFile(baseUnit, '', '.hbs'); log.debug('[' + requestId + '] including "' + baseUnit + '"'+" with configs "+stringify(templateConfigs)); var result = new Handlebars.SafeString(Handlebars.compileFile(template)(getScope(baseUnit,templateConfigs))); - fuseState.zoneStack.pop(); + fuseState.currentZone.pop(); return result; }); @@ -192,7 +192,6 @@ Handlebars.registerHelper('equal', function(lvalue, rvalue, options) { return options.fn(this); } }); - Handlebars.registerHelper('unequal', function(lvalue, rvalue, options) { if (arguments.length < 3) throw new Error("Handlebars Helper equal needs 2 parameters"); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-v2.0.0.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-v2.0.0.js old mode 100644 new mode 100755 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js old mode 100644 new mode 100755 index 798c8563..4a191ca4 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js @@ -10190,7 +10190,7 @@ var compile = function (args) { var parser = new less.Parser(options); parser.parse(input, function (e, root) { if (e) { - log.info(e); + log.error(e); writeError(e, options); quit(1); } else { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/login.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/login.jag old mode 100644 new mode 100755 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/logout.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/logout.jag old mode 100644 new mode 100755 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/api-wrapper-util.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/api-wrapper-util.js new file mode 100755 index 00000000..2de3c4fa --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/api-wrapper-util.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var apiWrapperUtil = function () { + var module = {}; + var tokenUtil = require("/modules/util.js").util; + module.refreshToken = function () { + var tokenPair = session.get("accessTokenPair"); + tokenPair = tokenUtil.refreshToken(tokenPair); + session.put("accessTokenPair", tokenPair); + response.addCookie({'name': 'accessToken', 'value': tokenPair.accessToken}); + }; + module.setupAccessTokenPair = function (type, properties) { + var tokenPair; + var clientId = "pY0FbBUC_GI7mfHVS1FvhWAifEwa"; + var clientSecret = "Tu5Za1R3fHtGc5yH4KK8TNiLVSca"; + if (type == "password") { + //tokenPair = tokenUtil.getTokenWithPasswordGrantType(properties.username, properties.password, clientId, clientSecret); + } else if (type == "saml") { + + } + //session.put("accessTokenPair", tokenPair); + //response.addCookie({'name': 'accessToken', 'value': tokenPair.accessToken}); + }; + return module; +}(); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js index bd03967a..048a5d24 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js @@ -20,7 +20,7 @@ var WEB_APP_TITLE = "WSO2 DC - Device Cloud"; var WEB_APP_CONTEXT = "/iotserver"; var USER_SESSION_KEY = "USER"; var UNSPECIFIED = "Unspecified"; -var DEVICES_UNIT_PATH="/units/devices/"; +var DEVICES_UNIT_PATH="/units/"; var DEVICE_IDENTIFIER = "deviceIdentifier"; var DEVICE_NAME = "name"; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js index 8dfd6fcd..5b1b6b52 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js @@ -167,7 +167,7 @@ deviceModule = function () { var data = {}; //XMLHTTPRequest's GET - log.info(removeDeviceEndpoint); + //log.info(removeDeviceEndpoint); return del(removeDeviceEndpoint, data, "text"); }; @@ -178,8 +178,8 @@ deviceModule = function () { var data = {}; //XMLHTTPRequest's POST - log.info(updateDeviceEndpoint+ "?name="+device.name); - return post(updateDeviceEndpoint+ "?name="+device.name, data, "text"); + //log.info(updateDeviceEndpoint+ "?name="+device.name); + return post(updateDeviceEndpoint+ "?name="+encodeURIComponent(device.name), data, "text"); }; /* @@ -273,4 +273,4 @@ deviceModule = function () { return publicMethods; -}(); \ No newline at end of file +}(); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/util.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/util.js new file mode 100755 index 00000000..f6d413b2 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/util.js @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var util = function () { + var module = {}; + var Base64 = Packages.org.apache.commons.codec.binary.Base64; + var String = Packages.java.lang.String; + var log = new Log(); + + /** + * Encode the payload in Base64 + * @param payload + * @returns {Packages.java.lang.String} + */ + function encode(payload){ + return new String(Base64.encodeBase64(new String(payload).getBytes())); + } + + /** + * Get an AccessToken pair based on username and password + * @param username + * @param password + * @param clientId + * @param clientSecret + * @param scope + * @returns {{accessToken: "", refreshToken: ""}} + */ + module.getTokenWithPasswordGrantType = function (username, password, clientId, clientSecret, scope) { + var xhr = new XMLHttpRequest(); + var tokenEndpoint = "https://localhost:9443/oauth2/token"; + var encodedClientKeys = encode(clientId + ":" + clientSecret); + xhr.open("POST", tokenEndpoint, false); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys); + xhr.send("grant_type=password&username=" + username + "&password=" + password + "&scope=" + scope); + delete password, delete clientSecret, delete encodedClientKeys; + var tokenPair = {}; + if (xhr.status == 200) { + var data = parse(xhr.responseText); + tokenPair.refreshToken = data.refresh_token; + tokenPair.accessToken = data.access_token; + } else if (xhr.status == 403) { + throw "Error in obtaining token with Password Grant Type"; + } else { + throw "Error in obtaining token with Password Grant Type"; + } + return tokenPair; + }; + module.getTokenWithSAMLGrantType = function () { + + }; + module.refreshToken = function(tokenPair){ + var xhr = new XMLHttpRequest(); + var tokenEndpoint = "https://localhost:9443/oauth2/token"; + var encodedClientKeys = encode(clientId + ":" + clientSecret); + xhr.open("POST", tokenEndpoint, false); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys); + xhr.send("grant_type=refresh_token&refresh_token=" + tokenPair.refreshToken + "&scope=" + scope); + delete password, delete clientSecret, delete encodedClientKeys; + var tokenPair = {}; + if (xhr.status == 200) { + var data = parse(xhr.responseText); + tokenPair.refreshToken = data.refresh_token; + tokenPair.accessToken = data.access_token; + } else if (xhr.status == 403) { + throw "Error in obtaining token with Password Grant Type"; + } else { + throw "Error in obtaining token with Password Grant Type"; + } + return tokenPair; + }; + return module; +}(); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js index f4b02c14..1bff6d8e 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js @@ -41,22 +41,52 @@ utility = function () { publicMethods.insertAppPermissions = function (userModule, type) { userModule.addPermissions([{key: "device-mgt", name: "Device Management"}], "", type); - userModule.addPermissions([{key: "admin", name: "Device Management Admin"}], "device-mgt", type); - userModule.addPermissions([{key: "user", name: "Device Management User"}], "device-mgt", type); + userModule.addPermissions([{ + key: "admin", + name: "Device Management Admin" + }], "device-mgt", type); + userModule.addPermissions([{ + key: "user", + name: "Device Management User" + }], "device-mgt", type); userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "devices/list", name: "List Devices"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "devices/operation", name: "Perform Operation"}], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "devices/list", + name: "List Devices" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "devices/operation", + name: "Perform Operation" + }], "device-mgt/admin", type); userModule.addPermissions([{key: "users", name: "Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/add", name: "Add New Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/invite", name: "Invite Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/list", name: "List Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/remove", name: "Remove Users"}], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/add", + name: "Add New Users" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/invite", + name: "Invite Users" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/list", + name: "List Users" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/remove", + name: "Remove Users" + }], "device-mgt/admin", type); userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/user", type); - userModule.addPermissions([{key: "devices/list", name: "List Devices"}], "device-mgt/user", type); - userModule.addPermissions([{key: "devices/operation", name: "Perform Operation"}], "device-mgt/user", "init"); + userModule.addPermissions([{ + key: "devices/list", + name: "List Devices" + }], "device-mgt/user", type); + userModule.addPermissions([{ + key: "devices/operation", + name: "Perform Operation" + }], "device-mgt/user", "init"); }; return publicMethods; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs index 6500d10a..d11adeca 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs @@ -1,3 +1,4 @@ +{{authorized}} {{layout "fluid"}} {{#zone "title"}} WSO2 DC | Device Cloud diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs index 8e4b528b..0a7b07f9 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/android"}} + {{unit "android"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs index 0dd30cc5..b8b0b319 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/android_sense"}} + {{unit "android_sense"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs index c957abd3..afbe5b13 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/arduino"}} + {{unit "arduino"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs index 4b79991c..89d1b6d6 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/digital_display"}} + {{unit "digital_display"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs index 89676768..8330160f 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/firealarm"}} + {{unit "firealarm"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs index 68142bbe..ea9cd1a3 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs @@ -4,7 +4,7 @@ Devices {{/zone}} {{#zone "body"}} - {{unit "appbar" link="device-mgt" title="Device Management"}} + {{unit "appbar" link="device-mgt" title="My Devices"}} {{unit "extended-search-box"}} {{unit "operation-mod"}}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs index 9025c456..11e7f64b 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/raspberrypi"}} + {{unit "raspberrypi"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs index 4a4b58c1..a1b5049d 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/sensebot"}} + {{unit "sensebot"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs index cdfa94ba..8b87456d 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/windows"}} + {{unit "windows"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag new file mode 100755 index 00000000..c0097b63 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag @@ -0,0 +1,12 @@ +<% +var userModule = require("/modules/user.js").userModule; +userModule.addPermissions([{key: "device-mgt/", name: "Device Management"}], ""); +userModule.addPermissions([{key: "device-mgt/admin", name: "Device Management Admin"}], ""); +userModule.addPermissions([{key: "device-mgt/user", name: "Device Management User"}], ""); + +userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/admin"); +userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/user"); +userModule.addPermissions([{key: "devices/list", name: "List all Devices"}], "device-mgt/admin"); +userModule.addPermissions([{key: "devices/list", name: "List own Devices"}], "device-mgt/user"); +new Log().info(userModule.isAuthorized("/permission/device-mgt/admin/devices/list")); +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js b/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js new file mode 100755 index 00000000..f8ce2f3e --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +describe('Device Module', function () { + var log = new Log(); + var mobileDB; + var cdmDB; + var deviceModule = require("/modules/device.js").deviceModule; + + function tearUp() { + mobileDB = new Database("MobileDM_DS"); + cdmDB = new Database("DM_DS"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488e', 'admin@wso2.com', '-1234');"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488F', 'mdm@wso2.com', '-1234');"); + + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488e', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488F', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + } + + function tearDown() { + deleteData(); + mobileDB.close(); + cdmDB.close(); + } + + function deleteData(){ + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488e'"); + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488F'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488e'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488F'"); + } + + it('List all Devices - Device Module', function () { + try { + tearUp(); + var results = deviceModule.listDevices(); + expect(results.length).not.toBe(0); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); + it('List Devices for User - Device Module', function () { + try { + tearUp(); + var results = deviceModule.listDevicesForUser("mdm@wso2.com"); + expect(results.length).toBe(1); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); + it('Perform operation on the device', function(){ + try { + tearUp(); + var devices = [{"id": "4892813d-0b18-4a02-b7b1-61775257488e", "type": "android"}]; + var operation = {"featureName": "DEVICE_LOCK", "type": "COMMAND", "properties": {"enabled": true}} + var results = deviceModule.performOperation(devices, operation); + expect(results.length).toBe(1); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); +}); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/testExecutor.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/test/testExecutor.jag old mode 100644 new mode 100755 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js b/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js new file mode 100755 index 00000000..5bbf7444 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +describe('Device Module', function () { + var log = new Log(); + var mobileDB; + var cdmDB; + var deviceModule = require("/modules/device.js").deviceModule; + var userModule = require("/modules/user.js").userModule; + var constants = require("/modules/constants.js"); + function tearUp() { + mobileDB = new Database("MobileDM_DS"); + cdmDB = new Database("DM_DS"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488e', 'admin@wso2.com', '-1234');"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488F', 'mdm@wso2.com', '-1234');"); + + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488e', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488F', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + session.put(constants.USER_SESSION_KEY, {"username" : "admin", "domain": "carbon.super", "tenantId": "-1234"}); + } + + function tearDown() { + deleteData(); + mobileDB.close(); + cdmDB.close(); + session.put(constants.USER_SESSION_KEY, null); + } + + function deleteData(){ + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488e'"); + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488F'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488e'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488F'"); + } + + it('List all users', function () { + try { + tearUp(); + var results = userModule.getUsers(); + expect(results.length).not.toBe(0); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); + it('Check permission for user', function () { + try { + tearUp(); + expect(userModule.isAuthorized("/permission/device-mgt/user/devices/list")).toBe(true); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); +}); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/tmp/.gitignore b/modules/distribution/src/repository/jaggeryapps/iotserver/tmp/.gitignore new file mode 100755 index 00000000..50e166d6 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/tmp/.gitignore @@ -0,0 +1,5 @@ +# Ignore everything in this directory. +# they are auto generated, should not be committed. +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag new file mode 100755 index 00000000..77778307 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag @@ -0,0 +1,4 @@ +<% +var apiWrapperUtil = require("/modules/api-wrapper-util.js").apiWrapperUtil; +apiWrapperUtil.refreshToken(); +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.hbs similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.hbs rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.hbs diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js new file mode 100644 index 00000000..dae1a137 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js @@ -0,0 +1,4 @@ +function onRequest(context){ + context.sketchPath = "api/device/sketch/download"; + return context; +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android-thumb.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android-thumb.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android-thumb.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/store.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/store.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/store.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.hbs similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.hbs rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.hbs diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js new file mode 100644 index 00000000..dae1a137 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js @@ -0,0 +1,4 @@ +function onRequest(context){ + context.sketchPath = "api/device/sketch/download"; + return context; +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense-thumb.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense-thumb.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense-thumb.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/store.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/store.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/store.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs index e82f3989..4067deba 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs @@ -41,7 +41,7 @@