Thursday, 19 September 2019

Maximo Automation Script with Ldap

Hi Today we are going to connect to LDAP and query Ldap's data using Maximo Automation Script


Steps:- 
1. Define Ldap Attributes
2. Create a hashtable and put those attributes
3. Create a Context
4. Create a Search Control
5. Search using Context and Search Control
6. Loop through results and get required ldap attribute using criteria defined.

***************************************************************************

from javax.naming import *
from java.util import *
from javax.naming.directory import *
from psdi.mbo import SqlFormat

//Step 1 
print "Starting Ldap querying from Maximo"

ldapurl="ldap:serverurl:port"
ldapuser="XXXX"
ldappassword="XXXX"
ldapbasedn="DC=something,DC=com"


//Step 2
ldaptable=Hashtable()
ldaptable.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory")
ldaptable.put(Context.PROVIDER_URL, ldapurl)
ldaptable.put(Context.SECURITY_AUTHENTICATION, "simple")
ldaptable.put(Context.SECURITY_PRINCIPAL,ldapuser)
ldaptable.put(Context.SECURITY_CREDENTIALS,ldappassword)

//Step 3

ctx =InitialDirContext(ldaptable) //Step4srch =SearchControls()
srch.setSearchScope(SearchControls.SUBTREE_SCOPE) //Step 6//To get email id of a person with person id Adam results=ctx.search(ldapbasedn,"Adam",srch) allattributes=results.getattributes() emailed=allattributes.get("emailed")

No comments:

Post a Comment