[KEYCLOAK-17100] Testsuite Wildfly initialization error on Windows

[KEYCLOAK-17392] Java CLASSPATH is wrongly parsed on Windows

Signed-off-by: Jan Lieskovsky <jlieskov@redhat.com>
Co-Authored-By: Peter Zaoral <pzaoral@redhat.com>
This commit is contained in:
Jan Lieskovsky 2021-03-14 11:43:17 +01:00 committed by Hynek Mlnařík
parent e126969f82
commit 5fac80b05e
2 changed files with 34 additions and 31 deletions

View file

@ -584,53 +584,56 @@ public class AuthServerTestEnricher {
public static void setJsseSecurityProviderForOutboundSslConnectionsOfElytronClient(@Observes(precedence = 100) StartSuiteContainers event) { public static void setJsseSecurityProviderForOutboundSslConnectionsOfElytronClient(@Observes(precedence = 100) StartSuiteContainers event) {
log.info( log.info(
"Determining the JSSE security provider to use for outbound " + "Determining the JSSE security provider to use for outbound " +
"SSL/TLS connections of the Elytron client..." "SSL/TLS connections of the Elytron client"
); );
/** First locate the wildfly-config.xml to use. Per:
* https://docs.wildfly.org/21/Client_Guide.html#wildfly-config-xml-discovery
*
* 1) try to load it from the 'wildfly.config.url' property
*/
String wildflyConfigXmlPath = System.getProperty("wildfly.config.url");
// 2) If not set, scan the classpath // Use path to wildfly-config.xml directly if specified
String wildflyConfigXmlPath =
System.getProperty("wildfly-client.config.path");
// Otherwise scan the classpath to determine its location
if (wildflyConfigXmlPath == null) { if (wildflyConfigXmlPath == null) {
log.debug("Scanning classpath to locate wildfly-config.xml..."); log.debug("Scanning classpath to locate wildfly-config.xml");
final String javaClassPath = System.getProperty("java.class.path"); final String javaClassPath = System.getProperty("java.class.path");
for (String dir : javaClassPath.split(":")) { for (String dir : javaClassPath.split(File.pathSeparator)) {
if (!dir.isEmpty()) { if (!dir.isEmpty()) {
String candidatePath = dir + File.separator + String candidatePath = dir + File.separator +
"wildfly-config.xml"; "wildfly-config.xml";
if (new File(candidatePath).exists()) { if (new File(candidatePath).exists()) {
wildflyConfigXmlPath = candidatePath; wildflyConfigXmlPath = candidatePath;
log.debugf( log.debugf(
"Using wildfly-config.xml at '%s' location!", "Found wildfly-config.xml at '%s' location",
wildflyConfigXmlPath wildflyConfigXmlPath
); );
break; break;
} }
} }
} }
}
final File wildflyConfigXml = ( wildflyConfigXmlPath != null ) ?
new File(wildflyConfigXmlPath) :
null;
// Throw an error if wildfly-config.xml path specified directly via the
// 'wildfly-client.config.path' property doesn't represent a regular file
// on the file system, or if it wasn't found by scanning the classpath
if ( wildflyConfigXml == null || ! wildflyConfigXml.exists() ) {
throw new RuntimeException(
"Failed to locate the wildfly-config.xml to use for " +
"the configuration of Elytron client"
);
} else { } else {
log.debugf( log.debugf(
"Using wildfly-config.xml from 'wildfly.config.url' " + "Using wildfly-config.xml from '%s' location",
"property at '%s' location",
wildflyConfigXmlPath wildflyConfigXmlPath
); );
} }
// If still not found, that's an error
if (wildflyConfigXmlPath == null) {
throw new RuntimeException(
"Failed to locate the wildfly-config.xml to use for " +
"the configuration of Elytron client!"
);
}
/** Determine the name of the system property from wildfly-config.xml /** Determine the name of the system property from wildfly-config.xml
* holding the name of the security provider which is used by Elytron * holding the name of the security provider which is used by Elytron
* client to define its SSL context for outbound SSL connections. * client to define its SSL context for outbound SSL connections.
*/ */
final File wildflyConfigXml = new File(wildflyConfigXmlPath);
String jsseSecurityProviderSystemProperty = null; String jsseSecurityProviderSystemProperty = null;
try { try {
DocumentBuilder documentBuilder = DocumentBuilderFactory DocumentBuilder documentBuilder = DocumentBuilderFactory
@ -642,7 +645,7 @@ public class AuthServerTestEnricher {
if (nodeList.getLength() != 1) { if (nodeList.getLength() != 1) {
throw new RuntimeException( throw new RuntimeException(
"Failed to locate the 'provider-name' element " + "Failed to locate the 'provider-name' element " +
"in wildfly-config.xml XML file!" "in wildfly-config.xml XML file"
); );
} }
String providerNameElement = nodeList.item(0).getAttributes() String providerNameElement = nodeList.item(0).getAttributes()
@ -655,12 +658,12 @@ public class AuthServerTestEnricher {
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(String.format( throw new RuntimeException(String.format(
"Error reading the '%s' file. Please make sure the provided " + "Error reading the '%s' file. Please make sure the provided " +
"path is correct and retry!", "path is correct and retry",
wildflyConfigXml.getAbsolutePath() wildflyConfigXml.getAbsolutePath()
)); ));
} catch (ParserConfigurationException|SAXException e) { } catch (ParserConfigurationException|SAXException e) {
throw new RuntimeException(String.format( throw new RuntimeException(String.format(
"Failed to parse the '%s' XML file!", "Failed to parse the '%s' XML file",
wildflyConfigXml.getAbsolutePath() wildflyConfigXml.getAbsolutePath()
)); ));
} }
@ -677,7 +680,7 @@ public class AuthServerTestEnricher {
} else { } else {
throw new RuntimeException( throw new RuntimeException(
"Failed to determine the name of system property " + "Failed to determine the name of system property " +
"holding JSSE security provider's name for Elytron client!" "holding JSSE security provider's name for Elytron client"
); );
} }
@ -725,7 +728,7 @@ public class AuthServerTestEnricher {
} else { } else {
throw new RuntimeException( throw new RuntimeException(
"The SunJSSE provider is not present " + "The SunJSSE provider is not present " +
"on the platform!" "on the platform"
); );
} }
} }
@ -738,11 +741,11 @@ public class AuthServerTestEnricher {
} else { } else {
throw new RuntimeException( throw new RuntimeException(
"Cannot identify a security provider for Elytron client " + "Cannot identify a security provider for Elytron client " +
"offering the TLSv1.2 capability!" "offering the TLSv1.2 capability"
); );
} }
log.infof( log.infof(
"Using the '%s' JSSE provider!", platformJsseProvider.getName() "Using the '%s' JSSE provider", platformJsseProvider.getName()
); );
} }
} }
@ -780,7 +783,7 @@ public class AuthServerTestEnricher {
administration.reloadIfRequired(); administration.reloadIfRequired();
} else { } else {
log.info("## The Auth Server has already configured TLS. Skipping... ##"); log.info("## The Auth Server has already configured TLS. Skipping ##");
} }
} }

View file

@ -659,7 +659,7 @@
~ Used for Wildfly Elytron 1.13.0.CR3+ RESTEasy client SSL truststore configuration. ~ Used for Wildfly Elytron 1.13.0.CR3+ RESTEasy client SSL truststore configuration.
~ See KEYCLOAK-15692, ELY-1891 issues & PRs of EAP7-1219 issue for details. ~ See KEYCLOAK-15692, ELY-1891 issues & PRs of EAP7-1219 issue for details.
--> -->
<wildfly.config.url>${project.build.directory}/dependency/wildfly-config.xml</wildfly.config.url> <wildfly-client.config.path>${project.build.directory}${file.separator}dependency${file.separator}wildfly-config.xml</wildfly-client.config.path>
</systemPropertyVariables> </systemPropertyVariables>
<properties> <properties>
<property> <property>