UserID Generation Logic: Creating Unique IDs via Business Logic Task Handler (BLTH)
search cancel

UserID Generation Logic: Creating Unique IDs via Business Logic Task Handler (BLTH)

book

Article ID: 100765

calendar_today

Updated On:

Products

CA Identity Manager CA Identity Suite

Issue/Introduction

This article provides a Business Logic Task Handler (BLTH) sample to automate UserID creation within CA Identity Manager. The logic generates a unique ID based on a combination of user attributes and includes an automated incrementing mechanism to prevent duplicate IDs.

UserID Generation Logic:

  • Format: [First Character of First Name] + [First Character of Last Name] + [Incrementing Character] + [Department Number]
  • Example: For a user named 'John Doe' in department '0200', the initial UserID will be jda0200.
  • Conflict Handling: If jda0200 already exists, the third character increments (e.g., jdb0200jdc0200) until a unique ID is found.

Environment

Identity Manager 14.x & v15

Resolution

To implement this custom UserID generation logic, follow the steps below:

 

  1. Prerequisites
    ⚠️ IMPORTANT: Always test custom code in a non-production environment. Ensure you have a full backup of your Identity Manager configuration before implementing BLTH changes.

  2. Implementation Steps
    Create a new Java class named BLTHsetUID extending BLTHAdapter.
    Implement the handleValidation method to extract %FIRST_NAME%, %LAST_NAME%, and departmentNumber.
    Use the provided logic to generate and validate the unique UserID string.
    Compile the code and deploy the resulting JAR file to the Identity Manager library path.

  3. Code Sample (Java)

package com.ca.identitymanager.myblth;

import com.netegrity.imapi.BLTHAdapter;
import com.netegrity.imapi.BLTHContext;
import com.netegrity.ims.exception.IMSException;
import com.netegrity.llsdk6.imsapi.exception.NoSuchObjectException;
import com.netegrity.llsdk6.imsapi.managedobject.User;
import com.netegrity.llsdk6.imsapi.provider.UserProvider;

public class BLTHsetUID extends BLTHAdapter {
    public void handleValidation(BLTHContext blthContext) throws Exception {
        User user = blthContext.getUser();
        
        String FirstName = user.getAttribute("%FIRST_NAME%");
        String LastName = user.getAttribute("%LAST_NAME%");
        String departmentNumber = user.getAttribute("departmentNumber");

        if (FirstName.isEmpty() || LastName.isEmpty() || departmentNumber.isEmpty()) {
            // this message will be presented on the screen
            IMSException imsEx = new IMSException();
            imsEx.addUserMessage("Failed to build an UID, first name, last name and department number are required");
            throw imsEx;
        }
        String UID = FirstName.substring(0, 1) + LastName.substring(0, 1) + 'a' + departmentNumber;
        UserProvider userbis = blthContext.getUserProvider();
        
        for (char c='a'; c<='z'; c++){      
          try {
                UID = FirstName.substring(0, 1) + LastName.substring(0, 1) + c + departmentNumber;
                userbis.findUser(UID, null);
                //UID already exists, search for next computed one
                if (c=='z') {
                    // this message will be presented on the screen
                    IMSException imsEx = new IMSException();
                    imsEx.addUserMessage("Failed to find an UID, all UIDs already exist");
                    throw imsEx;
                }
          } catch (NoSuchObjectException nso){break;}
        }

        try {
           blthContext.getUser().setAttribute("%USER_ID%", UID);
        } catch (Exception ex) {
            // this message will be presented on the screen
            IMSException imsEx = new IMSException();
            imsEx.addUserMessage("Failed to set an UID" + ex.getMessage());
            throw imsEx;
        }
    }
}

Additional Information

Adapt with your department Number attribute name or well known name and other specific requirements.