From 583b17d40578e5835dfe8d8c6cb6a91f074ff835 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 15 Mar 2018 23:02:16 +0530 Subject: [PATCH] Add login.do, retry.do and consent.do This implements following fixes/improvements; * Adding an intermediate for user to accept consents. * Fixing issue of not redirected to the consent.do * Authentication failure page --- .../devicemgt/app/conf/app-conf.json | 6 +- .../consent-do.hbs | 73 +++++++++++++++++++ .../consent-do.js | 38 ++++++++++ .../consent-do.json | 6 ++ .../public/js/script.js | 35 +++++++++ .../cdmf.page.sign-in.login-do/login-do.hbs | 71 ++++++++++++++++++ .../cdmf.page.sign-in.login-do/login-do.js | 32 ++++++++ .../cdmf.page.sign-in.login-do/login-do.json | 6 ++ .../cdmf.page.sign-in.retry-do/retry-do.hbs | 32 ++++++++ .../cdmf.page.sign-in.retry-do/retry-do.js | 17 +++++ .../cdmf.page.sign-in.retry-do/retry-do.json | 6 ++ .../app/pages/cdmf.page.sign-in/sign-in.hbs | 50 +------------ .../app/pages/cdmf.page.sign-in/sign-in.js | 31 +------- 13 files changed, 321 insertions(+), 82 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/public/js/script.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.json create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.json diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json index 93c0fef2e1e..65d3f51ceb1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/app-conf.json @@ -4,7 +4,7 @@ "debuggingEnabled": false, "permissionRoot": "/", "portalURL": "https://${server.ip}:9445", - "loginPage": "cdmf.page.sign-in", + "loginPage": "cdmf.page.sign-in.login-do", "adminServicesUrl": "https://${server.ip}:${server.https_port}/admin/services/", "authModule": { "enabled": true, @@ -15,12 +15,12 @@ }, "onFail": { "script": "/app/modules/login.js", - "page": "cdmf.page.sign-in" + "page": "cdmf.page.sign-in.login-do" } }, "logout": { "onSuccess": { - "page": "cdmf.page.sign-in" + "page": "cdmf.page.sign-in.login-do" }, "onFail": { "page": "cdmf.page.dashboard" diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.hbs new file mode 100644 index 00000000000..c1d0e4140de --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.hbs @@ -0,0 +1,73 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} +{{#zone "title"}}{{! to override parent page title }}{{/zone}} +{{unit "cdmf.unit.ui.title" pageTitle="Consent Page"}} + +{{#zone "content"}} +
+
+ +

User Consents

+
+
+ {{appName}} application requests access to your profile information +
+ +
+
+

By selecting following attributes I agree to share them with the above service provider.

+
+ +
+
+ {{#each mandatoryClaims}} + + {{/each}} +
+
+ {{#each requestedClaims}} + + {{/each}} +
+

Mandatory claims are marked with an asterisk ( * )

+
+ + + + +
+
+
+
+
+{{/zone}} +{{#zone "bottomJs"}} + {{js "js/script.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.js new file mode 100644 index 00000000000..e15908617ef --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.js @@ -0,0 +1,38 @@ +function onRequest(context) { + var Encode = Packages.org.owasp.encoder.Encode; + var viewModel = {}; + viewModel.appName = Encode.forHtml(request.getParameter("sp")); + var mandatoryClaims = []; + var requestedClaims = []; + + var mandatoryClaimsList, requestedClaimsList; + var i, j, partOne, partTwo; + if (request.getParameter("mandatoryClaims")) { + mandatoryClaimsList = request.getParameter("mandatoryClaims").split(","); + for (j = 0; j < mandatoryClaimsList.length; j++) { + var mandatoryClaimsStr = mandatoryClaimsList[j]; + i = mandatoryClaimsStr.indexOf('_'); + partOne = mandatoryClaimsStr.slice(0, i); + partTwo = mandatoryClaimsStr.slice(i + 1, mandatoryClaimsStr.length); + mandatoryClaims.push( + {"claimId": Encode.forHtmlAttribute(partOne), "displayName": Encode.forHtmlAttribute(partTwo)} + ); + } + } + if (request.getParameter("requestedClaims")) { + requestedClaimsList = request.getParameter("requestedClaims").split(","); + for (j = 0; j < requestedClaimsList.length; j++) { + var requestedClaimsStr = requestedClaimsList[j]; + i = requestedClaimsStr.indexOf('_'); + partOne = requestedClaimsStr.slice(0, i); + partTwo = requestedClaimsStr.slice(i + 1, requestedClaimsStr.length); + requestedClaims.push( + {"claimId": Encode.forHtmlAttribute(partOne), "displayName": Encode.forHtmlAttribute(partTwo)} + ); + } + } + viewModel.mandatoryClaims = mandatoryClaims; + viewModel.requestedClaims = requestedClaims; + viewModel.sessionDataKey = Encode.forHtmlAttribute(request.getParameter("sessionDataKey")); + return viewModel; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.json new file mode 100644 index 00000000000..4ca8fc3a6c7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/consent-do.json @@ -0,0 +1,6 @@ +{ + "version": "1.0.0", + "layout": "uuf.layout.sign-in", + "uri": "/consent.do", + "isAnonymous": true +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/public/js/script.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/public/js/script.js new file mode 100644 index 00000000000..8588c004a9f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.consent-do/public/js/script.js @@ -0,0 +1,35 @@ +function approved() { + var mandatoryClaimCBs = $(".mandatory-claim"); + var checkedMandatoryClaimCBs = $(".mandatory-claim:checked"); + + if (checkedMandatoryClaimCBs.length == mandatoryClaimCBs.length) { + document.getElementById('consent').value = "approve"; + document.getElementById("consentForm").submit(); + } else { + $("#modal_claim_validation").modal(); + } +} + +function deny() { + document.getElementById('consent').value = "deny"; + document.getElementById("consentForm").submit(); +} + +$(document).ready(function () { + $("#consent_select_all").click(function () { + if (this.checked) { + $('.checkbox input:checkbox').each(function () { + $(this).prop("checked", true); + }); + } else { + $('.checkbox :checkbox').each(function () { + $(this).prop("checked", false); + }); + } + }); + $(".checkbox input").click(function (e) { + if (e.target.id !== 'consent_select_all') { + $("#consent_select_all").prop("checked", false); + } + }); +}); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.hbs new file mode 100644 index 00000000000..ab496ea12c7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.hbs @@ -0,0 +1,71 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} +{{#zone "title"}}{{! to override parent page title }}{{/zone}} +{{unit "cdmf.unit.ui.title" pageTitle="Login"}} + +{{#zone "content"}} +
+
+ +

Login

+
+ {{#if message}} +
+ {{message}}! +
+ {{/if}} + +
+
+
+ + +
+
+ + +
+ {{#if sessionDataKey}} + + {{/if}} + {{#if referer}} + + {{/if}} + +
+
+ +
+ + +
+
+
+
+
+{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.js new file mode 100644 index 00000000000..627791eebbe --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.js @@ -0,0 +1,32 @@ +function onRequest(context) { + var authModuleConfigs = context.app.conf["authModule"]; + var sessionDataKey = request.getParameter("sessionDataKey"); + var authFailure = request.getParameter("authFailure"); + + //if sso enabled and sessionDataKey is empty redirect + var ssoConfigs = authModuleConfigs["sso"]; + if (ssoConfigs && (ssoConfigs["enabled"].toString() == "true") && !sessionDataKey) { + // SSO is enabled in Auth module. + var redirectUri = context.app.context + "/uuf/login"; + var queryString = request.getQueryString(); + if (queryString && (queryString.length > 0)) { + redirectUri = redirectUri + "?" + queryString; + } + response.sendRedirect(encodeURI(redirectUri)); + exit(); + } + + var viewModel = {}; + var loginActionUrl = context.app.context + "/uuf/login"; + if (sessionDataKey) { + loginActionUrl = "/commonauth"; + } + + if (authFailure) { + viewModel.message = "Login failed! Please recheck the username and password and try again."; + } + + viewModel.sessionDataKey = sessionDataKey; + viewModel.loginActionUrl = loginActionUrl; + return viewModel; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.json new file mode 100644 index 00000000000..467bcc522b6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.login-do/login-do.json @@ -0,0 +1,6 @@ +{ + "version": "1.0.0", + "layout": "uuf.layout.sign-in", + "uri": "/login.do", + "isAnonymous": true +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.hbs new file mode 100644 index 00000000000..48f95629954 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.hbs @@ -0,0 +1,32 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} +{{#zone "title"}}{{! to override parent page title }}{{/zone}} +{{unit "cdmf.unit.ui.title" pageTitle="Authentication Failed!"}} + +{{#zone "content"}} +
+
+ +

{{stat}}

+
+
+ {{statusMessage}} +
+
+
+{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.js new file mode 100644 index 00000000000..cdd7a4be938 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.js @@ -0,0 +1,17 @@ +function onRequest(context) { + var Encode = Packages.org.owasp.encoder.Encode; + session.invalidate(); + var viewModel = {}; + + var stat = request.getParameter("status"); + var statusMessage = request.getParameter("statusMsg"); + + if (!stat || !statusMessage) { + stat = "Authentication Error!"; + statusMessage = "Something went wrong during the authentication process.Please try signing in again."; + } + + viewModel.stat = Encode.forHtmlContent(stat); + viewModel.statusMessage = Encode.forHtmlContent(statusMessage); + return viewModel; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.json new file mode 100644 index 00000000000..b66acf55c9d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in.retry-do/retry-do.json @@ -0,0 +1,6 @@ +{ + "version": "1.0.0", + "layout": "uuf.layout.sign-in", + "uri": "/retry.do", + "isAnonymous": true +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs index bd000a752df..104579406b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs @@ -19,53 +19,5 @@ {{unit "cdmf.unit.ui.title" pageTitle="Login"}} {{#zone "content"}} -
-
- -

Login

-
- {{#if message}} -
- {{message}}! -
- {{/if}} - -
-
-
- - -
-
- - -
- {{#if sessionDataKey}} - - {{/if}} - {{#if referer}} - - {{/if}} - -
-
- -
- - -
-
-
-
-
+ Redirecting, Please wait... {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.js index 627791eebbe..1f33330c28e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.js @@ -1,32 +1,3 @@ function onRequest(context) { - var authModuleConfigs = context.app.conf["authModule"]; - var sessionDataKey = request.getParameter("sessionDataKey"); - var authFailure = request.getParameter("authFailure"); - - //if sso enabled and sessionDataKey is empty redirect - var ssoConfigs = authModuleConfigs["sso"]; - if (ssoConfigs && (ssoConfigs["enabled"].toString() == "true") && !sessionDataKey) { - // SSO is enabled in Auth module. - var redirectUri = context.app.context + "/uuf/login"; - var queryString = request.getQueryString(); - if (queryString && (queryString.length > 0)) { - redirectUri = redirectUri + "?" + queryString; - } - response.sendRedirect(encodeURI(redirectUri)); - exit(); - } - - var viewModel = {}; - var loginActionUrl = context.app.context + "/uuf/login"; - if (sessionDataKey) { - loginActionUrl = "/commonauth"; - } - - if (authFailure) { - viewModel.message = "Login failed! Please recheck the username and password and try again."; - } - - viewModel.sessionDataKey = sessionDataKey; - viewModel.loginActionUrl = loginActionUrl; - return viewModel; + response.sendRedirect(context.app.context + "/uuf/login"); } \ No newline at end of file