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ć
------------------------------