By: Dibyajyoti Parida user 26 Nov 2019 at 11:21 p.m. CST

10 Responses
Dibyajyoti Parida gravatar
I have installed python-ldap library inside the gluu server container. (pip install python-ldap) My goal is to import the ldap module inside the interception script. But its showing like the following error Caused by: Traceback (most recent call last): File "py_ldap.py", line 14, in <module> File "/opt/gluu/python/libs/ldap/__init__.py", line 22, in <module> import _ldap ImportError: No module named _ldap Please help me on this. Regards.

By Mohit Mali staff 26 Nov 2019 at 11:27 p.m. CST

Mohit Mali gravatar
Hi Dibyajyoti Parida, Thanks for reaching out gluu support , I will assist you on this ticket , let me pull information from script developer and get back to you asap. Thanks and Regards Mohit Mali

By Dibyajyoti Parida user 26 Nov 2019 at 11:32 p.m. CST

Dibyajyoti Parida gravatar
Thanks Mohit Mali, It would be great, if I can get the solution in shorter time period. Regards. Dibyajyoti Parida

By Mohit Mali staff 26 Nov 2019 at 11:59 p.m. CST

Mohit Mali gravatar
hi Dibyajyoti Parida, I just get some information from developer ,the step that’s missing is opening the file /etc/gluu/conf/ox-ldap.properties, finding the property entry pythonModulesDir and appending the value /opt/jython-<version>/Lib/site-packages to the existing value. Directories appended there are column separated (:) Hope this will resolve your issue. Thanks and Regards Mohit Mali

By Mohit Mali staff 27 Nov 2019 at 1:45 a.m. CST

Mohit Mali gravatar
Hi DibyaJyoti, I had a word with my senior developer , we cannot using any python module which require c compilation because in gluu we are using jython rather than python so pip install won't work , you can still use java native library for ldap. ``` # Jython LDAP Example from javax.naming import * from java.util import * from javax.naming.directory import * # Credentials to access LDAP user = "cn=Directory Manager" passwd = "TopSEcret" # Query starting point and query target search_start = "ou=people,o=gluu" search_target = "(objectClass=gluuPerson)" # Setup LDAP Context Options settings = Hashtable() settings.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory") settings.put(Context.PROVIDER_URL, "ldaps://localhost:1636") settings.put(Context.SECURITY_PRINCIPAL, user) settings.put(Context.SECURITY_CREDENTIALS, passwd) # Connect to LDAP Server ctx = InitialDirContext(settings) srch = SearchControls() srch.setSearchScope(SearchControls.SUBTREE_SCOPE) # Execute LDAP Search results = ctx.search(search_start, search_target, srch ) #Display Search for result in results: attributes = result.getAttributes() for atr in attributes.getAll(): print atr print "-"*20 ```

By Dibyajyoti Parida user 27 Nov 2019 at 4:22 a.m. CST

Dibyajyoti Parida gravatar
Hi Mohit Mali, when I am trying with the code you have shared, its showing the the error below org.gluu.exception.PythonException: Failed to load python file 'java.io.ByteArrayInputStream@306ba90b' at org.gluu.service.PythonService.loadPythonScript(PythonService.java:184) at org.gluu.service.PythonService$Proxy$_$$_WeldClientProxy.loadPythonScript(Unknown Source) at org.gluu.service.custom.script.CustomScriptManager.createExternalTypeFromStringWithPythonException(CustomScriptManager.java:390) at org.gluu.service.custom.script.CustomScriptManager$Proxy$_$$_WeldSubclass.createExternalTypeFromStringWithPythonException(Unknown Source) at org.gluu.service.custom.script.CustomScriptManager.createExternalType(CustomScriptManager.java:358) at org.gluu.service.custom.script.CustomScriptManager.reloadCustomScriptConfigurations(CustomScriptManager.java:268) at org.gluu.service.custom.script.CustomScriptManager.reloadImpl(CustomScriptManager.java:157) at org.gluu.service.custom.script.CustomScriptManager.reload(CustomScriptManager.java:144) at org.gluu.service.custom.script.CustomScriptManager.reloadTimerEvent(CustomScriptManager.java:120) at org.gluu.service.custom.script.CustomScriptManager$Proxy$_$$_WeldSubclass.reloadTimerEvent(Unknown Source) at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95) at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85) at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:168) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286) at javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124) at org.jboss.weld.util.Observers.notify(Observers.java:166) at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285) at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273) at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:177) at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:159) at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:632) at org.jboss.weld.util.ForwardingBeanManager.fireEvent(ForwardingBeanManager.java:104) at org.gluu.service.timer.TimerJob.execute(TimerJob.java:39) at org.gluu.service.timer.JobExecutionDelegate.execute(JobExecutionDelegate.java:31) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: Traceback (most recent call last): File "jython_ldap.py", line 15, in <module> ImportError: No module named directory

By Mohit Mali staff 27 Nov 2019 at 5:48 a.m. CST

Mohit Mali gravatar
Hi Dibyajyoti Parida, ok we are looking on this , may i know what is your objective to achieve by writing those script ?. Thanks and Regards Mohit Mali

By Dibyajyoti Parida user 27 Nov 2019 at 5:57 a.m. CST

Dibyajyoti Parida gravatar
Hi Mohit Mali, We are trying to authenticate users whose password is stored in LDAP. We have to do it through interception script. Basic need is to fetch something from LDAP from interception script.

By Dibyajyoti Parida user 27 Nov 2019 at 7:35 a.m. CST

Dibyajyoti Parida gravatar
Hi Mohit, We seek your urgent help on this . We are importing necessesary classes/modules as below but why its failing with javax.naming.directory ? Often its also failing complaining about javax or java.util.Hastable etc. ``` import java import javax from org.xdi.service.cdi.util import CdiUtil from org.xdi.oxauth.security import Identity from org.xdi.model.custom.script.type.auth import PersonAuthenticationType from org.xdi.oxauth.service import AuthenticationService from org.xdi.util import StringHelper from javax.naming import Context from java.util import Hashtable from java.naming.directory import SearchControls from java.naming.directory import InitialDirContext ``` Please suggest how we can use these native java classes.

By William Lowe user 02 Dec 2019 at 7:12 p.m. CST

William Lowe gravatar
I believe this has been resolved. Dibyajyoti, can you please post notes about your resolution?

By Dibyajyoti Parida user 31 Dec 2019 at 1:55 a.m. CST

Dibyajyoti Parida gravatar
we did not go python way..we went jython way and we never required any library.