Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  Active Directory-Persongroups

    Posted 12/06/24 07:45 AM

    Hello everyone,

    We have a request from user to manage  Person groups through Active Directory. We were able to import Person groups into maximo with the help of a script that I will provide later. However, persons who are in groups in AD cannot be synchronized to Person Groups in Maximo. Does anyone have any ideas for upgrading this code or creating a new script.
    The script is triggered by an escalation every few minutes and in this way Person groups are imported into Maximo.
    SCRIPT:

    from psdi.server import MXServer
    from psdi.mbo import MboConstants
    from java.util import Hashtable  
    from javax.naming.directory import InitialDirContext, SearchControls  

    # LDAP settings
    ldap_url = "??????????"  
    search_base = "ou=????,ou=?????,dc=????dc=local"
    user = "?????????"  
    password = "'??????"

    # Create a Hashtable and populate it with LDAP configuration
    env = Hashtable()
    env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory")
    env.put("java.naming.provider.url", ldap_url)
    env.put("java.naming.security.authentication", "simple")
    env.put("java.naming.security.principal", user)  
    env.put("java.naming.security.credentials", password)
    env.put("java.naming.referral", "follow")  

    # Try to connect to LDAP using the Hashtable
    try:
        ctx = InitialDirContext(env)  

        # Set up search controls to search for groups in AD
        searchControls = SearchControls()
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE)

        # Search for user groups in AD
        results = ctx.search(search_base, "(objectClass=group)", searchControls)

        # Get the Maximo security context using the correct API
        securityContext = MXServer.getMXServer().getSecurityContext()

        # Retrieve UserInfo for MAXADMIN user (or any other user that is authorized)
        user_info = MXServer.getMXServer().getUserInfo("MAXADMIN")  

        # Get the Maximo MboSet for person groups
        mboSet = MXServer.getMXServer().getMboSet("PERSONGROUP", user_info)  
        mboSet.setWhere("1=1")  # Get all existing person groups
        mboSet.reset()

        # Create a list of existing group names in Maximo
        existing_groups = {}
        mboSet.moveFirst()  # Start from the first record in the MboSet
        while mboSet.moveNext():  # Iterate through the MboSet
            group_name = mboSet.getString("PERSONGROUP")  
            existing_groups[group_name] = mboSet.getMbo() 

        # Process each group from Active Directory
        while results.hasMore():
            group = results.next()
            group_name = group.getAttributes().get("cn").get()

            # Check if the group already exists in Maximo
            if group_name not in existing_groups:
                # Group doesn't exist, create a new person group
                new_group = mboSet.add()  # Add a new Mbo
                new_group.setValue("PERSONGROUP", group_name, MboConstants.NOACCESSCHECK)  
                new_group.setValue("DESCRIPTION", "Imported from AD: " + group_name, MboConstants.NOACCESSCHECK)  

        # Save the changes to all MBOs in the set
        mboSet.save()  

        # Clean up
        ctx.close()
        mboSet.cleanup()

    except Exception as e:
        # Handle any exceptions
        print("Error: " + str(e))


    Thank you



    ------------------------------
    Dario Stjepanović
    ------------------------------


  • 2.  RE: Active Directory-Persongroups

    Posted 12/09/24 04:13 AM
    Edited by Andreas Brieke 12/09/24 04:25 AM

    Hi Dario,

    what is the error you are getting?

    I can tell you that in our scripts to retrieve data from Active Directory i have an additional line to set which attributes i want to get:

    searchContext = SeachControls()
    searchContext.setSearchScope(SearchControls.SUBTREE_SCOPE)
    #one of those:
    #searchContext.setReturningAttributes(None) # None -> All attributes
    #searchContext.setReturningAttributes(['cn','name','displayName']) # Array-> selected attributes
    #searchContext.setReturningAttributes([]) # empty Array-> no attributes

    In addition, Active Directory normally answers with paged results. You need to handle this in your script also, see Paged Results Control

    Oracle remove preview
    Paged Results Control
    This JNDI Java tutorial describes Java Naming and Directory Interface (JNDI) technology, naming and directory operations, and LDAP
    View this on Oracle >

    . If you need help with this contact me, i currently don't have the scripts at hand.



    ------------------------------
    Andreas Brieke
    IT Service Management Consultant
    SVA System Vertrieb Alexander GmbH
    ------------------------------