Plugins and JAAS

47 views
Skip to first unread message

Rob McDougall

unread,
Nov 9, 2020, 5:12:48 PM11/9/20
to pf4j
I'm experiencing an issue that I think is related to the PluginClassLoader.

I have a plugin that is intended to connect to FileNet.  We've included the FileNet libraries in the plugin jar.  We've got code that works fine when run in a standalone but fails when run within the plugin.  We get an error message "No LoginModule found for com.filenet.api.util.WSILoginModule".

I've done some investigation of the issue and here is what I think is happening.  The plugin code calls the FIleNet libraries.  The FileNet libraries call the JAAS api (part of the Java runtime).  I believe the JAAS code is unable to find the WSILoginModule because it resides in the FileNet libraries.

My thought is that when the call to JAAS happens, the PluginClassLoader doesn't find it, so it delegates to the SystemClassLoader which finds and runs the JAAS code.  When the JAAS code looks for the WSILoginModule, it uses the SystemClassLoader which knows nothing about the FileNet libraries in the plugin.

1) Does this make sense to you guys (I'm assuming that you know more about how the class loaders interact than I do and can perhaps tell me that I'm wrong)?

2) Is there a workaround for this that does not involve me modifying the application that loads the plugin?  (I'd prefer not to modify that application if I can help it.) 

3) Is there any way to make libraries in the plugin .jar visible to the SystemClassLoader?

Any help would be appreciated.

Regards,
Rob

deceba...@gmail.com

unread,
Nov 9, 2020, 5:31:23 PM11/9/20
to pf4j
Hi,

First of all, please give more details about the context of your application as:
- Java version
- OS
- PF4J version

You have multiple solution here. First, you need to identify how PluginClassLoader loads classes. For this, you need to put the log of PluginClassLoader on TRACE.
After this step you will know if a class is loaded by PluginClassLoader or it is loaded by parent class loader.
You have the possibility to modify the plugin class loading strategy (but this is another story).
So, switch the logger level of PluginClassLoader on TRACE and gather information about PluginClassLoader.

Regards,
Decebal

Rob McDougall

unread,
Nov 9, 2020, 7:47:12 PM11/9/20
to deceba...@gmail.com, pf4j
  • So, switch the logger level of PluginClassLoader on TRACE and gather information about PluginClassLoader.

 

OK, I will do that and let you know what I find tomorrow.

 

In the meantime, to answer your other questions:

- Java version

Java 11

 

- OS

Windows

 

- PF4J version

3.4.1

 

Thanks for helping me with this…

 

Regards,

Rob

 

Rob McDougall | Senior Technical Architect | 4Point | +1.613.907.6415 | www.4Point.com

Receive our news and announcements before anyone else - follow us on:

Twitter icon - small  linkedin icon  - small  Facebook icon - small

--
You received this message because you are subscribed to a topic in the Google Groups "pf4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pf4j/u5CONBO0odI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pf4j+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pf4j/3f6d3232-343e-49f0-ae71-316874b511can%40googlegroups.com.

Rob McDougall

unread,
Nov 10, 2020, 11:53:13 AM11/10/20
to deceba...@gmail.com, pf4j

I've attached the whole log, but I think the important section is here:

2020-11-10 10:31:57.083 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Found class 'com.filenet.apiimpl.core.UserPasswordToken$1' in PLUGIN classpath

2020-11-10 10:31:57.083 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Received request to load class 'javax.security.auth.login.LoginContext'

2020-11-10 10:31:57.083 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Couldn't find class 'javax.security.auth.login.LoginContext' in PLUGIN classpath

2020-11-10 10:31:57.084 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Search in dependencies for class 'javax.security.auth.login.LoginContext'

2020-11-10 10:31:57.084 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Couldn't find class 'javax.security.auth.login.LoginContext' in DEPENDENCIES classpath

2020-11-10 10:31:57.085 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Found class 'javax.security.auth.login.LoginContext' in APPLICATION classpath

