Siebel CRM Desktop for IBM Notes Administration Guide > Customizing Authentication > CRM Desktop SSO Objects You Can Customize >

Example Code That Customizes CRM Desktop SSO


The following code comes predefined with CRM Desktop:

include("utils.js", "_utils");
include("core.js", "_core");
_utils.logger = logger;
_utils.sso_client = sso_client;
_core.sso_client = sso_client;
_core.settings_cache = settings_cache;

var Utils = _utils.Utils;
var Lib = _core.Lib;
var CookieManager = new Lib.CookieManager();
var SSOConfiguration = {
  "CookieBuffer": "DomainCookies",
  "AuthType": settings.get("AuthType"),
  "EndpointRegExp": settings.get("EndpointRegExp"),
  "SuccessLoginRegExp": settings.get("SuccessLoginRegExp")
};
var interactive_params = {
  "InitialWidth": 1024,
  "InitialHeight": 768,
  "InitialTitle": "SSO",
  "InitialTitlePrefix": "SSO",
  "CheckFn": InteractiveCheckFunction
};

var persistent_cookies = true;

sso_client.request_handler = process_request;

function InteractiveCheckFunction (ia_state, ia_result, original_request) {
  var path = (original_request.get_object()).replace(/\//i,"").split("?");

  if (SSOConfiguration.EndpointRegExp == "") {
    is_original_url = ( (ia_state.url).toLowerCase() ).indexOf((original_request.get_server() + path[0]).toLowerCase() ) != -1;
  } else {
  is_original_url = (new RegExp(SSOConfiguration.EndpointRegExp,
'i')).test(ia_state.url)
  }
  if (!is_original_url && ia_state.status == "before") {
  persistent_cookies = false;
  }
  if (ia_state.status == "finished" && ia_state.html_body != "") {
    if (is_original_url) {
      var regexp = SSOConfiguration.SuccessLoginRegExp == "" ? "FAULTSTRING.
*?10944629" : SSOConfiguration.SuccessLoginRegExp;

if ( ia_state.html_body.match( new RegExp(regexp,'mi') ) != null) {
return true;
}
}
}
return false;
}
function RequestData(request, clear_session) {
if (GetCache() !== "" && CookieManager.GetAllCookies().length == 0) {
Utils.SetRequestCookies(request, GetCache());
}
var response = Lib.ExecuteRequest(request, CookieManager, clear_session);
if (CookieManager.GetAllCookies().length > 0) {
UpdateCache(CookieManager.GetAllCookiesAsString());
}
return response;
}
function RedefineInteractiveDescriptor (response, redefine_location) {
return function (descriptor, ia_state) {
Utils.Log("Clear browser cookies", "info");
var cookies = Utils.ParseCookieString(ia_state.cookies);
var cookie = {};
for (var i = 0, len = cookies.length; i < len; i++) {
cookie = Utils.ParseCookie(cookies[i]);
ia_state.cookies = cookie.Name + "=;";
}
if (response !== null) {
if (redefine_location) {
descriptor.SetEndpoint(Utils.GetSpecificHeader(response.get_headers(),
"Location")[0]);
}
}
return descriptor;
}
}
function UpdateCache (value) {
Utils.Log("Update cache cookies", "info");
var cached = Utils.ParseCookies(Utils.ParseCookieString(GetCache()));
var browser = Utils.ParseCookies(Utils.ParseCookieString(value));
for (var i = 0, iLen = browser.length; i < iLen; i++) {
isset = false;
for (var j = 0, jLen = cached.length; j < jLen; j++) {

if (browser[i].Name == cached[j].Name) {
isset = true;
cached[j] = browser[i];
}
}
if(!isset) {
cached.push(browser[i]);
}
}
settings_cache.set(SSOConfiguration.CookieBuffer,CookieManager.ConvertCookiesToString(cached));
}
function ClearCache () {
settings_cache.set(SSOConfiguration.CookieBuffer, "");
}
function GetCache() {
return settings_cache.get(SSOConfiguration.CookieBuffer);
}
function process_request(sso_client_request) {
var ignore_cache = settings.get("IgnoreCache");
var response;
if (SSOConfiguration.AuthType == "NTLM") {
var creds = sso_client_request.get_credentials();
creds.set_username('');
creds.set_password('');
creds.set_auth_schemes('n');
response = sso_client.execute_request(sso_client_request);
if (response == null) Utils.Log("No response received", "warning");
} else {
var request_x_type = Utils.GetSpecific-
Header(sso_client_request.get_headers(), "X-CRMD-TYPE");
if (request_x_type == "verify" && ignore_cache == "1") {
ClearCache();
}
response = RequestData(sso_client_request, false);
var status_code = response.get_status_code();
if (request_x_type == "logout") {
response = null;
} else if (status_code == "401" || status_code == "407") {
Utils.Throw("not_valid", "script_not_valid_sso_ntlm_attempt");

Utils.Log("Attempt to use SSO mode with NTLM-protected EAI", "info");
return null;
} else if (status_code == "302" || Utils.Transitions.IsHtml(response)) {
var redefine = status_code == "302" ? true : false;
Utils.Log("Interactive mode initialized", "info");
var result = Lib.RunInteractive(sso_client_request, interactive_params,
CookieManager, RedefineInteractiveDescriptor(response, redefine));
if (result == "success") {
if (persistent_cookies == true && ignore_cache == "1" && settings.
get("UserChanged") == "1") {
Utils.Throw("not_valid", "script_not_valid_clear_cookies");
Utils.Log("Persistent cookies exist", "info");
return null;
} else {
persistent_cookies = true;
Utils.Log("Login successful", "info");
}
} else if (result == "canceled") {
Utils.Log("Login canceled", "info");
sso_client.raise_cancel_exception("User canceled login dialog.");
return null;
}
Utils.Log("Interactive mode finished", "info");
response = RequestData(Utils.CloneRequest(sso_client,
sso_client_request, null), true);
}
}
return response;
}

Siebel CRM Desktop for IBM Notes Administration Guide Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.