Trigger log4j loading prior to context classloader (elastic/x-pack-elasticsearch#4355)

OpenSAML requires that the context classloader be set to the
classloader that contains the opensaml jar files in order to
initialise itself. However, sometimesrthis seems to cause the
classloading for slf4j/log4j to take place while that context
classloader is set, which fails.

This change forces slf4j/log4j to be initialised prior to setting
the context classloader.

Original commit: elastic/x-pack-elasticsearch@85ed8eb488
This commit is contained in:
Tim Vernum 2018-04-17 11:04:31 +10:00 committed by GitHub
parent fa44406cea
commit 7cd99d2f96
1 changed files with 3 additions and 1 deletions

View File

@ -52,8 +52,8 @@ import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.core.xml.util.XMLObjectSupport;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.saml2.core.Assertion;
import org.opensaml.saml.saml2.core.NameID;
import org.opensaml.saml.saml2.core.Response;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
@ -81,6 +81,8 @@ public class SamlUtils {
*/
static void initialize(Logger logger) throws PrivilegedActionException {
if (INITIALISED.compareAndSet(false, true)) {
// We want to force these classes to be loaded _before_ we fiddle with the context classloader
LoggerFactory.getLogger(InitializationService.class);
SpecialPermission.check();
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
logger.debug("Initializing OpenSAML");