NIFI-6904 Moving ClassLoader creation before Authorizer instantiation

This closes #3903
This commit is contained in:
Bryan Bende 2019-11-25 09:13:20 -05:00 committed by Matt Gilman
parent ac5bacccb8
commit dd620680b1
No known key found for this signature in database
GPG Key ID: DF61EC19432AEE37
1 changed files with 9 additions and 6 deletions

View File

@ -158,7 +158,7 @@ public class AuthorizerFactoryBean implements FactoryBean, DisposableBean, UserG
if (authorizers.containsKey(authorizer.getIdentifier())) {
throw new Exception("Duplicate Authorizer identifier in Authorizers configuration: " + authorizer.getIdentifier());
}
authorizers.put(authorizer.getIdentifier(), createAuthorizer(authorizer.getIdentifier(), authorizer.getClazz(),authorizer.getClasspath()));
authorizers.put(authorizer.getIdentifier(), createAuthorizer(authorizer.getIdentifier(), authorizer.getClazz(), authorizer.getClasspath()));
}
// configure each authorizer
@ -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);
}