diff --git a/BrowserExtensions/common/casajar/content/bandit.gif b/BrowserExtensions/common/casajar/content/bandit.gif new file mode 100644 index 00000000..19c373eb Binary files /dev/null and b/BrowserExtensions/common/casajar/content/bandit.gif differ diff --git a/BrowserExtensions/common/casajar/content/casaOverlay.js b/BrowserExtensions/common/casajar/content/casaOverlay.js index fe738c21..e352ab12 100644 --- a/BrowserExtensions/common/casajar/content/casaOverlay.js +++ b/BrowserExtensions/common/casajar/content/casaOverlay.js @@ -5,6 +5,181 @@ var bGlobalPrompt = 'true'; var consoleService = null; var loginCounter = 0; var sAttemptedHost = ''; +var IAWindow; +var props = null; +var sCurrentPersona = "home"; +var bShowValues = false; + + +function dumpRealms() +{ + logMessage("dumpRealms called"); + var realms = Packages.Jim.getRealms("jim_realms.xml"); +} + + +function writeTestKey() +{ + writeCASASetting("Bandit", "ldapdn", "cn=bandit1,o=novell"); + writeCASASetting("Bandit", "password", "11111111"); + writeCASASetting("Bandit", "ftoBalance", "100"); + writeCASASetting("Bandit", "costCenter", "Marketing"); + writeCASASetting("Bandit", "sn", "CASA Last Name"); + writeCASASetting("Bandit", "facsimileTelephoneNumber", "111-222-3333"); + writeCASASetting("Bandit", "postalAddress", "Los Angeles"); + writeCASASetting("Bandit", "manager", "CASA Manager"); + writeCASASetting("Bandit", "mail", "casa@novell.com"); + writeCASASetting("Bandit", "telephoneNumber", "999-999-8888"); + writeCASASetting("Bandit", "givenName", "CASA First name"); + writeCASASetting("Bandit", "kBalance", "100000"); + writeCASASetting("Bandit", "cn", "Casa"); + writeCASASetting("Bandit", "title", "My House"); + writeCASASetting("Bandit", "creditCard", "9999-8888-7777-6666"); + writeCASASetting("Bandit", "salary", "The same as Steve Jobs"); +} + +function writeCASASetting(sID, sKey, sValue) +{ + var obj = getMiCASAStore(); + try + { + res = obj.miCASAWriteKey(sID, sKey, sValue); + } + catch (err) + { + alert(err); + } +} + + +function readTestKey() +{ + readCASASetting("Bandit", "ldapdn"); + readCASASetting("Bandit", "password"); +} + +function readCASASetting(sID, sKey) +{ + var obj = getMiCASAStore(); + var theValue = new String(); + logMessage("Reading from CASA: " + sKey); + try + { + res = obj.miCASAReadKey(sID, sKey, theValue); + logMessage("rcode:"+res + " sValue:"+theValue.value); + + } + catch (err) + { + logMessage(err); + } + + return theValue.value; +} + +function getCASAData(arraySelected) +{ + var htData = new java.util.Hashtable(); + + for (var i=0; i 0)) + { + htData.put(arraySelected[i], sValue); + } + + + } + return htData; +} + +function getPeristentPersona() +{ + try + { + var props = loadMapFileAndReturnProps(); + var sPersona = props.getProperty("CurrentPersona"); + return sPersona; + } + catch (error) + { + return "home"; + } + +} + + +function setLocalPersona() +{ + sCurrentPersona = "home"; + changePersona(sCurrentPersona); + if (bShowValues) + { + showAttribsWithValues(); + } +} + +function setEnterprisePersona() +{ + sCurrentPersona = "work"; + changePersona(sCurrentPersona); + if (bShowValues) + { + showAttribsWithValues(); + } +} + +function setCombinedPersona() +{ + sCurrentPersona = "joined"; + changePersona(sCurrentPersona); + if (bShowValues) + { + showAttribsWithValues(); + } +} + +function setCasaPersona() +{ + sCurrentPersona = "CASA"; + changePersona(sCurrentPersona); + if (bShowValues) + { + showAttribsWithValues(); + } +} + +function displayCurrentPersona() +{ + var curPersonaIDElement = document.getElementById("curPersonaID"); + if (curPersonaIDElement != null) + { + curPersonaIDElement.value = sCurrentPersona; + } +} + + +function changePersona(persona) +{ + logMessage("Changing persona to: "+persona); + + try + { + var props = loadMapFileAndReturnProps(); + props.setProperty("CurrentPersona", persona); + storeProperties(props); + } + catch (err) + { + alert(err); + } + sCurrentPersona = persona; + displayCurrentPersona(); +} + function logMessage(message) { @@ -24,16 +199,207 @@ function logMessage(message) } } +function showConsole() +{ + var jvm = Components.classes["@mozilla.org/oji/jvm-mgr;1"].getService(Components.interfaces.nsIJVMManager); + if (jvm != null) + { + jvm.showJavaConsole(); + } + else + { + logMessage("No JVM"); + alert("No JVM"); + } +} + +function displayUserDir() +{ + alert(java.lang.System.getProperty("user.dir")); +} + +function displayUserHome() +{ + alert(java.lang.System.getProperty("user.home")); +} + +function displayJavaInfo() +{ + alert("Version: " + java.lang.System.getProperty("java.version") + "\r\nClassPath: " + java.lang.System.getProperty("java.class.path")); +} + + +function storeProperties(props) +{ + var userdir = java.lang.System.getProperty("user.dir"); + logMessage("looking for namemap.properties in " + userdir); + + try + { + var os = java.io.FileOutputStream(userdir + "/namemap.properties"); + props.store(os,null); + os.close(); + } + catch (error) + { + alert(error); + } +} + +function loadMapFileAndReturnProps() +{ + try + { + var userdir = java.lang.System.getProperty("user.dir"); + logMessage("looking for namemap.properties in " + userdir); + + var is = java.io.FileInputStream(userdir + "/namemap.properties"); + //alert(is); + + props = new java.util.Properties(); + props.load(is); + is.close(); + logMessage(props); + return props; + } + catch (ioerror) + { + logMessage(ioerror); + } +} + +function mapAttrib(sName) +{ + if (sName == null) return; + if (sName.indexOf('opt.')==0) + { + //sName = sName.substring(4); + } + + if (props == null) + { + props = loadMapFileAndReturnProps(); + if (props == null) + { + logMessage("did not load props"); + return sName; + } + } + + var newName = props.getProperty(sName); + //alert(newName); + if (newName != null) + { + logMessage("found mapped name: " + newName); + return newName; + } + else + { + logMessage("did not find mapped name: " + sName); + return sName; + } + +} + + +function mapName(sName) +{ + if (sName.indexOf('opt.')==0) + { + //sName = sName.subString(4); + } + + switch (sName) + { + case "cn": + return 'User_name'; + break; + case "mail": + return 'Email_Address'; + break; + case "mailStop": + return 'Post-office'; + break; + case "jobCode": + return 'Job_Code'; + break; + case "costCenter": + return 'Cost.Center'; + break; + case "givenName": + return 'First_name'; + break; + case "workForceId": + return 'EmployeID'; + break; + } + + return sName; + +} + + + +function handleIA(attribs) +{ + + var attribsRequested = attribs.split(','); + var params = ''; + for (var i=0; i= para.length) ; j++) { @@ -133,7 +517,7 @@ function websso() if (para.item(j).type == "password") { formToSubmit = para.item(j).parentNode.parentNode; - + // did we get it? if (formToSubmit.type != "form") { @@ -309,8 +693,462 @@ function promptuser() var contentwidth = window.innerWidth; window.moveTo((sw-contentwidth)/2 , (sh-contentheight)/2); + } + var bAllSelected = false; + function toogleAllAttribsOptional() + { + var lstBoxOpt = document.getElementById('attribListOptional'); + var bttnSelectAll = document.getElementById('selectall'); + + if (bAllSelected) + { + lstBoxOpt.clearSelection(); + bAllSelected = false; + bttnSelectAll.label = "Select All "; + } + else + { + + lstBoxOpt.selectAll(); + bAllSelected = true; + bttnSelectAll.label = " Clear All"; + } + } + + function selectAllAttribsOptional() + { + var lstBoxOpt = document.getElementById('attribListOptional'); + var bttnSelectAll = document.getElementById('selectall'); + lstBoxOpt.selectAll(); + bAllSelected = true; + bttnSelectAll.label = " Clear All"; + } + + function selectAllAttribs() + { + var lstBox = document.getElementById('attribList'); + lstBox.selectAll(); + } + + function getAllValues(arraySelected) + { + var sUser = readCASASetting("Bandit", "ldapdn"); + var sPass = readCASASetting("Bandit", "password"); + + if (sUser != null) + { + logMessage("CASA returned:"+sUser); + } + else + { + logMessage("SecretID Bandit not found"); + sUser = "cn=admin,o=novell"; + } + + + var htData; + if (sCurrentPersona == "CASA") + { + htData = getCASAData(arraySelected); + } + else + { + try + { + logMessage(" ********* Calling IA"); + htData = Packages.Jim.main2("cn=bandit1,o=Novell", sPass, null, sCurrentPersona, arraySelected); + logMessage(" ******** Returned"); + } + catch (err) + { + logMessage(" ******** Error calling IA: " + err); + } + } + return htData; + } + + function toogleShowHide() + { + var bttn = document.getElementById('bttnShowValues'); + + clearBoxes(); + + if (bShowValues) + { + bShowValues = false; + setAttribs(); + if (bttn != null) + { + bttn.label = "Show Values"; + } + } + else + { + bShowValues = true; + showAttribsWithValues(); + if (bttn != null) + { + bttn.label = "Hide Values"; + } + } + } + + function showAttribsWithValues() + { + logMessage("showAttribsWithValues called"); + + bShowValues = true; + sCurrentPersona = getPeristentPersona(); + displayCurrentPersona(); + + var parentHost = opener._content.location.host; + var label = document.getElementById('hostsite'); + label.value = parentHost; + + var url = document.location.toString(); + var sAttrib = ""; + var sDisplay = ""; + + var lstBox = document.getElementById('attribList'); + var lstBoxOpt = document.getElementById('attribListOptional'); + + var params = url.substring(url.indexOf('?')+1).split('&'); + + var csvRequested = ""; + //collect requested attribs and query IA for values + for (var i = 0; !(i > params.length - 1); i++) + { + sAttrib = params[i].substring(0, params[i].indexOf('=')); + sDisplay = params[i].substring(params[i].indexOf('=')+1); + + if (sAttrib.length > 0) + { + + if (sAttrib.indexOf('opt') == 0) + { + csvRequested += sAttrib.substring(4); + } + else + { + csvRequested += sAttrib; + } + } + + // append comma + if (i < params.length -2) + { + csvRequested += ','; + } + } + + //alert(csvRequested); + + // query all values requested + var arrayRequested = csvRequested.split(','); + var htValues = getAllValues(arrayRequested); + + //alert(htValues); + // clear the current listboxes + clearBoxes(); + + var sCurrentValue = ''; + for (var i = 0; !(i > params.length - 1); i++) + { + sAttrib = params[i].substring(0, params[i].indexOf('=')); + sDisplay = params[i].substring(params[i].indexOf('=')+1); + + if (sAttrib.length > 0) + { + // reset sCurrentValue + sCurrentValue = ''; + + if (sAttrib.indexOf('opt') == 0) + { + sCurrentValue = htValues.get(sAttrib.substring(4)); + if (sCurrentValue != null) + { + sCurrentValue = " (" + sCurrentValue + ")"; + } + else + { + sCurrentValue = ''; + } + + lstBoxOpt.appendItem(mapAttrib(sDisplay.substring(4)) + sCurrentValue, sAttrib.substring(4)); + } + else + { + //alert("getting: " + sAttrib); + //alert(htValues); + sCurrentValue = htValues.get(sAttrib); + if (sCurrentValue != null) + { + sCurrentValue = " (" + sCurrentValue + ")"; + } + else + { + sCurrentValue = ''; + } + + lstBox.appendItem(sDisplay + sCurrentValue, sAttrib); + } + } + } + + selectAllAttribs(); + centerPrompt(); + } + + function clearBoxes() + { + // clear required + var lstBox = document.getElementById('attribList'); + + for (var i=lstBox.getRowCount(); i>0; i--) + { + lstBox.removeItemAt(i-1); + } + + // clear optional + lstBox = document.getElementById('attribListOptional'); + for (var i=lstBox.getRowCount(); i>0; i--) + { + lstBox.removeItemAt(i-1); + } + } + + + + function setAttribs() + { + logMessage("setAttribs called"); + + sCurrentPersona = getPeristentPersona(); + changePersona(sCurrentPersona); + + var parentHost = opener._content.location.host; + var label = document.getElementById('hostsite'); + label.value = parentHost; + + var url = document.location.toString(); + var sAttrib = ""; + var sDisplay = ""; + + var lstBox = document.getElementById('attribList'); + var lstBoxOpt = document.getElementById('attribListOptional'); + + var params = url.substring(url.indexOf('?')+1).split('&'); + + for (var i = 0; !(i > params.length - 1); i++) + { + sAttrib = params[i].substring(0, params[i].indexOf('=')); + sDisplay = params[i].substring(params[i].indexOf('=')+1); + + if (sAttrib.length > 0) + { + + if (sAttrib.indexOf('opt') == 0) + { + lstBoxOpt.appendItem(mapAttrib(sDisplay.substring(4)), sAttrib.substring(4)); + } + else + { + lstBox.appendItem(sDisplay, sAttrib); + } + } + } + + selectAllAttribs(); + centerPrompt(); + } + + function getSelectedPersona() + { + var personaLst = document.getElementById('theList'); + var personaSelected = personaLst.selectedItems; + return personaSelected[0].value + } + + function getSelectedAttribsOptional() + { + var lstBox = document.getElementById('attribListOptional'); + var selected = lstBox.selectedItems; + return selected; + } + + function displaySelectedAttribsOptional() + { + var selected = getSelectedAttribsOptional(); + for (var i=0; i 0)) + { + var repostURL = opener._content.location + "?"; + var keys = htData.keys(); + while (keys.hasMoreElements()) + { + var sKey = keys.nextElement(); + var sValue = htData.get(sKey); + repostURL += (sKey + "=" + sValue); + if (keys.hasMoreElements()) + repostURL += "&"; + } + + opener._content.location = repostURL; + + } + + // close this window + window.close(); + + } + + function closeWin() { @@ -393,7 +1231,7 @@ function promptuser() { if (sValue.length > 0) { - logMessage('Writing ' + secretID + ' : ' + sKey + ' : xxxxxxx'); + logMessage('Writing ' + secretID + '[' + secretID.length + '] : ' + sKey + ' : xxxxxxx'); try { res = obj.miCASAWriteKey(secretID, sKey, sValue); if (res != 0) diff --git a/BrowserExtensions/common/casajar/content/debug.xul b/BrowserExtensions/common/casajar/content/debug.xul new file mode 100644 index 00000000..d43da4f7 --- /dev/null +++ b/BrowserExtensions/common/casajar/content/debug.xul @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +