diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/config/config.json b/product/modules/distribution/src/repository/jaggeryapps/cdm/config/config.json new file mode 100644 index 0000000000..22f5a8d5b4 --- /dev/null +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/config/config.json @@ -0,0 +1,16 @@ +{ + "APP_CONTEXT" : "/cdm/", + "API_CONTEXT" : "api", + "HTTPS_URL": "%https.ip%", + "HTTP_URL": "%http.ip%", + "ssoConfiguration": { + "enabled": true, + "issuer": "cdm", + "identityProviderURL": "%https.ip%/sso/samlsso.jag", + "keyStorePassword": "wso2carbon", + "identityAlias": "wso2carbon", + "responseSigningEnabled": "true", + "storeAcs": "%https.ip%/emm/acs", + "keyStoreName": "/repository/resources/security/wso2carbon.jks" + } +} diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/acs.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/acs.jag index ed367512d2..400f98a931 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/acs.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/acs.jag @@ -1,76 +1,18 @@ <% -var dataConfi = require('/config/emm.js').config(); +var dataConfig = require('/modules/mdm-props.js').config(); var sso = require("/modules/sso.js").sso; var log = new Log(); var keyStoreParams = { - keyStoreName: dataConfi.ssoConfiguration.keyStoreName, - keyStorePassword: dataConfi.ssoConfiguration.keyStorePassword, - identityAlias: dataConfi.ssoConfiguration.identityAlias + keyStoreName: dataConfig.ssoConfiguration.keyStoreName, + keyStorePassword: dataConfig.ssoConfiguration.keyStorePassword, + identityAlias: dataConfig.ssoConfiguration.identityAlias } -sso.configure(dataConfi.ssoConfiguration.issuer, "emm", keyStoreParams, dataConfi.ssoConfiguration.identityProviderURL); +sso.configure(dataConfig.ssoConfiguration.issuer, "cdm", keyStoreParams, dataConfig.ssoConfiguration.identityProviderURL); sso.acs(function(loggedInUser) { - session.put("LOGGED_IN_USER", loggedInUser); - session.put("Loged", "true"); + session.put("USER", loggedInUser); var username = loggedInUser; - var userModule = require('/modules/user.js').user; - var db = common.getDatabase(); - var user = new userModule(db); - var objUser = user.getUser({ - 'userid': username, - login: true - }); - if (objUser != null) { - var userFeed = {}; - userFeed.tenantId = stringify(objUser["tenantId"]); - userFeed.username = objUser["username"]; - userFeed.email = objUser["email"]; - userFeed.firstName = objUser["firstName"]; - userFeed.lastName = objUser["lastName"]; - userFeed.mobile = objUser["mobile"]; - userFeed.tenantDomain = user.getTenantDomainFromID(stringify(objUser["tenantId"])); - var parsedRoles = parse(objUser["roles"]); - userFeed.roles = parsedRoles; - var isEMMAdmin = false; - var isAdmin = false; - for (var i = 0; i < parsedRoles.length; i++) { - if (parsedRoles[i] == 'Internal/emmadmin') { - isEMMAdmin = true; - break; - } - if (parsedRoles[i] == 'admin') { - isAdmin = true; - isEMMAdmin = true; - break; - } - } - userFeed.isEMMAdmin = isEMMAdmin; - userFeed.isAdmin = isAdmin; - session.put("emmConsoleUserLogin", "true"); - session.put("emmConsoleUser", userFeed); - //var db = common.getDatabase(); - - var startupModule = require('/modules/startup.js').startup; - var startup = new startupModule(db); - startup.onUserLogin(userFeed); - - var groupModule = require('/modules/group.js').group; - var group = new groupModule(db); - - if (!group.roleExists("Internal/emmadmin")) { - var userList = new Array(); - group.addGroup({ - 'name': 'Internal/emmadmin', - 'users': userList - }); - } - var appController = require('/controller/app.js'); - - if (isAdmin || isEMMAdmin) { - response.sendRedirect('console/dashboard'); - } else { - response.sendRedirect(appController.appInfo().server_url + 'users/devices?user=' + userFeed.username); - } - } + log.debug("User logged in: "+username); + response.sendRedirect('/cdm/dashboard'); }, function() { - response.sendRedirect('/emm'); + response.sendRedirect('/cdm'); }); %> \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/login.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/login.jag index e5b4c7ec1c..c9194d9f46 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/login.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/login.jag @@ -1,17 +1,18 @@ <% (function(){ - if (!session.get("emmConsoleUserLogin")) { - var dataConfi = require('/config/emm.js').config(); - var sso = require("/modules/sso.js").sso; - var keyStoreParams = { - keyStoreName : dataConfi.ssoConfiguration.keyStoreName, - keyStorePassword : dataConfi.ssoConfiguration.keyStorePassword, - identityAlias : dataConfi.ssoConfiguration.identityAlias - } - sso.configure(dataConfi.ssoConfiguration.issuer, "emm", keyStoreParams, dataConfi.ssoConfiguration.identityProviderURL); - sso.login(); + if (!session.get("USER")) { + var dataConfig = require('/modules/mdm-props.js').config(); + var sso = require("/modules/sso.js").sso; + + var keyStoreParams = { + keyStoreName : dataConfig.ssoConfiguration.keyStoreName, + keyStorePassword : dataConfig.ssoConfiguration.keyStorePassword, + identityAlias : dataConfig.ssoConfiguration.identityAlias + } + sso.configure(dataConfig.ssoConfiguration.issuer, "cdm", keyStoreParams, dataConfig.ssoConfiguration.identityProviderURL); + sso.login(); }else{ - response.sendRedirect("/emm"); + response.sendRedirect("/cdm"); } }()); %> diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/logout.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/logout.jag index b11568a17e..cafe1a3e8a 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/logout.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/controller/logout.jag @@ -1,15 +1,15 @@ <% -var user = session.get("emmConsoleUser"); +var user = session.get("USER"); if (user === null) { - response.sendRedirect('/emm'); + response.sendRedirect('/cdm/dashboard'); } else { - var dataConfi = require('/config/emm.js').config(); + var dataConfi = require('/modules/mdm-props.js').config(); var sso = require("/modules/sso.js").sso; var keyStoreParams = { keyStoreName: dataConfi.ssoConfiguration.keyStoreName, keyStorePassword: dataConfi.ssoConfiguration.keyStorePassword, identityAlias: dataConfi.ssoConfiguration.identityAlias } - sso.configure(dataConfi.ssoConfiguration.issuer, "emm", keyStoreParams, dataConfi.ssoConfiguration.identityProviderURL); + sso.configure(dataConfi.ssoConfiguration.issuer, "cdm", keyStoreParams, dataConfi.ssoConfiguration.identityProviderURL); sso.logout(user); } %> \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/auth-header.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/auth-header.jag index 4da7a8a6c7..71bce94b7e 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/auth-header.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/auth-header.jag @@ -1,3 +1,23 @@ -<% -// This will have the auth headers +<% +/* + * 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 loggedUser = session.get("USER"); +if(loggedUser==null){ + response.sendRedirect("/cdm/login"); +} %> \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/header.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/header.jag index 72ffa5bcae..0f8512cbe4 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/header.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/includes/header.jag @@ -18,6 +18,7 @@
  • Dashboard
  • Configuration
  • Management
  • +
  • Logout
  • diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf b/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf index 92697a30fa..f3891e024e 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf @@ -2,6 +2,18 @@ "welcomeFiles": ["pages/dashboard.jag"], "initScripts": ["/init.js"], "urlMappings": [ + { + "url": "/login", + "path": "/controller/login.jag" + }, + { + "url": "/logout", + "path": "/controller/logout.jag" + }, + { + "url": "/acs", + "path": "/controller/acs.jag" + }, { "url": "/devices/*", "path": "/pages/device.jag" diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/mdm-props.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/mdm-props.js new file mode 100644 index 0000000000..5ec5ac76ed --- /dev/null +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/mdm-props.js @@ -0,0 +1,37 @@ +/* + * 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 config = function () { + var conf = application.get("PINCH_CONFIG"); + if (!conf) { + var pinch = require('/modules/pinch.min.js').pinch, + server = require('carbon').server; + config = require('/config/config.json'), + pinch(config, /^/, function (path, key, value) { + if ((typeof value === 'string') && value.indexOf('%https.ip%') > -1) { + return value.replace('%https.ip%', server.address("https")); + } else if ((typeof value === 'string') && value.indexOf('%http.ip%') > -1) { + return value.replace('%http.ip%', server.address("http")); + } + return value; + }); + application.put("PINCH_CONFIG", config); + conf = config; + } + return conf; +}; \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/pinch.min.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/pinch.min.js new file mode 100644 index 0000000000..30af3b3e62 --- /dev/null +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/pinch.min.js @@ -0,0 +1,22 @@ +/* + * * + * * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * * + * * Licensed 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. + * + */ + +(function(){var k=function(a,c){return a.length!==c.length?!1:a.every(function(a,b){return c[b]===a})},j=function(a,c,d){var b,e;if("[object Array]"===Object.prototype.toString.call(a)){b=0;for(e=a.length;b

    You are now being redirected to SSO Provider. If the redirection fails, please click on the button below.

    "); } sso.logout = function(user){ diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag index 8bf721890f..0e7cd8d05f 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag @@ -18,6 +18,7 @@ * under the License. */ var title="WSO2 CDM"; +include("/includes/auth-header.jag"); %> <% diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag index 17a14734d5..dfd36da7f9 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag @@ -18,6 +18,7 @@ * under the License. */ var title="WSO2 CDM"; +include("/includes/auth-header.jag"); %> <%