Merge pull request #4353 from vramik/was

KEYCLOAK-5243 was-wls support
This commit is contained in:
Pavel Drozd 2017-07-31 13:26:04 +02:00 committed by GitHub
commit d761085318
15 changed files with 420 additions and 6 deletions

View file

@ -46,6 +46,7 @@
<arquillian-drone.version>2.0.1.Final</arquillian-drone.version> <arquillian-drone.version>2.0.1.Final</arquillian-drone.version>
<arquillian-graphene.version>2.1.0.Alpha3</arquillian-graphene.version> <arquillian-graphene.version>2.1.0.Alpha3</arquillian-graphene.version>
<arquillian-wildfly-container.version>2.1.0.Alpha2</arquillian-wildfly-container.version> <arquillian-wildfly-container.version>2.1.0.Alpha2</arquillian-wildfly-container.version>
<arquillian-wls-container.version>1.0.1.Final</arquillian-wls-container.version>
<arquillian-infinispan-container.version>1.2.0.Beta2</arquillian-infinispan-container.version> <arquillian-infinispan-container.version>1.2.0.Beta2</arquillian-infinispan-container.version>
<version.shrinkwrap.resolvers>2.2.2</version.shrinkwrap.resolvers> <version.shrinkwrap.resolvers>2.2.2</version.shrinkwrap.resolvers>
<undertow-embedded.version>1.0.0.Alpha2</undertow-embedded.version> <undertow-embedded.version>1.0.0.Alpha2</undertow-embedded.version>
@ -108,6 +109,12 @@
<artifactId>wildfly-arquillian-container-domain-managed</artifactId> <artifactId>wildfly-arquillian-container-domain-managed</artifactId>
<version>${arquillian-wildfly-container.version}</version> <version>${arquillian-wildfly-container.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-wls-remote-12.1.x</artifactId>
<version>${arquillian-wls-container.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View file

@ -25,6 +25,7 @@ import org.keycloak.adapters.spi.AuthenticationError;
import org.keycloak.saml.processing.core.saml.v2.constants.X500SAMLProfileConstants; import org.keycloak.saml.processing.core.saml.v2.constants.X500SAMLProfileConstants;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
@ -47,7 +48,7 @@ import java.util.List;
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
@Path("/") @Path("/")
public class SendUsernameServlet { public class SendUsernameServlet extends HttpServlet {
private static boolean checkRoles = false; private static boolean checkRoles = false;
private static SamlAuthenticationError authError; private static SamlAuthenticationError authError;

View file

@ -133,6 +133,14 @@ public class AppServerTestEnricher {
return getAppServerQualifier(testClass).contains("tomcat"); 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) { public static boolean isOSGiAppServer(Class testClass) {
String q = getAppServerQualifier(testClass); String q = getAppServerQualifier(testClass);
return q.contains("karaf") || q.contains("fuse"); return q.contains("karaf") || q.contains("fuse");

View file

@ -26,8 +26,15 @@ import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.jboss.logging.Logger.Level; import org.jboss.logging.Logger.Level;
import org.jboss.shrinkwrap.api.Archive; 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.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive; 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.adapters.servlet.KeycloakOIDCFilter;
import org.keycloak.representations.adapters.config.AdapterConfig; import org.keycloak.representations.adapters.config.AdapterConfig;
import org.keycloak.testsuite.arquillian.annotation.UseServletFilter; import org.keycloak.testsuite.arquillian.annotation.UseServletFilter;
@ -35,18 +42,29 @@ import org.keycloak.testsuite.util.IOUtil;
import org.keycloak.util.JsonSerialization; import org.keycloak.util.JsonSerialization;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.xml.transform.TransformerException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.hasAppServerContainerAnnotation; import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.hasAppServerContainerAnnotation;
import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.isRelative; import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.isRelative;
import static org.keycloak.testsuite.arquillian.AppServerTestEnricher.isTomcatAppServer; 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.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 { // } else {
// log.info(testClass.getJavaClass().getSimpleName() + " is not an AdapterTest"); // 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) { 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", "login-config");
removeElementsFromDoc(webXmlDoc, "web-app", "security-role"); 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 <servlet> 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); archive.add(new StringAsset((documentToString(webXmlDoc))), WEBXML_PATH);
} }
private String getServletClassName(Archive<?> archive) {
Map<ArchivePath, Node> 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;
}
} }

View file

@ -29,7 +29,6 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer; import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;

View file

@ -98,6 +98,8 @@
<module>jboss</module> <module>jboss</module>
<module>karaf</module> <module>karaf</module>
<module>tomcat</module> <module>tomcat</module>
<module>was</module>
<module>wls</module>
</modules> </modules>
<profiles> <profiles>

View file

@ -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

View file

@ -0,0 +1,53 @@
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:a="http://jboss.org/schema/arquillian"
version="2.0"
exclude-result-prefixes="xalan a">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" xalan:indent-amount="4" standalone="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/a:arquillian">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<container qualifier="app-server-was" mode="manual">
<configuration>
<property name="enabled">true</property>
<property name="remoteServerAddress">localhost</property>
<property name="remoteServerSoapPort">8880</property>
<property name="securityEnabled">false</property>
<property name="username">admin</property>
<property name="adapterImplClass">org.jboss.arquillian.container.was.remote_8_5.WebSphereRemoteContainer</property>
</configuration>
</container>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-tests-adapters</artifactId>
<version>3.3.0.CR1-SNAPSHOT</version>
</parent>
<artifactId>integration-arquillian-tests-adapters-was</artifactId>
<packaging>pom</packaging>
<name>Adapter Tests - WAS</name>
<profiles>
<profile>
<id>app-server-was</id>
<modules>
<module>was8</module>
</modules>
</profile>
</profiles>
</project>

View file

@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-tests-adapters-was</artifactId>
<version>3.3.0.CR1-SNAPSHOT</version>
</parent>
<artifactId>integration-arquillian-tests-adapters-was8</artifactId>
<name>Adapter Tests - WAS8</name>
<properties>
<common.resources>${project.parent.basedir}/common</common.resources>
<app.server>was</app.server>
<app.server.type>remote</app.server.type>
<app.server.skip.unpack>true</app.server.skip.unpack>
</properties>
<dependencies>
<!--check module's README.md to learn more about the dependency-->
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-was-remote-8.5-custom</artifactId>
<version>1.0.0.Final</version>
</dependency>
</dependencies>
</project>

View file

@ -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 {
}

View file

@ -0,0 +1,54 @@
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:a="http://jboss.org/schema/arquillian"
version="2.0"
exclude-result-prefixes="xalan a">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" xalan:indent-amount="4" standalone="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/a:arquillian">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<container qualifier="app-server-wls" mode="manual">
<configuration>
<property name="enabled">true</property>
<property name="adapterImplClass">org.jboss.arquillian.container.wls.remote_12_1_2.WebLogicContainer</property>
<property name="adminUrl">t3://localhost:8280/</property>
<property name="adminUserName">weblogic</property>
<property name="adminPassword">weblogic1</property>
<property name="target">AdminServer</property>
<property name="wlHome">/home/jenkins/Oracle/Middleware/Oracle_Home/wlserver</property>
</configuration>
</container>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-tests-adapters</artifactId>
<version>3.3.0.CR1-SNAPSHOT</version>
</parent>
<artifactId>integration-arquillian-tests-adapters-wls</artifactId>
<packaging>pom</packaging>
<name>Adapter Tests - WLS</name>
<profiles>
<profile>
<id>app-server-wls</id>
<modules>
<module>wls12</module>
</modules>
</profile>
</profiles>
</project>

View file

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-tests-adapters-wls</artifactId>
<version>3.3.0.CR1-SNAPSHOT</version>
</parent>
<artifactId>integration-arquillian-tests-adapters-wls12</artifactId>
<name>Adapter Tests - WLS12</name>
<properties>
<common.resources>${project.parent.basedir}/common</common.resources>
<app.server>wls</app.server>
<app.server.type>remote</app.server.type>
<app.server.skip.unpack>true</app.server.skip.unpack>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-wls-remote-12.1.x</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -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 {
}