BLTH for UserID creation
search cancel

BLTH for UserID creation

book

Article ID: 100765

calendar_today

Updated On:

Products

CA Identity Manager CA Identity Governance CA Identity Portal CA Risk Analytics CA Secure Cloud SaaS - Arcot A-OK (WebFort) CLOUDMINDER ADVANCED AUTHENTICATION CA Secure Cloud SaaS - Advanced Authentication CA Secure Cloud SaaS - Identity Management CA Secure Cloud SaaS - Single Sign On

Issue/Introduction

I am looking for a blth where i need to create a user ID based on following conditions
UserID=(First Character of First Name + First character of Last Name + 'a' + DepartmentNumber)
For Example:
First name: <FirstName>
Last Name: <LastName>
Department: 0200
UserID = <UserID>
if the generated user id already exist then we can increment the character at 3 position to b.
in that case new UserID will be abc0200


Environment

Release:
Component: IDMGR

Resolution

package com.ca.identitymanager.guiph01;

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.