Skip to content

Commit 9ac33f8

Browse files
committed
Enhanced SSO to allow users to generate the appropriate login request and send that to CloudStack UI. If the Cloudstack UI detects this parameter "loginUrl", it will attempt a single signon process.
1 parent fa98eda commit 9ac33f8

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

‎ui/scripts/cloud.core.callbacks.js‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*
1717
*/
18-
18+
$.urlParam = function(name){ var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); if (!results) { return 0; } return results[1] || 0;}
19+
1920
/*
2021
This file is meant to help with implementing single signon integration. If you are using the
2122
cloud.com default UI, there is no need to touch this file.
@@ -37,35 +38,35 @@ var g_loginResponse = null;
3738

3839
/*
3940
For single signon purposes, you just need to make sure that after a successful login, you set the
40-
global variable "g_loginResponse"
41+
global variable "g_loginResponse"
42+
43+
You can also pass in a special param called loginUrl that is pregenerated and sent to the CloudStack, it will
44+
automatically log you in.
4145
4246
Below is a sample login attempt
4347
*/
4448

45-
/*
46-
$(document).ready(function() {
47-
//var username = encodeURIComponent($("#account_username").val());
48-
//var password = $("#account_password").val();
49-
//var domain = encodeURIComponent($("#account_domain").val());
50-
//var url = "/client/api?command=login&username="+username+"&password="+$.md5(password)+"&domain="+domain+"&response=json";
49+
$(document).ready(function() {
5150

52-
// Test URL
53-
var url = "/client/api?command=login&username=admin&password=5f4dcc3b5aa765d61d8327deb882cf99&domain=%2F&response=json";
54-
$.ajax({
55-
url: url,
56-
dataType: "json",
57-
async: false,
58-
success: function(json) {
59-
g_loginResponse = json.loginresponse;
60-
},
61-
error: function() {
62-
// This means the login failed. You should redirect to your login page.
63-
},
64-
beforeSend: function(XMLHttpRequest) {
65-
return true;
66-
}
67-
});
51+
var url = $.urlParam("loginUrl");
52+
if (url != undefined && url != null && url.length > 0) {
53+
url = unescape("/client/api?"+url);
54+
$.ajax({
55+
url: url,
56+
dataType: "json",
57+
async: false,
58+
success: function(json) {
59+
g_loginResponse = json.loginresponse;
60+
},
61+
error: function() {
62+
onLogoutCallback();
63+
// This means the login failed. You should redirect to your login page.
64+
},
65+
beforeSend: function(XMLHttpRequest) {
66+
return true;
67+
}
68+
});
69+
}
6870
});
69-
*/
7071

7172

‎ui/scripts/cloud.core.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*
1717
*/
1818

19-
$.urlParam = function(name){ var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); if (!results) { return 0; } return results[1] || 0;}
20-
2119
//***** actions for a tab in right panel (begin) ************************************************************************
2220
function buildActionLinkForTab(label, actionMap, $actionMenu, $midmenuItem1, $thisTab) {
2321
var apiInfo = actionMap[label];

0 commit comments

Comments
 (0)