Moving ClassLoader creation before Authorizer instantiation
This closes
@@ -315,9 +315,17 @@ public class AuthorizerFactoryBean implements FactoryBean, DisposableBean, UserG
throw new Exception(String.format("Multiple bundles found for the specified authorizer class '%s', only one is allowed.", authorizerClassName));
}
+ // start with ClassLoad from authorizer's bundle
final Bundle authorizerBundle = authorizerBundles.get(0);
ClassLoader authorizerClassLoader = authorizerBundle.getClassLoader();
+ // if additional classpath resources were specified, replace with a new ClassLoader that wraps the original one
+ if (StringUtils.isNotEmpty(classpathResources)) {
+ logger.info(String.format("Replacing Authorizer ClassLoader for '%s' to include additional resources: %s", identifier, classpathResources));
+ URL[] urls = ClassLoaderUtils.getURLsForClasspath(classpathResources, null, true);
+ authorizerClassLoader = new URLClassLoader(urls, authorizerClassLoader);
+ }
+
// get the current context classloader
final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
@@ -348,11 +356,6 @@ public class AuthorizerFactoryBean implements FactoryBean, DisposableBean, UserG
}
}
- if (StringUtils.isNotEmpty(classpathResources)) {
- URL[] urls = ClassLoaderUtils.getURLsForClasspath(classpathResources, null, true);
- authorizerClassLoader = new URLClassLoader(urls, authorizerClassLoader);
- }
-
return AuthorizerFactory.withNarLoader(instance, authorizerClassLoader);
}
