From 9fa50bded5f557cff08d7db34ac2dfd272325bac Mon Sep 17 00:00:00 2001 From: vramik Date: Mon, 12 Jun 2017 11:28:49 +0200 Subject: [PATCH] was-wls changes --- testsuite/integration-arquillian/pom.xml | 7 ++ .../adapter/servlet/SendUsernameServlet.java | 3 +- .../arquillian/AppServerTestEnricher.java | 8 ++ .../DeploymentArchiveProcessor.java | 73 ++++++++++++++++++- .../org/keycloak/testsuite/util/IOUtil.java | 1 - .../tests/other/adapters/pom.xml | 2 + .../tests/other/adapters/was/README.md | 19 +++++ .../adapters/was/common/xslt/arquillian.xsl | 53 ++++++++++++++ .../tests/other/adapters/was/pom.xml | 45 ++++++++++++ .../tests/other/adapters/was/was8/pom.xml | 50 +++++++++++++ .../adapter/WASSAMLFilterAdapterTest.java | 9 +++ .../adapters/wls/common/xslt/arquillian.xsl | 54 ++++++++++++++ .../tests/other/adapters/wls/pom.xml | 45 ++++++++++++ .../tests/other/adapters/wls/wls12/pom.xml | 48 ++++++++++++ .../adapter/WLSSAMLFilterAdapterTest.java | 9 +++ 15 files changed, 420 insertions(+), 6 deletions(-) create mode 100644 testsuite/integration-arquillian/tests/other/adapters/was/README.md create mode 100644 testsuite/integration-arquillian/tests/other/adapters/was/common/xslt/arquillian.xsl create mode 100644 testsuite/integration-arquillian/tests/other/adapters/was/pom.xml create mode 100644 testsuite/integration-arquillian/tests/other/adapters/was/was8/pom.xml create mode 100644 testsuite/integration-arquillian/tests/other/adapters/was/was8/src/test/java/org/keycloak/testsuite/adapter/WASSAMLFilterAdapterTest.java create mode 100644 testsuite/integration-arquillian/tests/other/adapters/wls/common/xslt/arquillian.xsl create mode 100644 testsuite/integration-arquillian/tests/other/adapters/wls/pom.xml create mode 100644 testsuite/integration-arquillian/tests/other/adapters/wls/wls12/pom.xml create mode 100644 testsuite/integration-arquillian/tests/other/adapters/wls/wls12/src/test/java/org/keycloak/testsuite/adapter/WLSSAMLFilterAdapterTest.java diff --git a/testsuite/integration-arquillian/pom.xml b/testsuite/integration-arquillian/pom.xml index 0c90c57cba..0bcb2b899b 100644 --- a/testsuite/integration-arquillian/pom.xml +++ b/testsuite/integration-arquillian/pom.xml @@ -46,6 +46,7 @@ 2.0.1.Final 2.1.0.Alpha3 2.1.0.Alpha2 + 1.0.1.Final 1.2.0.Beta2 2.2.2 1.0.0.Alpha2 @@ -108,6 +109,12 @@ wildfly-arquillian-container-domain-managed ${arquillian-wildfly-container.version} + + org.jboss.arquillian.container + arquillian-wls-remote-12.1.x + ${arquillian-wls-container.version} + test + diff --git a/testsuite/integration-arquillian/test-apps/servlets/src/main/java/org/keycloak/testsuite/adapter/servlet/SendUsernameServlet.java b/testsuite/integration-arquillian/test-apps/servlets/src/main/java/org/keycloak/testsuite/adapter/servlet/SendUsernameServlet.java index f5690a5822..2c0b17d1d2 100755 --- a/testsuite/integration-arquillian/test-apps/servlets/src/main/java/org/keycloak/testsuite/adapter/servlet/SendUsernameServlet.java +++ b/testsuite/integration-arquillian/test-apps/servlets/src/main/java/org/keycloak/testsuite/adapter/servlet/SendUsernameServlet.java @@ -25,6 +25,7 @@ import org.keycloak.adapters.spi.AuthenticationError; import org.keycloak.saml.processing.core.saml.v2.constants.X500SAMLProfileConstants; import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -47,7 +48,7 @@ import java.util.List; * @version $Revision: 1 $ */ @Path("/") -public class SendUsernameServlet { +public class SendUsernameServlet extends HttpServlet { private static boolean checkRoles = false; private static SamlAuthenticationError authError; diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java index 92646f4f5e..bc83338dbd 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java @@ -133,6 +133,14 @@ public class AppServerTestEnricher { return getAppServerQualifier(testClass).contains("tomcat"); } + public static boolean isWASAppServer(Class testClass) { + return getAppServerQualifier(testClass).contains("was"); + } + + public static boolean isWLSAppServer(Class testClass) { + return getAppServerQualifier(testClass).contains("wls"); + } + public static boolean isOSGiAppServer(Class testClass) { String q = getAppServerQualifier(testClass); return q.contains("karaf") || q.contains("fuse"); diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/DeploymentArchiveProcessor.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/DeploymentArchiveProcessor.java index 2f1f8419d8..79b0365878 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/DeploymentArchiveProcessor.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/DeploymentArchiveProcessor.java @@ -26,8 +26,15 @@ import org.jboss.arquillian.test.spi.annotation.ClassScoped; import org.jboss.logging.Logger; import org.jboss.logging.Logger.Level; import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ArchivePath; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.Node; +import org.jboss.shrinkwrap.api.asset.ClassAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.jboss.shrinkwrap.resolver.api.maven.MavenFormatStage; +import org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem; import org.keycloak.adapters.servlet.KeycloakOIDCFilter; import org.keycloak.representations.adapters.config.AdapterConfig; import org.keycloak.testsuite.arquillian.annotation.UseServletFilter; @@ -35,18 +42,29 @@ import org.keycloak.testsuite.util.IOUtil; import org.keycloak.util.JsonSerialization; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; -import javax.xml.transform.TransformerException; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.hasAppServerContainerAnnotation; import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.isRelative; import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.isTomcatAppServer; +import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.isWLSAppServer; +import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.isWASAppServer; import static org.keycloak.testsuite.arquillian.AuthServerTestEnricher.getAuthServerContextRoot; -import static org.keycloak.testsuite.util.IOUtil.*; +import static org.keycloak.testsuite.util.IOUtil.appendChildInDocument; +import static org.keycloak.testsuite.util.IOUtil.documentToString; +import static org.keycloak.testsuite.util.IOUtil.getElementTextContent; +import static org.keycloak.testsuite.util.IOUtil.loadJson; +import static org.keycloak.testsuite.util.IOUtil.loadXML; +import static org.keycloak.testsuite.util.IOUtil.modifyDocElementAttribute; +import static org.keycloak.testsuite.util.IOUtil.modifyDocElementValue; +import static org.keycloak.testsuite.util.IOUtil.removeElementsFromDoc; +import static org.keycloak.testsuite.util.IOUtil.removeNodeByAttributeValue; /** @@ -86,6 +104,21 @@ public class DeploymentArchiveProcessor implements ApplicationArchiveProcessor { // } else { // log.info(testClass.getJavaClass().getSimpleName() + " is not an AdapterTest"); // } + if (isWLSAppServer(testClass.getJavaClass())) { +// { + MavenResolverSystem resolver = Maven.resolver(); + MavenFormatStage dependencies = resolver + .loadPomFromFile("pom.xml") + .importTestDependencies() + .resolve("org.apache.httpcomponents:httpclient") + .withTransitivity(); + + ((WebArchive) archive) + .addAsLibraries(dependencies.asFile()) + .addClass(org.keycloak.testsuite.arquillian.annotation.AppServerContainer.class) + .addClass(org.keycloak.testsuite.arquillian.annotation.UseServletFilter.class); + } + } public static boolean isAdapterTest(TestClass testClass) { @@ -260,11 +293,43 @@ public class DeploymentArchiveProcessor implements ApplicationArchiveProcessor { removeElementsFromDoc(webXmlDoc, "web-app", "login-config"); removeElementsFromDoc(webXmlDoc, "web-app", "security-role"); + if (isWASAppServer(testClass.getJavaClass())) { + removeElementsFromDoc(webXmlDoc, "web-app", "servlet-mapping"); + removeElementsFromDoc(webXmlDoc, "web-app", "servlet"); + } + + if (isWLSAppServer(testClass.getJavaClass())) { + // add tag in case it is missing + NodeList nodes = webXmlDoc.getElementsByTagName("servlet"); + if (nodes.getLength() < 1) { + Element servlet = webXmlDoc.createElement("servlet"); + Element servletName = webXmlDoc.createElement("servlet-name"); + Element servletClass = webXmlDoc.createElement("servlet-class"); + + servletName.setTextContent("javax.ws.rs.core.Application"); + servletClass.setTextContent(getServletClassName(archive)); + + servlet.appendChild(servletName); + servlet.appendChild(servletClass); + + appendChildInDocument(webXmlDoc, "web-app", servlet); + } + } } - archive.add(new StringAsset((documentToString(webXmlDoc))), WEBXML_PATH); } - + + private String getServletClassName(Archive archive) { + + Map content = archive.getContent(Filters.include(".*Servlet.class")); + for (ArchivePath path : content.keySet()) { + ClassAsset asset = (ClassAsset) content.get(path).getAsset(); + return asset.getSource().getName(); + } + + return null; + } + } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/IOUtil.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/IOUtil.java index 734a4fcf43..1707ef7d8a 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/IOUtil.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/IOUtil.java @@ -29,7 +29,6 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; diff --git a/testsuite/integration-arquillian/tests/other/adapters/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/pom.xml index 1c63e6a9d7..6cfc621f24 100644 --- a/testsuite/integration-arquillian/tests/other/adapters/pom.xml +++ b/testsuite/integration-arquillian/tests/other/adapters/pom.xml @@ -98,6 +98,8 @@ jboss karaf tomcat + was + wls diff --git a/testsuite/integration-arquillian/tests/other/adapters/was/README.md b/testsuite/integration-arquillian/tests/other/adapters/was/README.md new file mode 100644 index 0000000000..ae7afce903 --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/was/README.md @@ -0,0 +1,19 @@ +# Keycloak Arquillian WebSphere AS Integration Testsuite + +- arquillian-was-remote-8.5-custom container is used for deploying artifacts to running WebSphere server +- arquillian-was-remote-8.5-custom is based on arquillian-was-remote-8.5 and solves some ibm dependency issues +- arquillian-was-remote-8.5-custom can be downloaded from this [repo](https://repository.jboss.org/nexus/content/repositories/jboss_releases_staging_profile-11801) +- more info about arquillian-was-remote-8.5-custom: + - There is the [artifact](https://github.com/vramik/arquillian-container-was/blob/custom/was-remote-8.5/pom.xml#L17) + - This is a [profile](https://github.com/vramik/arquillian-container-was/blob/custom/pom.xml#L108-L114) to activate + - To build `ws-dependencies` module it is required to specify `lib_location` property where directory `lib` is located. The `lib` has to contain `com.ibm.ws.admin.client_8.5.0.jar` and `com.ibm.ws.orb_8.5.0.jar` which are part of WebSphere AS installation + - see [pom.xml](https://github.com/vramik/arquillian-container-was/blob/custom/ws-dependencies/pom.xml) for more details + - note: to solve classpath conflicts the package javax/ws from within `com.ibm.ws.admin.client_8.5.0.jar` has to be removed + +## How to run tests + +1. start IBM WebSphere container with ibmjdk8 (tests expects that app-server runs on port 8280) +2. add the [repository](https://repository.jboss.org/nexus/content/repositories/jboss_releases_staging_profile-11801) to settings.xml +3. mvn -f keycloak/pom.xml -Pdistribution -DskipTests clean install +4. mvn -f keycloak/testsuite/integration-arquillian/pom.xml -Pauth-server-wildfly -DskipTests clean install +5. mvn -f keycloak/testsuite/integration-arquillian/tests/other/adapters/was/pom.xml -Pauth-server-wildfly,app-server-was clean install \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/adapters/was/common/xslt/arquillian.xsl b/testsuite/integration-arquillian/tests/other/adapters/was/common/xslt/arquillian.xsl new file mode 100644 index 0000000000..420a0fbfdb --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/was/common/xslt/arquillian.xsl @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + true + localhost + 8880 + false + admin + org.jboss.arquillian.container.was.remote_8_5.WebSphereRemoteContainer + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/adapters/was/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/was/pom.xml new file mode 100644 index 0000000000..c5b96a215c --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/was/pom.xml @@ -0,0 +1,45 @@ + + + + + + 4.0.0 + + + org.keycloak.testsuite + integration-arquillian-tests-adapters + 3.3.0.CR1-SNAPSHOT + + + integration-arquillian-tests-adapters-was + + pom + + Adapter Tests - WAS + + + + app-server-was + + was8 + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/adapters/was/was8/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/was/was8/pom.xml new file mode 100644 index 0000000000..ad138d389d --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/was/was8/pom.xml @@ -0,0 +1,50 @@ + + + + + + 4.0.0 + + + org.keycloak.testsuite + integration-arquillian-tests-adapters-was + 3.3.0.CR1-SNAPSHOT + + + integration-arquillian-tests-adapters-was8 + + Adapter Tests - WAS8 + + + ${project.parent.basedir}/common + was + remote + true + + + + + + org.jboss.arquillian.container + arquillian-was-remote-8.5-custom + 1.0.0.Final + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/adapters/was/was8/src/test/java/org/keycloak/testsuite/adapter/WASSAMLFilterAdapterTest.java b/testsuite/integration-arquillian/tests/other/adapters/was/was8/src/test/java/org/keycloak/testsuite/adapter/WASSAMLFilterAdapterTest.java new file mode 100644 index 0000000000..3c1fb197da --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/was/was8/src/test/java/org/keycloak/testsuite/adapter/WASSAMLFilterAdapterTest.java @@ -0,0 +1,9 @@ +package org.keycloak.testsuite.adapter; + +import org.keycloak.testsuite.adapter.servlet.AbstractSAMLFilterServletAdapterTest; +import org.keycloak.testsuite.arquillian.annotation.AppServerContainer; + +@AppServerContainer("app-server-was") +public class WASSAMLFilterAdapterTest extends AbstractSAMLFilterServletAdapterTest { + +} diff --git a/testsuite/integration-arquillian/tests/other/adapters/wls/common/xslt/arquillian.xsl b/testsuite/integration-arquillian/tests/other/adapters/wls/common/xslt/arquillian.xsl new file mode 100644 index 0000000000..d34cc0c9e3 --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/wls/common/xslt/arquillian.xsl @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + true + org.jboss.arquillian.container.wls.remote_12_1_2.WebLogicContainer + t3://localhost:8280/ + weblogic + weblogic1 + AdminServer + /home/jenkins/Oracle/Middleware/Oracle_Home/wlserver + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/adapters/wls/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/wls/pom.xml new file mode 100644 index 0000000000..85e33bce93 --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/wls/pom.xml @@ -0,0 +1,45 @@ + + + + + + 4.0.0 + + + org.keycloak.testsuite + integration-arquillian-tests-adapters + 3.3.0.CR1-SNAPSHOT + + + integration-arquillian-tests-adapters-wls + + pom + + Adapter Tests - WLS + + + + app-server-wls + + wls12 + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/adapters/wls/wls12/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/wls/wls12/pom.xml new file mode 100644 index 0000000000..afade15a9a --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/wls/wls12/pom.xml @@ -0,0 +1,48 @@ + + + + + + 4.0.0 + + + org.keycloak.testsuite + integration-arquillian-tests-adapters-wls + 3.3.0.CR1-SNAPSHOT + + + integration-arquillian-tests-adapters-wls12 + + Adapter Tests - WLS12 + + + ${project.parent.basedir}/common + wls + remote + true + + + + + org.jboss.arquillian.container + arquillian-wls-remote-12.1.x + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/adapters/wls/wls12/src/test/java/org/keycloak/testsuite/adapter/WLSSAMLFilterAdapterTest.java b/testsuite/integration-arquillian/tests/other/adapters/wls/wls12/src/test/java/org/keycloak/testsuite/adapter/WLSSAMLFilterAdapterTest.java new file mode 100644 index 0000000000..ad2a92ff2c --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/adapters/wls/wls12/src/test/java/org/keycloak/testsuite/adapter/WLSSAMLFilterAdapterTest.java @@ -0,0 +1,9 @@ +package org.keycloak.testsuite.adapter; + +import org.keycloak.testsuite.adapter.servlet.AbstractSAMLFilterServletAdapterTest; +import org.keycloak.testsuite.arquillian.annotation.AppServerContainer; + +@AppServerContainer("app-server-wls") +public class WLSSAMLFilterAdapterTest extends AbstractSAMLFilterServletAdapterTest { + +}