Simplified the single signon process

This commit is contained in:
will 2011-01-26 11:16:02 -08:00
parent 6d72b45379
commit 2f91af1fba
3 changed files with 54 additions and 50 deletions

View File

@ -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 <b><span id="zone_
message.add.cluster.zone=Add a hypervisor managed cluster for zone <b><span id="zone_name"></span></b>
message.add.primary.storage=Add a new Primary Storage for zone <b><span id="zone_name"></span></b>, pod <b><span id="pod_name"></span></b>
message.add.ip.range.to.pod=<p>Add an IP range to pod: <b><span id="pod_name_label"></span></b></p>
message.secondary.storage=Add a new storage for zone <b><span id="zone_name"></span></b>
message.add.secondary.storage=Add a new storage for zone <b><span id="zone_name"></span></b>
message.number.zones=<h2><span> # of </span> Zones</h2>
message.number.pods=<h2><span> # of </span> Pods</h2>
message.number.clusters=<h2><span> # of </span> Clusters</h2>

View File

@ -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.

View File

@ -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();