By: Abhinay B. user 02 Nov 2018 at 4:11 a.m. CDT

4 Responses
Abhinay B. gravatar
I am having trouble importing from a JAR file in custom authentication. The name of the jar is ed.jar and below is a code snippet that works in Jython (tested by running in my system): ``` import os,glob,sys, site from org.python.util import jython for jar in glob.glob(os.path.join(directory,'*.jar')): #directory contains the ed.jar to import as well as its depencies sys.path.append(jar) import ed #ed is the JAR to import. ``` I added the same above lines to a custom script in Gluu: ``` from java.util import Arrays from org.apache.http.params import CoreConnectionPNames 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.model.config import ConfigurationFactory from org.xdi.oxauth.service import UserService, AuthenticationService, SessionIdService from org.xdi.oxauth.service.net import HttpService from org.xdi.oxauth.util import ServerUtil from org.xdi.util import StringHelper from org.xdi.oxauth.service import EncryptionService from java.util import Arrays, HashMap, IdentityHashMap import java import datetime import urllib import sys import json #code that I added starts here import os,glob,site from org.python.util import jython #the next few lines find the location of directory containing the jar files jar_location = jython().getClass().getProtectionDomain().getCodeSource().getLocation().getPath() jar_location = jar_location.rsplit("/",1)[0] directory = jar_location + '/external/' #add all the jars as done in previous code for jar in glob.glob(os.path.join(directory,'*.jar')): sys.path.append(jar) import ed class PersonAuthentication(PersonAuthenticationType): ``` I get the following error (in oxauth_script.log): ``` org.python.core.PyException: null at org.python.core.Py.ImportError(Py.java:334) ~[jython-standalone-2.7.1.jar:?] at org.python.core.imp.import_first(imp.java:879) ~[jython-standalone-2.7.1.jar:?] at org.python.core.imp.import_module_level(imp.java:964) ~[jython-standalone-2.7.1.jar:?] at org.python.core.imp.importName(imp.java:1057) ~[jython-standalone-2.7.1.jar:?] at org.python.core.ImportFunction.__call__(__builtin__.java:1280) ~[jython-standalone-2.7.1.jar:?] at org.python.core.PyObject.__call__(PyObject.java:450) ~[jython-standalone-2.7.1.jar:?] at org.python.core.__builtin__.__import__(__builtin__.java:1232) ~[jython-standalone-2.7.1.jar:?] at org.python.core.imp.importOneAs(imp.java:1093) ~[jython-standalone-2.7.1.jar:?] at org.python.pycode._pyx289.f$0(allowed_countries.py:50) ~[?:?] at org.python.pycode._pyx289.call_function(allowed_countries.py) ~[?:?] at org.python.core.PyTableCode.call(PyTableCode.java:171) ~[jython-standalone-2.7.1.jar:?] at org.python.core.PyCode.call(PyCode.java:18) ~[jython-standalone-2.7.1.jar:?] at org.python.core.Py.runCode(Py.java:1614) ~[jython-standalone-2.7.1.jar:?] at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:296) ~[jython-standalone-2.7.1.jar:?] at org.xdi.service.PythonService.loadPythonScript(PythonService.java:179) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.PythonService$Proxy$_$$_WeldClientProxy.loadPythonScript(Unknown Source) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager.createExternalTypeFromStringWithPythonException(CustomScriptManager.java:372) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager$Proxy$_$$_WeldSubclass.createExternalTypeFromStringWithPythonException(Unknown Source) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager.createExternalType(CustomScriptManager.java:340) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager.reloadCustomScriptConfigurations(CustomScriptManager.java:253) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager.reloadImpl(CustomScriptManager.java:153) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager.reload(CustomScriptManager.java:141) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager.reloadTimerEvent(CustomScriptManager.java:118) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.custom.script.CustomScriptManager$Proxy$_$$_WeldSubclass.reloadTimerEvent(Unknown Source) [oxcore-service-3.1.4.Final.jar:?] at sun.reflect.GeneratedMethodAccessor135.invoke(Unknown Source) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181] at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:129) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124) [cdi-api-2.0.SP1.jar:${parsedVersion.osgiVersion}] at org.jboss.weld.util.Observers.notify(Observers.java:166) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:177) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:159) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:632) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.jboss.weld.util.ForwardingBeanManager.fireEvent(ForwardingBeanManager.java:104) [weld-core-impl-3.0.5.Final.jar:3.0.5.Final] at org.xdi.service.timer.TimerJob.execute(TimerJob.java:37) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.timer.JobExecutionDelegate.execute(JobExecutionDelegate.java:29) [oxcore-service-3.1.4.Final.jar:?] at org.xdi.service.timer.JobExecutionDelegate$Proxy$_$$_WeldClientProxy.execute(Unknown Source) [oxcore-service-3.1.4.Final.jar:?] at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz-2.2.3.jar:?] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.3.jar:?] 2018-11-02 08:51:24,795 ERROR [oxAuthScheduler_Worker-5] [org.xdi.service.custom.script.CustomScriptManager] (CustomScriptManager.java:342) - Failed to prepare external type 'org.xdi.exception.PythonException: Failed to load python file 'java.io.ByteArrayInputStream@7ab1fc6f'' 2018-11-02 08:51:24,802 INFO [oxAuthScheduler_Worker-5] [org.xdi.service.PythonService$PythonLoggerOutputStream] (PythonService.java:239) - Permission dynamic scope. Destroy 2018-11-02 08:51:24,803 INFO [oxAuthScheduler_Worker-5] [org.xdi.service.PythonService$PythonLoggerOutputStream] (PythonService.java:239) - Permission dynamic scope. Destroyed successfully 2018-11-02 08:51:24,813 INFO [oxAuthScheduler_Worker-5] [org.xdi.service.PythonService$PythonLoggerOutputStream] (PythonService.java:239) - Permission dynamic scope. Initialization 2018-11-02 08:51:24,814 INFO [oxAuthScheduler_Worker-5] [org.xdi.service.PythonService$PythonLoggerOutputStream] (PythonService.java:239) - Permission dynamic scope. Initialized successfully ``` Why is the above error occuring?

By Aliaksandr Samuseu staff 02 Nov 2018 at 8:02 a.m. CDT

Aliaksandr Samuseu gravatar
Custom scripts and any indepth modifications are not covered by Community support, sorry.

By Abhinay B. user 02 Nov 2018 at 8:09 a.m. CDT

Abhinay B. gravatar
I understand that customization is beyond the scope. But just tell me if it is possible to import a jar file in the custom scripts. No need to tell me the method. I want to know whether am searching in the wrong direction.

By Michael Schwartz staff 02 Nov 2018 at 9:25 a.m. CDT

Michael Schwartz gravatar
See [Customize Public Pages](https://gluu.org/docs/ce/3.1.4/operation/custom-design/#directory-structure-and-mappings) ``` Customized libs for oxAuth to use should be placed in the following directories: /opt/gluu/jetty/identity/custom/libs /opt/gluu/jetty/oxauth/custom/libs ```

By Abhinay B. user 02 Nov 2018 at 10:21 a.m. CDT

Abhinay B. gravatar
Thank you for the guidance!