From 2f91af1fba077a238ba199c1e80775174223dae2 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 26 Jan 2011 11:16:02 -0800 Subject: [PATCH] Simplified the single signon process --- .../classes/resources/messages.properties | 3 +- ui/scripts/cloud.core.callbacks.js | 42 ++++--------- ui/scripts/cloud.core.init.js | 59 +++++++++++++------ 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index e301f8fc4d7..b33e65699e4 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -301,6 +301,7 @@ label.add.by.cidr=Add By CIDR label.add.by.group=Add By Group label.security.group.name=Security Group Name label.add.more=Add More +label.nfs.server=NFS Server label.lang.english=English label.lang.chinese=Chinese @@ -418,7 +419,7 @@ message.add.cluster=Add a hypervisor managed cluster for zone message.add.primary.storage=Add a new Primary Storage for zone , pod message.add.ip.range.to.pod=

Add an IP range to pod:

-message.secondary.storage=Add a new storage for zone +message.add.secondary.storage=Add a new storage for zone message.number.zones=

# of Zones

message.number.pods=

# of Pods

message.number.clusters=

# of Clusters

diff --git a/ui/scripts/cloud.core.callbacks.js b/ui/scripts/cloud.core.callbacks.js index cab0b4e3421..4329e4b73e5 100644 --- a/ui/scripts/cloud.core.callbacks.js +++ b/ui/scripts/cloud.core.callbacks.js @@ -28,24 +28,19 @@ or it's the first time the user has come to this page. */ function onLogoutCallback() { // Returning true means the LOGIN page will be show. If you wish to redirect the user - // to different login page, this is where you would do that. + // to different login page, this is where you would do that. + g_loginResponse = null; return true; -} +} + +var g_loginResponse = null; /* -For single signon purposes, you should set the following cookies so that the UI does not force a logout. +For single signon purposes, you just need to make sure that after a successful login, you set the +global variable "g_loginResponse" -JSESSIONID : jsessionid generated by the mgmt server -username : username -role : 0 = User, 1 = ROOT Admin, 2 = Domain Admin -domainid: domainid - -All values can be retrieved by making a successful AJAX login call to the mgmt server. - -If you cannot set these cookies before redirecting to this mgmt UI. You can uncomment the code -below and as long as you can retrieve the username, password, and domain in another manner (i.e. through -a querystring), you can execute the login command below. -*/ +Below is a sample login attempt +*/ /* $(document).ready(function() { @@ -55,26 +50,13 @@ $(document).ready(function() { //var url = "/client/api?command=login&username="+username+"&password="+password+"&domain="+domain+"&response=json"; // Test URL - var url = "/client/api?command=login&username=admin&password=password&domain=ROOT&response=json"; + var url = "/client/api?command=login&username=admin&password=5f4dcc3b5aa765d61d8327deb882cf99&domain=%2F&response=json"; $.ajax({ url: url, dataType: "json", async: false, - success: function(json) { - $.cookie('username', json.loginresponse.username); - $.cookie('role', json.loginresponse.type); - $.cookie('hypervisortype', json.loginresponse.hypervisortype); - $.cookie('domainid', '1'); //e.g. domainid of ROOT domain is 1 - $.cookie('account', json.loginresponse.account); - $.cookie('directattachnetworkgroupsenabled', json.loginresponse.directattachnetworkgroupsenabled); - - $.cookie('timezoneoffset', null); //comment this line and uncomment the next line if you want to set a specific timezone offset. Otherwise, default timezone from browser will be used. - //$.cookie('timezoneoffset', '5.75'); //e.g. Timezone "Kathmandu" is 'UTC+05:45'. Thus, its timezoneoffset is '5.75' - - $.cookie('timezone', null); //comment this line and uncomment the next line if you want to set a specific timezone. This value is used for any default timezone dropdown - //$.cookie('timezone', 'America/Los_Angeles'); - - $.cookie('sessionKey', json.loginresponse.sessionkey); + success: function(json) { + g_loginResponse = json.loginresponse; }, error: function() { // This means the login failed. You should redirect to your login page. diff --git a/ui/scripts/cloud.core.init.js b/ui/scripts/cloud.core.init.js index 8012f47561a..71046f7fa4a 100644 --- a/ui/scripts/cloud.core.init.js +++ b/ui/scripts/cloud.core.init.js @@ -766,32 +766,53 @@ $(document).ready(function() { initDialogWithOK("dialog_info_please_select_one_item_in_middle_menu", 350, false); // Check whether the session is valid. - g_mySession = $.cookie("JSESSIONID"); - g_sessionKey = $.cookie("sessionKey"); - g_role = $.cookie("role"); - g_username = $.cookie("username"); - g_account = $.cookie("account"); - g_domainid = $.cookie("domainid"); - g_timezone = $.cookie("timezone"); - g_directAttachSecurityGroupsEnabled = $.cookie("directattachsecuritygroupsenabled"); - g_userPublicTemplateEnabled = $.cookie("userpublictemplateenabled"); - - if($.cookie("timezoneoffset") != null) - g_timezoneoffset = isNaN($.cookie("timezoneoffset"))?null: parseFloat($.cookie("timezoneoffset")); - else - g_timezoneoffset = null; - - if (!g_directAttachSecurityGroupsEnabled || g_directAttachSecurityGroupsEnabled.length == 0) - g_directAttachSecurityGroupsEnabled = "false"; + if (g_loginResponse == null) { + g_mySession = $.cookie("JSESSIONID"); + g_sessionKey = $.cookie("sessionKey"); + g_role = $.cookie("role"); + g_username = $.cookie("username"); + g_account = $.cookie("account"); + g_domainid = $.cookie("domainid"); + g_timezone = $.cookie("timezone"); + g_directAttachSecurityGroupsEnabled = $.cookie("directattachsecuritygroupsenabled"); + g_userPublicTemplateEnabled = $.cookie("userpublictemplateenabled"); - if (!g_userPublicTemplateEnabled || g_userPublicTemplateEnabled.length == 0) - g_userPublicTemplateEnabled = "true"; + if($.cookie("timezoneoffset") != null) + g_timezoneoffset = isNaN($.cookie("timezoneoffset"))?null: parseFloat($.cookie("timezoneoffset")); + else + g_timezoneoffset = null; + + if (!g_directAttachSecurityGroupsEnabled || g_directAttachSecurityGroupsEnabled.length == 0) + g_directAttachSecurityGroupsEnabled = "false"; + + if (!g_userPublicTemplateEnabled || g_userPublicTemplateEnabled.length == 0) + g_userPublicTemplateEnabled = "true"; + } else { + g_mySession = $.cookie('JSESSIONID'); + g_sessionKey = encodeURIComponent(g_loginResponse.sessionkey); + g_role = g_loginResponse.type; + g_username = g_loginResponse.username; + g_account = g_loginResponse.account; + g_domainid = g_loginResponse.domainid; + g_timezone = g_loginResponse.timezone; + g_timezoneoffset = g_loginResponse.timezoneoffset; + } $.ajax({ data: createURL("command=listCapabilities"), dataType: "json", async: false, success: function(json) { + if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) { + g_userPublicTemplateEnabled = ""+json.listcapabilitiesresponse.capability.userpublictemplateenabled; + $.cookie('userpublictemplateenabled', g_userPublicTemplateEnabled, { expires: 1}); + } + + if (json.listcapabilitiesresponse.capability.securitygroupsenabled != null) { + g_directAttachSecurityGroupsEnabled = ""+json.listcapabilitiesresponse.capability.securitygroupsenabled; + $.cookie('directattachsecuritygroupsenabled', g_directAttachSecurityGroupsEnabled, { expires: 1}); + } + buildSecondLevelNavigation(); $("#main_username").text(g_username); showLeftNavigationBasedOnRole();