diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js index b0eb98c5548..b0e05fdd8a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js @@ -1,56 +1,51 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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 + * "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. */ /* - * This module contains user and roles related functionality + * This module contains user and roles related functionality. */ var userModule = function () { var log = new Log("/app/modules/user.js"); var constants = require("/app/modules/constants.js"); var utility = require("/app/modules/utility.js")["utility"]; - var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); - var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; + var devicemgtProps = require("/app/conf/devicemgt-props.js").config(); + var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; /* Initializing user manager */ - var carbon = require('carbon'); - var tenantId = carbon.server.tenantId(); - var url = carbon.server.address('https') + "/admin/services"; + var carbon = require("carbon"); + var url = carbon.server.address("https") + "/admin/services"; var server = new carbon.server.Server(url); - var userManager = new carbon.user.UserManager(server, tenantId); - - var deviceManagementService = utility.getDeviceManagementService(); - var EmailMessageProperties = Packages.org.wso2.carbon.device.mgt.common.EmailMessageProperties; var publicMethods = {}; var privateMethods = {}; /** - * Get the carbon user object from the session. If not found - it will throw a user not found error. - * @returns {carbon user object} + * Get the carbon user object from the session. If not found - it will throw a user not found error. + * @returns {object} carbon user object */ privateMethods.getCarbonUser = function () { - var carbon = require('carbon'); - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; + var carbon = require("carbon"); + var carbonUser = session.get(constants["USER_SESSION_KEY"]); + var utility = require("/modules/utility.js")["utility"]; if (!carbonUser) { log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; + throw constants["ERRORS"]["USER_NOT_FOUND"]; } return carbonUser; }; @@ -59,83 +54,25 @@ var userModule = function () { * Only GET method is implemented for now since there are no other type of methods used this method. * @param url - URL to call the backend without the host * @param method - HTTP Method (GET, POST) - * @returns { - * 'status': 'success'|'error', - * 'content': {} - * } + * @returns An object with 'status': 'success'|'error', 'content': {} */ privateMethods.callBackend = function (url, method) { - if (constants.HTTP_GET == method) { - var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) { - var response = {}; - response.content = responsePayload["responseContent"]; - if (responsePayload["responseContent"] == null && responsePayload != null) { - response.content = responsePayload; + if (constants["HTTP_GET"] == method) { + return serviceInvokers.XMLHttp.get(url, + function (backendResponse) { + var response = {}; + response.content = backendResponse.responseText; + if (backendResponse.status == 200) { + response.status = "success"; + } else if (backendResponse.status == 400 || backendResponse.status == 401 || + backendResponse.status == 404 || backendResponse.status == 500) { + response.status = "error"; + } + return response; } - response.status = "success"; - return response; - }, - function (responsePayload) { - var response = {}; - response.content = responsePayload; - response.status = "error"; - return response; - }); - return response; + ); } else { - log.error("Programming error : This method only support HTTP GET requests."); - } - }; - - /* - @Deprecated - */ - /** - * Add user to mdm-user-store. - * - * @param username Username of the user - * @param firstname First name of the user - * @param lastname Last name of the user - * @param emailAddress Email address of the user - * @param userRoles Roles assigned to the user - * - * @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists - */ - publicMethods.addUser = function (username, firstname, lastname, emailAddress, userRoles) { - var statusCode, carbon = require('carbon'); - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - try { - utility.startTenantFlow(carbonUser); - var tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - if (userManager.userExists(username)) { - if (log.isDebugEnabled()) { - log.debug("A user with name '" + username + "' already exists."); - } - // http status code 409 refers to - conflict. - statusCode = 409; - } else { - var initialUserPassword = privateMethods.generateInitialUserPassword(); - var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress); - - userManager.addUser(username, initialUserPassword, userRoles, defaultUserClaims, "default"); - privateMethods.inviteUserToEnroll(username, initialUserPassword); - if (log.isDebugEnabled()) { - log.debug("A new user with name '" + username + "' was created."); - } - // http status code 201 refers to - created. - statusCode = 201; - } - return statusCode; - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); + log.error("Runtime error : This method only support HTTP GET requests."); } }; @@ -179,197 +116,6 @@ var userModule = function () { } }; - /* - @Deprecated - */ - /** - * Remove an existing user from mdm-user-store. - * - * @param username Username of the user - * @returns {number} HTTP Status code 200 if succeeded, 409 if the user does not exist - */ - publicMethods.removeUser = function (username) { - var statusCode, carbon = require('carbon'); - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - try { - utility.startTenantFlow(carbonUser); - var tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - if (userManager.userExists(username)) { - userManager.removeUser(username); - if (log.isDebugEnabled()) { - log.debug("An existing user with name '" + username + "' was removed."); - } - // http status code 200 refers to - success. - statusCode = 200; - } else { - if (log.isDebugEnabled()) { - log.debug("A user with name '" + username + "' does not exist to remove."); - } - // http status code 409 refers to - conflict. - statusCode = 409; - } - return statusCode; - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - - /* - @Deprecated - */ - /** - * Private method to be used by addUser() to - * generate an initial user password for a user. - * This will be the password used by a user for his initial login to the system. - * - * @returns {string} Initial User Password - */ - privateMethods.generateInitialUserPassword = function () { - var passwordLength = 6; - //defining the pool of characters to be used for initial password generation - var lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz"; - var upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - var numericCharset = "0123456789"; - - var totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset; - var totalCharsetLength = totalCharset.length; - - var initialUserPassword = ""; - for (var i = 0; i < passwordLength; ++i) { - initialUserPassword += totalCharset.charAt(Math.floor(Math.random() * totalCharsetLength)); - } - if (log.isDebugEnabled()) { - log.debug("Initial password created for new user : " + initialUserPassword); - } - return String(initialUserPassword); - }; - - /* - @Deprecated - */ - /** - * Build default user claims. - * - * @param firstname First name of the user - * @param lastname Last name of the user - * @param emailAddress Email address of the user - * - * @returns {Object} Default user claims to be provided - */ - privateMethods.buildDefaultUserClaims = function (firstname, lastname, emailAddress) { - var defaultUserClaims = { - "http://wso2.org/claims/givenname": firstname, - "http://wso2.org/claims/lastname": lastname, - "http://wso2.org/claims/emailaddress": emailAddress - }; - if (log.isDebugEnabled()) { - log.debug("ClaimMap created for new user : " + stringify(defaultUserClaims)); - } - return defaultUserClaims; - }; - - /* - @Deprecated - */ - /** - * Send an initial invitation email to a user with username/password attached - * for the very-first enrollment with WSO2 MDM. - * - * @param username Username of the user - * @param password Password of the user - */ - privateMethods.inviteUserToEnroll = function (username, password) { - var carbon = require('carbon'); - var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent"; - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - //var user = userManagementService.getUser(username, carbonUser.tenantId); - try { - utility.startTenantFlow(carbonUser); - var tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - var emailTo = []; - var user = userManager.getUser(username); - emailTo[0] = privateMethods.getEmail(username, userManager); - var emailMessageProperties = new EmailMessageProperties(); - emailMessageProperties.setMailTo(emailTo); - emailMessageProperties.setFirstName(privateMethods.getFirstName(username, userManager)); - emailMessageProperties.setUserName(username); - emailMessageProperties.setPassword(password); - emailMessageProperties.setEnrolmentUrl(enrollmentURL); - deviceManagementService.sendRegistrationEmail(emailMessageProperties); - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - - /* - @Deprecated - */ - privateMethods.getEmail = function (username, userManager) { - return userManager.getClaim(username, "http://wso2.org/claims/emailaddress", null) - }; - - /* - @Deprecated - */ - privateMethods.getFirstName = function (username, userManager) { - return userManager.getClaim(username, "http://wso2.org/claims/givenname", null) - }; - - /* - @Deprecated - */ - privateMethods.getLastName = function (username, userManager) { - return userManager.getClaim(username, "http://wso2.org/claims/lastname", null) - }; - - /* - @Deprecated - */ - publicMethods.inviteUser = function (username) { - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent"; - - try { - utility.startTenantFlow(carbonUser); - var tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - var user = userManager.getUser(username); - var emailProperties = new EmailMessageProperties(); - var emailTo = []; - emailTo[0] = privateMethods.getEmail(username, userManager); - emailProperties.setMailTo(emailTo); - //emailProperties.setFirstName(user.getFirstName()); - emailProperties.setFirstName(privateMethods.getFirstName(username, userManager)); - emailProperties.setEnrolmentUrl(enrollmentURL); - deviceManagementService.sendEnrolmentInvitation(emailProperties); - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - /* @Updated */ @@ -382,9 +128,12 @@ var userModule = function () { } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users"; - return privateMethods.callBackend(url, constants.HTTP_GET); - + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=100"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content).users; + } + return response; } catch (e) { throw e; } finally { @@ -395,22 +144,16 @@ var userModule = function () { /** * Return a User object from the backend by calling the JAX-RS * @param username - * @returns { - * 'status': 'success'|'error', - * 'content': { - "username": "abc", - "firstname": "abc", - "lastname": "efj", - "emailAddress": "abc@abc.com" - } - * } + * @returns {object} a response object with status and content on success. */ publicMethods.getUser = function (username) { var carbonUser = privateMethods.getCarbonUser(); try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/view?username=" + username; - var response = privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + + encodeURIComponent(username); + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + response["content"] = parse(response.content); response["userDomain"] = carbonUser.domain; return response; } catch (e) { @@ -419,18 +162,19 @@ var userModule = function () { utility.endTenantFlow(); } }; + /** - * TODO: comment + * Returns a set of roles assigned to a particular user * @param username - * @returns {*} + * @returns {object} a response object with status and content on success. */ publicMethods.getRolesByUsername = function (username) { var carbonUser = privateMethods.getCarbonUser(); try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/roles?username=" + username; - var response = privateMethods.callBackend(url, constants.HTTP_GET); - return response; + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + + encodeURIComponent(username) + "/roles"; + return privateMethods.callBackend(url, constants["HTTP_GET"]); } catch (e) { throw e; } finally { @@ -450,8 +194,8 @@ var userModule = function () { } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/users-by-username"; - return privateMethods.callBackend(url, constants.HTTP_GET) + var url = devicemgtProps["httpsURL"] + "/mdm-admin/users/users-by-username"; + return privateMethods.callBackend(url, constants["HTTP_GET"]); } catch (e) { throw e; } finally { @@ -467,15 +211,19 @@ var userModule = function () { */ publicMethods.getRoles = function () { var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + var utility = require("/app/modules/utility.js")["utility"]; if (!carbonUser) { log.error("User object was not found in the session"); throw constants["ERRORS"]["USER_NOT_FOUND"]; } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles"; - return privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content).roles; + } + return response; } catch (e) { throw e; } finally { @@ -488,18 +236,24 @@ var userModule = function () { */ /** * Get User Roles from user store (Internal roles not included). + * @returns {object} a response object with status and content on success. */ - publicMethods.getRolesByUserStore = function (userStore) { + publicMethods.getRolesByUserStore = function () { + var ROLE_LIMIT = devicemgtProps["pageSize"]; var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + var utility = require("/app/modules/utility.js")["utility"]; if (!carbonUser) { log.error("User object was not found in the session"); throw constants["ERRORS"]["USER_NOT_FOUND"]; } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/" + encodeURIComponent(userStore); - return privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles?limit=" + ROLE_LIMIT; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content).roles; + } + return response; } catch (e) { throw e; } finally { @@ -510,40 +264,45 @@ var userModule = function () { /** * Get Platforms. */ + //TODO Move this piece of logic out of user.js to somewhere else appropriate. publicMethods.getPlatforms = function () { var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + var utility = require("/app/modules/utility.js")["utility"]; if (!carbonUser) { log.error("User object was not found in the session"); throw constants["ERRORS"]["USER_NOT_FOUND"]; } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types"; - return privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/admin/device-types"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content); + } + return response; } catch (e) { throw e; } finally { utility.endTenantFlow(); } }; - /* - @Updated - */ + /** * Get role */ publicMethods.getRole = function (roleName) { var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + var utility = require("/app/modules/utility.js")["utility"]; if (!carbonUser) { log.error("User object was not found in the session"); throw constants["ERRORS"]["USER_NOT_FOUND"]; } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/role?rolename=" + encodeURIComponent(roleName); - var response = privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/roles/" + encodeURIComponent(roleName); + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + response.content = parse(response.content); return response; } catch (e) { throw e; @@ -687,30 +446,6 @@ var userModule = function () { return permissions; }; - /** - * Add new role with permissions. - * - * @param roleName Name of the role - * @param users List of users to assign the role - * @param permissions List of permissions - */ - publicMethods.addRole = function (roleName, users, permissions) { - var carbon = require('carbon'); - var tenantId = carbon.server.tenantId(); - var url = carbon.server.address('https') + "/admin/services"; - var server = new carbon.server.Server(url); - var userManager = new carbon.user.UserManager(server, tenantId); - try { - if (!userManager.roleExists(roleName)) { - userManager.addRole(roleName, users, permissions); - } else { - log.info("Role exist with name: " + roleName); - } - } catch (e) { - throw e; - } - }; - publicMethods.addPermissions = function (permissionList, path, init) { var registry, carbon = require("carbon"); var carbonServer = application.get("carbonServer"); @@ -776,24 +511,29 @@ var userModule = function () { * retrieve secondary user stores. * This needs Authentication since the method access admin services. * - * @returns {string array} Array of secondary user stores. + * @returns Array of secondary user stores. */ publicMethods.getSecondaryUserStores = function () { var returnVal = []; - var endpoint = devicemgtProps.adminService + constants.USER_STORE_CONFIG_ADMIN_SERVICE_END_POINT; + var endpoint = devicemgtProps["adminService"] + constants["USER_STORE_CONFIG_ADMIN_SERVICE_END_POINT"]; var wsPayload = ""; serviceInvokers.WS.soapRequest( - "urn:getSecondaryRealmConfigurations", endpoint, wsPayload, function (wsResponse) { + "urn:getSecondaryRealmConfigurations", + wsPayload, + endpoint, + function (wsResponse) { var domainIDs = stringify(wsResponse.*::['return']. *::domainId.text()); if (domainIDs != "\"\"") { - var regExpForSearch = new RegExp(constants.USER_STORES_NOISY_CHAR, "g"); + var regExpForSearch = new RegExp(constants["USER_STORES_NOISY_CHAR"], "g"); domainIDs = domainIDs.replace(regExpForSearch, ""); - returnVal = domainIDs.split(constants.USER_STORES_SPLITTING_CHAR); + returnVal = domainIDs.split(constants["USER_STORES_SPLITTING_CHAR"]); } }, function (e) { log.error("Error retrieving secondary user stores", e); - }, constants.SOAP_VERSION); + }, + constants["SOAP_VERSION"]); return returnVal; }; + return publicMethods; }(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs index e8902e77d20..d9f24cd04fc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. }} -{{unit "cdmf.unit.ui.title" pageTitle="User Management"}} +{{unit "cdmf.unit.ui.title" pageTitle="User Management | Add User"}} {{#zone "breadcrumbs"}}
  • @@ -50,8 +50,8 @@ -
  • ' + $(this).html() + '
  • '); + } + }); + + /** + * append advance operations to list table toolbar + */ + $('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' + + '' + ); + + /** + * sorting dropdown menu select function + */ + $('.dataTables_wrapper .sort-list li a').click(function () { + $(this).closest('li').siblings('li').find('a').removeClass('sorting_asc').removeClass('sorting_desc'); + + var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + + if (!($(this).hasClass('sorting_asc')) && !($(this).hasClass('sorting_desc'))) { + $(this).addClass('sorting_asc'); + thisTable.fnSort([[$(this).attr('data-column'), 'asc']]); + } + else if ($(this).hasClass('sorting_asc')) { + $(this).switchClass('sorting_asc', 'sorting_desc'); + thisTable.fnSort([[$(this).attr('data-column'), 'desc']]); + } + else if ($(this).hasClass('sorting_desc')) { + $(this).switchClass('sorting_desc', 'sorting_asc'); + thisTable.fnSort([[$(this).attr('data-column'), 'asc']]); + } + }); + + var rowSelectedClass = 'DTTT_selected selected'; + + /** + * Enable/Disable selection on rows + */ + $('.dataTables_wrapper [data-click-event=toggle-selectable]').click(function () { + var button = this, + thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + if ($(button).html() == 'Select') { + thisTable.addClass("table-selectable"); + $(button).addClass("active").html('Cancel'); + $(button).parent().next().children("button").removeClass("disabled"); + // EMM related code + $(".viewEnabledIcon").unbind("click"); + //--- End of EMM related codes + } else if ($(button).html() == 'Cancel') { + thisTable.removeClass("table-selectable"); + $(button).addClass("active").html('Select'); + $(button).parent().next().children().addClass("disabled"); + // EMM related function + $(".viewEnabledIcon").bind("click", initiateViewOption); + //--- End of EMM related codes + } + }); + /** + * select/deselect all rows function + */ + $('.dataTables_wrapper [data-click-event=toggle-selected]').click(function () { + var button = this, + thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + if (!$(button).hasClass('disabled')) { + if ($(button).html() == 'Select All') { + thisTable.api().rows().every(function () { + $(this.node()).addClass(rowSelectedClass); + $(button).html('Deselect All'); + }); + } + else if ($(button).html() == 'Deselect All') { + thisTable.api().rows().every(function () { + $(this.node()).removeClass(rowSelectedClass); + $(button).html('Select All'); + }); + } + } + }); + + /** + * on row click select/deselect row function + */ + $('body').on('click', '[data-type=selectable]', function () { + var rowSelectedClass = 'DTTT_selected selected'; + $(this).toggleClass(rowSelectedClass); + var button = this, + thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + + thisTable.api().rows().every(function () { + if (!$(this.node()).hasClass(rowSelectedClass)) { + $(button).closest('.dataTables_wrapper').find('[data-click-event=toggle-selected]').html('Select All'); + } + }); + }); + + /** + * list table list/grid view toggle function + */ + var toggleButton = $('[data-click-event=toggle-list-view]'); + toggleButton.click(function () { + if ($(this).attr('data-view') == 'grid') { + $(this).closest('.dataTables_wrapper').find('.dataTable').addClass('grid-view'); + //$(this).closest('li').hide(); + //$(this).closest('li').siblings().show(); + } + else { + $(this).closest('.dataTables_wrapper').find('.dataTable').removeClass('grid-view'); + //$(this).closest('li').hide(); + //$(this).closest('li').siblings().show(); + } + }) + } + },settings) + ); + +}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js index 30f2be1c64e..a63dcbd5b0a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js @@ -26,10 +26,9 @@ var invokerUtil = function () { restAPIRequestDetails["requestMethod"] = requestMethod; restAPIRequestDetails["requestURL"] = requestURL; restAPIRequestDetails["requestPayload"] = JSON.stringify(requestPayload); - var appContext = devicemgtProps["appContext"]; var request = { - url: appContext + "api/invoker/execute/", + url: context + "/api/invoker/execute/", type: "POST", contentType: "application/json", data: JSON.stringify(restAPIRequestDetails), diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs index 16595376577..af0fa53631b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs @@ -15,10 +15,7 @@ specific language governing permissions and limitations under the License. }} -{{#zone "bottomJs"}} - {{js "js/js.cookie.js"}} - {{js "js/invoker-lib.js"}} - +{{#zone "content"}}
    @@ -34,4 +31,11 @@
    -{{/zone}} \ No newline at end of file +{{/zone}} +{{#zone "bottomJs"}} + + {{js "js/js.cookie.js"}} + {{js "js/invoker-lib.js"}} +{{/zone}} diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java index 067405622d4..a402f18e7cc 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java @@ -29,7 +29,7 @@ public class CertificateAuthenticator implements WebappAuthenticator { private static final String CERTIFICATE_AUTHENTICATOR = "CertificateAuth"; private static final String MUTUAL_AUTH_HEADER = "mutual-auth-header"; private static final String PROXY_MUTUAL_AUTH_HEADER = "proxy-mutual-auth-header"; - private static final String CERTIFICATE_VERIFICATION_HEADER = "certificate-verification-header"; + private static final String CERTIFICATE_VERIFICATION_HEADER = "Mdm-Signature"; private static final String CLIENT_CERTIFICATE_ATTRIBUTE = "javax.servlet.request.X509Certificate"; @Override @@ -55,7 +55,6 @@ public class CertificateAuthenticator implements WebappAuthenticator { authenticationInfo.setStatus(Status.CONTINUE); } - String certVerificationHeader = request.getContext().findParameter(CERTIFICATE_VERIFICATION_HEADER); try { // When there is a load balancer terminating mutual SSL, it should pass this header along and // as the value of this header, the client certificate subject dn should be passed. @@ -78,7 +77,7 @@ public class CertificateAuthenticator implements WebappAuthenticator { } } else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) { - String certHeader = request.getHeader(certVerificationHeader); + String certHeader = request.getHeader(CERTIFICATE_VERIFICATION_HEADER); if (certHeader != null && AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService(). verifySignature(certHeader)) { diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/h2.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/h2.sql new file mode 100644 index 00000000000..6705b595f0e --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/h2.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +); \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mssql.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mssql.sql new file mode 100644 index 00000000000..888ee030c87 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mssql.sql @@ -0,0 +1,8 @@ +CREATE TABLE DM_DEVICE_CERTIFICATE ( + ID INTEGER IDENTITY NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE VARBINARY(max) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +); diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mysql.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mysql.sql new file mode 100644 index 00000000000..3bdf0a5a176 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mysql.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +)ENGINE = InnoDB; \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/oracle.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/oracle.sql new file mode 100644 index 00000000000..75732199f61 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/oracle.sql @@ -0,0 +1,8 @@ +CREATE TABLE DM_DEVICE_CERTIFICATE ( + ID NUMBER(10) NOT NULL, + SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID NUMBER(10) DEFAULT 0, + USERNAME VARCHAR2(500) DEFAULT NULL, + PRIMARY KEY (ID) +) \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/postgresql.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/postgresql.sql new file mode 100644 index 00000000000..c23791abf04 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/postgresql.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID BIGSERIAL NOT NULL PRIMARY KEY, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BYTEA DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL +); \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf index 7bae1dd04a1..44e5960b63c 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf @@ -1,3 +1,4 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/wso2certs.jks,target:${installFolder}/../../resources/security/wso2certs.jks,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/certificate-config.xml,target:${installFolder}/../../conf/certificate-config.xml,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/certificate-config.xml,target:${installFolder}/../../conf/certificate-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/dbscripts/cdm/,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 3e40d109bd7..e9894b79977 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -17,15 +17,6 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( PRIMARY KEY (ID) ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID INTEGER auto_increment NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) -); - CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER auto_increment NOT NULL, DESCRIPTION TEXT DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index a67d67f9e00..66ce12dc875 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -17,15 +17,6 @@ CREATE TABLE DM_GROUP ( PRIMARY KEY (ID) ); -CREATE TABLE DM_DEVICE_CERTIFICATE ( - ID INTEGER IDENTITY NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE VARBINARY(max) DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) -); - CREATE TABLE DM_DEVICE ( ID INTEGER identity NOT NULL, DESCRIPTION VARCHAR(max) DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 40535450acf..1d2013cbc42 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -6,15 +6,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( PRIMARY KEY (ID) )ENGINE = InnoDB; -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID INTEGER auto_increment NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) -)ENGINE = InnoDB; - CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER AUTO_INCREMENT NOT NULL, DESCRIPTION TEXT DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 41f539cee05..18ed9c2abe4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -44,16 +44,6 @@ WHEN (NEW.ID IS NULL) SELECT DM_GROUP_seq.NEXTVAL INTO :NEW.ID FROM DUAL; END; / - -CREATE TABLE DM_DEVICE_CERTIFICATE ( - ID NUMBER(10) NOT NULL, - SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID NUMBER(10) DEFAULT 0, - USERNAME VARCHAR2(500) DEFAULT NULL, - PRIMARY KEY (ID) -) -/ -- Generate ID using sequence and trigger CREATE SEQUENCE DM_DEVICE_CERTIFICATE_seq START WITH 1 INCREMENT BY 1 NOCACHE / diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index c29d18e0214..2da059d3a77 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -5,14 +5,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID BIGSERIAL NOT NULL PRIMARY KEY, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BYTEA DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL -); - CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID BIGSERIAL NOT NULL PRIMARY KEY, DESCRIPTION TEXT DEFAULT NULL,