2020-11-10 10:31:57.085 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Received request to load class 'com.filenet.apiimpl.core.UserPasswordCallback'

2020-11-10 10:31:57.086 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Found class 'com.filenet.apiimpl.core.UserPasswordCallback' in PLUGIN classpath

2020-11-10 10:31:57.087 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Received request to load class 'com.filenet.apiimpl.util.ApiToEngineBridge'

2020-11-10 10:31:57.088 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Found class 'com.filenet.apiimpl.util.ApiToEngineBridge' in PLUGIN classpath

(Exception occurs here, I think)

2020-11-10 10:31:57.169 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Received request to load class 'com.filenet.api.exception.ExceptionCode'

2020-11-10 10:31:57.185 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Received request to load class 'com.filenet.apiimpl.util.LString'

2020-11-10 10:31:57.186 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Found class 'com.filenet.apiimpl.util.LString' in PLUGIN classpath

2020-11-10 10:31:57.186 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Found class 'com.filenet.api.exception.ExceptionCode' in PLUGIN classpath

2020-11-10 10:31:57.202 TRACE 26252 --- [http-nio-8080-exec-1] org.pf4j.PluginClassLoader               : Received request to load class 'com.filenet.api.exception.ErrorLoggingLevel'

 

I’ve also done some investigation and the code that appears to be throwing the exception (based on the stack trace) is this (from javax.security.auth.login.LoginContext):

 

                    if (moduleStack[i].module == null) {

                        try {

                            @SuppressWarnings("deprecation")

                            Object tmp = Class.forName(name, false, contextClassLoader).newInstance();

                            moduleStack[i].module = (LoginModule) tmp;

                            if (debug != null) {

                                debug.println(name + " loaded via reflection");

                            }

                        } catch (ClassNotFoundException e) {

                            throw new LoginException("No LoginModule found for "

                                    + name);

                        }

                    }

 

The contextClassLoader is initialized with this code (also from javax.security.auth.login.LoginContext):       });

        contextClassLoader = java.security.AccessController.doPrivileged

                (new java.security.PrivilegedAction<ClassLoader>() {

                public ClassLoader run() {

                    ClassLoader loader =

                            Thread.currentThread().getContextClassLoader();

                    if (loader == null) {

                        // Don't use bootstrap class loader directly to ensure

                        // proper package access control!

                        loader = ClassLoader.getSystemClassLoader();

                    }

 

                    return loader;

                }

        });

 

I don’t have a lot of experience with class loaders, but I’m assuming that it’s using the system class loader and that is why it is not finding the class in the plugin.

--
You received this message because you are subscribed to the Google Groups "pf4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pf4j+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pf4j/YTBPR01MB2559C5A04DF96E8A0FC3A12BCAE90%40YTBPR01MB2559.CANPRD01.PROD.OUTLOOK.COM.

formsfeeder.log

Rob McDougall

unread,
Nov 12, 2020, 2:49:21 PM11/12/20
to deceba...@gmail.com, pf4j
  • You have the possibility to modify the plugin class loading strategy (but this is another story).

 

Based on the research I’ve done, I think I’m going to need to modify the class loading strategy.  It looks like the PluginClassLoader is not the loader looking for the class and that’s why it is not being found.

 

Any idea how I can make a class contained in the plugin available to the System class loader?

Rob McDougall

unread,
Nov 12, 2020, 5:14:23 PM11/12/20
to deceba...@gmail.com, pf4j

OK, I seem to have worked around the issue by performing the following:

                this.prevClassLoader = Thread.currentThread().getContextClassLoader();

      Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());      // Set the context classloader to the my classloader.

 

Later on, I set it back to the original setting before returning back from the plugin.

deceba...@gmail.com

unread,
Nov 14, 2020, 3:21:06 PM11/14/20
to pf4j
I'm glad you found a solution. Thank you for sharing your solution!
Reply all
Reply to author
Forward
0 new messages