Identity policy script example (advanced approach)

Identity policies can be defined dynamically through the use of JavaScript (the advanced approach). Policies can also be defined with the basic method (which does not require any JavaScript). JavaScript can use all standard functions and programming constructs, including loops and conditional branches..

The values of personal attributes can be retrieved with ISIM specific JavaScript functions. The context of the script is a user (person) for whom the identity is being generated. A JavaScript object that represents the person within ISIM data model named subject represents this context.

The following example illustrates the advanced mode of creating user IDs with the uid attribute (or given name, if the uid attribute is empty) for an individual. The script also checks whether the user ID is already used. If the user ID is already in use, the script adds a number to the end of the user ID, making it unique. .

function createIdentity() {
  var EXISTING_CASE = 0;
  var UPPER_CASE = 1;
  var LOWER_CASE = 2;
  var tf = false;
  var identity = "";
  var baseidentity = "";
  var counter = 0;
  var locale = subject.getProperty("erlocale");
  var fAttrKey = "uid";
  var sAttrKey = "";
  var idx1 = 0;
  var idx2 = 0;
  var fCase = 2;
  var sCase = 2;
  if ((locale != null) && (locale.length > 0)) {
    locale = locale[0];
  }  if (locale == null || locale.length == 0)
    locale = "";
  var firstAttribute = "";
  var secondAttribute = "";
  if (((fAttrKey != null) && (fAttrKey.length > 0)) || ((sAttrkey != null) 
  && (sAttrkey.length > 0))) {
    if ((fAttrKey != null) && (fAttrKey.length > 0)) {
      firstAttribute = subject.getProperty(fAttrKey);
      if (((firstAttribute != null) && (firstAttribute.length > 0)))
        firstAttribute = firstAttribute[0];
      if (firstAttribute == null || firstAttribute.length == 0)
        firstAttribute = "";
      else {
        firstAttribute = IdentityPolicy.resolveAttribute(fAttrKey, 
        firstAttribute);
        if ((idx1 > firstAttribute.length) || (idx1 == 0))
          idx1 = firstAttribute.length;
        firstAttribute = firstAttribute.substring(0, idx1);
      }      if (fCase == UPPER_CASE)
        firstAttribute = firstAttribute.toUpperCase(locale);
      else if (fCase == LOWER_CASE)
        firstAttribute = firstAttribute.toLowerCase(locale);
    }    if ((sAttrKey != null) && (sAttrKey.length > 0)) {
      secondAttribute = subject.getProperty(sAttrKey);
      if (((secondAttribute != null) && (secondAttribute.length > 0)))
        secondAttribute = secondAttribute[0];
      if (secondAttribute == null || secondAttribute.length == 0)
        secondAttribute = "";
      else {
        secondAttribute = IdentityPolicy.resolveAttribute(sAttrKey, 
			secondAttribute);
        if ((idx2 > secondAttribute.length) || (idx2 == 0))
          idx2 = secondAttribute.length;
        secondAttribute = secondAttribute.substring(0, idx2);
      }      if (sCase == UPPER_CASE)
        secondAttribute = secondAttribute.toUpperCase(locale);
      else if (sCase == LOWER_CASE)
        secondAttribute = secondAttribute.toLowerCase(locale);
    }    baseidentity = firstAttribute + secondAttribute;
  }  if ((baseidentity == null) || (baseidentity.length == 0)) {
    var givenname = subject.getProperty("givenname");
    if (((givenname != null) && (givenname.length > 0)))
      givenname = givenname[0];
    if (givenname == null || givenname.length == 0)
      givenname = "";
    else
      givenname = givenname.substring(0, 1);
    baseidentity = givenname + subject.getProperty("sn")[0];
  }  tf = IdentityPolicy.userIDExists(baseidentity, false, false);
  if (!tf) {
    return baseidentity;
  }  while (tf) {
    counter+=1;
    identity = baseidentity + counter;
    tf = IdentityPolicy.userIDExists(identity, false, false);
  }  return identity;
}return createIdentity();

Parent topic: Identity policies