install adapter via cli script from java code after start

This commit is contained in:
vramik 2016-01-07 18:58:32 +01:00
parent efa112f820
commit 448a15b2ca
14 changed files with 233 additions and 402 deletions

View file

@ -273,7 +273,6 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions> <executions>
<execution> <execution>
<id>copy-keystore</id> <id>copy-keystore</id>
@ -309,7 +308,6 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId> <artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions> <executions>
<execution> <execution>
<id>enforce-properties</id> <id>enforce-properties</id>

View file

@ -15,22 +15,29 @@
<as7.version>7.1.1.Final</as7.version> <as7.version>7.1.1.Final</as7.version>
<app.server.as7.home>${containers.home}/jboss-as-${as7.version}</app.server.as7.home> <app.server.as7.home>${containers.home}/jboss-as-${as7.version}</app.server.as7.home>
<adapter.libs.as7>${containers.home}/keycloak-as7-adapter-dist</adapter.libs.as7> <adapter.libs.as7>${containers.home}/keycloak-as7-adapter-dist</adapter.libs.as7>
<startup.timeout.sec>150</startup.timeout.sec>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
</dependency>
<!--for as7-->
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<version>${as7.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.jboss.as</groupId> <groupId>org.jboss.as</groupId>
<artifactId>jboss-as-dist</artifactId> <artifactId>jboss-as-dist</artifactId>
<version>${as7.version}</version> <version>${as7.version}</version>
<type>zip</type> <type>zip</type>
</dependency> </dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.keycloak</groupId> <groupId>org.keycloak</groupId>
<artifactId>keycloak-eap6-adapter-dist</artifactId> <artifactId>keycloak-as7-adapter-dist</artifactId>
<type>zip</type> <type>zip</type>
</dependency> </dependency>
</dependencies> </dependencies>
@ -79,15 +86,36 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration> <configuration>
<systemPropertyVariables> <systemPropertyVariables>
<app.server.as7>true</app.server.as7> <app.server.as7>true</app.server.as7>
<app.server.as7.home>${app.server.as7.home}</app.server.as7.home> <app.server.as7.home>${app.server.as7.home}</app.server.as7.home>
<adapter.libs.as7>${adapter.libs.as7}</adapter.libs.as7> <adapter.libs.as7>${adapter.libs.as7}</adapter.libs.as7>
<startup.timeout.sec>${startup.timeout.sec}</startup.timeout.sec>
<adapter.as7.jdk7.path>${adapter.as7.jdk7.path}</adapter.as7.jdk7.path>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-properties</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>adapter.as7.jdk7.path</property>
</requireProperty>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
@ -102,35 +130,6 @@
<properties> <properties>
<adapter.libs.as7>${app.server.as7.home}</adapter.libs.as7> <adapter.libs.as7>${app.server.as7.home}</adapter.libs.as7>
</properties> </properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<id>configure-adapter-subsystem</id>
<phase>process-resources</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<transformationSets>
<transformationSet>
<dir>${app.server.as7.home}/standalone/configuration</dir>
<includes>
<include>standalone.xml</include>
</includes>
<stylesheet>src/main/xslt/standalone.xsl</stylesheet>
<outputDir>${app.server.as7.home}/standalone/configuration</outputDir>
</transformationSet>
</transformationSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile> </profile>
</profiles> </profiles>
</project> </project>

View file

@ -20,6 +20,8 @@
<property name="managementAddress">localhost</property> <property name="managementAddress">localhost</property>
<property name="managementProtocol">remote</property> <property name="managementProtocol">remote</property>
<property name="managementPort">${app.server.management.port.jmx}</property> <property name="managementPort">${app.server.management.port.jmx}</property>
<property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>
<property name="javaHome">${adapter.as7.jdk7.path}</property>
</configuration> </configuration>
</container> </container>

View file

@ -1,51 +0,0 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:j="urn:jboss:domain:1.2"
xmlns:ds="urn:jboss:domain:datasources:1.0"
xmlns:k="urn:jboss:domain:keycloak:1.1"
xmlns:sec="urn:jboss:domain:security:1.1"
version="2.0"
exclude-result-prefixes="xalan j ds k sec">
<xsl:param name="config"/>
<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="//j:extensions">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<extension module="org.keycloak.keycloak-adapter-subsystem"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//j:profile">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<subsystem xmlns="urn:jboss:domain:keycloak:1.1"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//sec:security-domains">
<xsl:copy>
<xsl:apply-templates select="node()[name(.)='security-domain']"/>
<security-domain name="keycloak">
<authentication>
<login-module code="org.keycloak.adapters.jboss.KeycloakLoginModule" flag="required"/>
</authentication>
</security-domain>
<security-domain name="sp" cache-type="default">
<authentication>
<login-module code="org.picketlink.identity.federation.bindings.wildfly.SAML2LoginModule" flag="required"/>
</authentication>
</security-domain>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View file

@ -12,17 +12,17 @@
<name>Adapter Tests on EAP 6</name> <name>Adapter Tests on EAP 6</name>
<properties> <properties>
<app.server.eap6.home>${containers.home}</app.server.eap6.home> <app.server.eap6.home>${containers.home}/jboss-eap-6.4</app.server.eap6.home>
<adapter.libs.eap6>${containers.home}/keycloak-eap6-adapter-dist</adapter.libs.eap6> <adapter.libs.eap6>${containers.home}/keycloak-eap6-adapter-dist</adapter.libs.eap6>
<skip.configure.adapter.subsystem>false</skip.configure.adapter.subsystem>
</properties> </properties>
<dependencies> <dependencies>
<!-- <dependency> <!-- This dependency is for starting auth server based on wildfly (eap7)-->
<dependency>
<groupId>org.wildfly</groupId> <groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId> <artifactId>wildfly-arquillian-container-managed</artifactId>
</dependency>--> </dependency>
<!--TODO: this is for EAP6--> <!-- This is for EAP6-->
<dependency> <dependency>
<groupId>org.jboss.as</groupId> <groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId> <artifactId>jboss-as-arquillian-container-managed</artifactId>
@ -53,11 +53,10 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration> <configuration>
<systemPropertyVariables> <systemPropertyVariables>
<app.server.eap6>true</app.server.eap6> <app.server.eap6>true</app.server.eap6>
<app.server.eap6.home>${app.server.eap6.home}/jboss-eap-6.4</app.server.eap6.home> <app.server.eap6.home>${app.server.eap6.home}</app.server.eap6.home>
<adapter.libs.eap6>${adapter.libs.eap6}</adapter.libs.eap6> <adapter.libs.eap6>${adapter.libs.eap6}</adapter.libs.eap6>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
@ -97,46 +96,6 @@
</build> </build>
<profiles> <profiles>
<profile>
<id>prod</id>
<activation>
<property>
<name>prod</name>
<value>true</value>
</property>
</activation>
<properties>
<skip.configure.adapter.subsystem>true</skip.configure.adapter.subsystem>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-eap6-with-adapter</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.keycloak</groupId>
<artifactId>rh-sso-eap6-adapter</artifactId>
<version>${version.rh.soo}</version>
<type>zip</type>
<outputDirectory>${app.server.eap6.home}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile> <profile>
<id>adapter-jdk</id> <id>adapter-jdk</id>
<activation> <activation>
@ -190,36 +149,6 @@
<properties> <properties>
<adapter.libs.eap6>${app.server.eap6.home}</adapter.libs.eap6> <adapter.libs.eap6>${app.server.eap6.home}</adapter.libs.eap6>
</properties> </properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<id>configure-adapter-subsystem</id>
<phase>process-resources</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<skip>${skip.configure.adapter.subsystem}</skip>
<transformationSets>
<transformationSet>
<dir>${app.server.eap6.home}/standalone/configuration</dir>
<includes>
<include>standalone.xml</include>
</includes>
<stylesheet>src/main/xslt/standalone.xsl</stylesheet>
<outputDir>${app.server.eap6.home}/standalone/configuration</outputDir>
</transformationSet>
</transformationSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile> </profile>
<profile> <profile>
<id>ssl</id> <id>ssl</id>

View file

@ -1,51 +0,0 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:j="urn:jboss:domain:1.7"
xmlns:ds="urn:jboss:domain:datasources:1.2"
xmlns:k="urn:jboss:domain:keycloak:1.1"
xmlns:sec="urn:jboss:domain:security:1.2"
version="2.0"
exclude-result-prefixes="xalan j ds k sec">
<xsl:param name="config"/>
<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="//j:extensions">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<extension module="org.keycloak.keycloak-adapter-subsystem"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//j:profile">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<subsystem xmlns="urn:jboss:domain:keycloak:1.1"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//sec:security-domains">
<xsl:copy>
<xsl:apply-templates select="node()[name(.)='security-domain']"/>
<security-domain name="keycloak">
<authentication>
<login-module code="org.keycloak.adapters.jboss.KeycloakLoginModule" flag="required"/>
</authentication>
</security-domain>
<security-domain name="sp" cache-type="default">
<authentication>
<login-module code="org.picketlink.identity.federation.bindings.wildfly.SAML2LoginModule" flag="required"/>
</authentication>
</security-domain>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View file

@ -189,7 +189,6 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions> <executions>
<execution> <execution>
<id>example-wars</id> <id>example-wars</id>
@ -384,6 +383,13 @@
<exclude.adapters>**/adapter/**/*Test.java</exclude.adapters> <exclude.adapters>**/adapter/**/*Test.java</exclude.adapters>
</properties> </properties>
</profile> </profile>
<profile>
<id>no-relative</id>
<properties>
<!-- Exclude relative adapters tests. -->
<exclude.adapters>**/adapter/**/WildflyRelative*Test.java</exclude.adapters>
</properties>
</profile>
</profiles> </profiles>

View file

@ -100,35 +100,6 @@
<properties> <properties>
<adapter.libs.wildfly>${app.server.wildfly.home}</adapter.libs.wildfly> <adapter.libs.wildfly>${app.server.wildfly.home}</adapter.libs.wildfly>
</properties> </properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<id>configure-adapter-subsystem</id>
<phase>process-resources</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<transformationSets>
<transformationSet>
<dir>${app.server.wildfly.home}/standalone/configuration</dir>
<includes>
<include>standalone.xml</include>
</includes>
<stylesheet>src/main/xslt/standalone.xsl</stylesheet>
<outputDir>${app.server.wildfly.home}/standalone/configuration</outputDir>
</transformationSet>
</transformationSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile> </profile>
<profile> <profile>
<id>ssl</id> <id>ssl</id>
@ -166,7 +137,6 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions> <executions>
<execution> <execution>
<id>copy-keystore</id> <id>copy-keystore</id>

View file

@ -79,7 +79,6 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration> <configuration>
<systemPropertyVariables> <systemPropertyVariables>
<app.server.wildfly>true</app.server.wildfly> <app.server.wildfly>true</app.server.wildfly>
@ -102,35 +101,6 @@
<properties> <properties>
<adapter.libs.wildfly>${app.server.wildfly.home}</adapter.libs.wildfly> <adapter.libs.wildfly>${app.server.wildfly.home}</adapter.libs.wildfly>
</properties> </properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<id>configure-adapter-subsystem</id>
<phase>process-resources</phase>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<transformationSets>
<transformationSet>
<dir>${app.server.wildfly.home}/standalone/configuration</dir>
<includes>
<include>standalone.xml</include>
</includes>
<stylesheet>src/main/xslt/standalone.xsl</stylesheet>
<outputDir>${app.server.wildfly.home}/standalone/configuration</outputDir>
</transformationSet>
</transformationSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile> </profile>
</profiles> </profiles>
</project> </project>

View file

@ -1,51 +0,0 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:j="urn:jboss:domain:2.2"
xmlns:ds="urn:jboss:domain:datasources:2.0"
xmlns:k="urn:jboss:domain:keycloak:1.1"
xmlns:sec="urn:jboss:domain:security:1.2"
version="2.0"
exclude-result-prefixes="xalan j ds k sec">
<xsl:param name="config"/>
<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="//j:extensions">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<extension module="org.keycloak.keycloak-adapter-subsystem"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//j:profile">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<subsystem xmlns="urn:jboss:domain:keycloak:1.1"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//sec:security-domains">
<xsl:copy>
<xsl:apply-templates select="node()[name(.)='security-domain']"/>
<security-domain name="keycloak">
<authentication>
<login-module code="org.keycloak.adapters.jboss.KeycloakLoginModule" flag="required"/>
</authentication>
</security-domain>
<security-domain name="sp" cache-type="default">
<authentication>
<login-module code="org.picketlink.identity.federation.bindings.wildfly.SAML2LoginModule" flag="required"/>
</authentication>
</security-domain>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View file

@ -15,6 +15,7 @@
<exclude.console>-</exclude.console> <exclude.console>-</exclude.console>
<exclude.account>-</exclude.account> <exclude.account>-</exclude.account>
<exclude.client>-</exclude.client> <exclude.client>-</exclude.client>
<exclude.migration>-</exclude.migration>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
@ -50,6 +51,7 @@
<exclude>${exclude.console}</exclude> <exclude>${exclude.console}</exclude>
<exclude>${exclude.account}</exclude> <exclude>${exclude.account}</exclude>
<exclude>${exclude.client}</exclude> <exclude>${exclude.client}</exclude>
<exclude>${exclude.migration}</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
@ -77,6 +79,7 @@
<exclude.console>**/console/**/*Test.java</exclude.console> <exclude.console>**/console/**/*Test.java</exclude.console>
<exclude.account>**/account/**/*Test.java</exclude.account> <exclude.account>**/account/**/*Test.java</exclude.account>
<exclude.client>**/client/**/*Test.java</exclude.client> <exclude.client>**/client/**/*Test.java</exclude.client>
<exclude.migration>**/migration/**/*Test.java</exclude.migration>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>

View file

@ -1,10 +1,14 @@
package org.keycloak.testsuite.arquillian; package org.keycloak.testsuite.arquillian;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.jboss.arquillian.container.spi.Container; import org.jboss.arquillian.container.spi.Container;
import org.jboss.arquillian.container.spi.ContainerRegistry; import org.jboss.arquillian.container.spi.ContainerRegistry;
@ -19,6 +23,7 @@ import org.jboss.arquillian.core.api.annotation.Observes;
import org.jboss.arquillian.test.spi.annotation.ClassScoped; import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.arquillian.test.spi.annotation.SuiteScoped; import org.jboss.arquillian.test.spi.annotation.SuiteScoped;
import org.jboss.arquillian.container.spi.event.container.AfterStart; import org.jboss.arquillian.container.spi.event.container.AfterStart;
import org.jboss.arquillian.container.spi.event.container.BeforeStart;
import org.jboss.arquillian.test.spi.event.suite.BeforeClass; import org.jboss.arquillian.test.spi.event.suite.BeforeClass;
import org.jboss.arquillian.test.spi.event.suite.BeforeSuite; import org.jboss.arquillian.test.spi.event.suite.BeforeSuite;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -103,43 +108,92 @@ public class ContainersTestEnricher {
* After start container. Server logs are checked (in case jboss based container). * After start container. Server logs are checked (in case jboss based container).
* In case of migration scenario: previous container is stopped. * In case of migration scenario: previous container is stopped.
*/ */
public void afterStart(@Observes AfterStart event) throws IOException { public void afterStart(@Observes AfterStart event) throws IOException, InterruptedException {
if (System.getProperty("check.server.log", "true").equals("true")) { Container container = containers.pollFirst();
checkServerLog(); String jbossHomePath = null;
if (isJBossBased(container)) {
jbossHomePath = container.getContainerConfiguration().getContainerProperties().get("jbossHome");
log.debug("jbossHome: " + jbossHomePath + "\n");
if (System.getProperty("check.server.log", "true").equals("true")) {
checkServerLog(jbossHomePath);
}
} }
if (migrationTests && !alreadyStopped) { if (migrationTests && !alreadyStopped) {
log.info("\n\n### Stopping keycloak " + System.getProperty("version", "- previous") + " ###\n"); log.info("\n\n### Stopping keycloak " + System.getProperty("version", "- previous") + " ###\n");
stopSuiteContainers.fire(new StopSuiteContainers()); stopSuiteContainers.fire(new StopSuiteContainers());
log.info("\n\n### Starting keycloak current version ###\n"); log.info("\n\n### Starting keycloak current version ###\n");
alreadyStopped = true;
} }
alreadyStopped = true;
if (isJBossBased(container) && container.getName().startsWith("app-server")) {
log.info("Installing adapter to app server via cli script");
String jbossCliPath = jbossHomePath + "/bin/jboss-cli.sh";
String scriptPathArg = "--file=" + jbossHomePath + "/bin/adapter-install.cli";
String managementPort = container.getContainerConfiguration().getContainerProperties().get("managementPort");
String controllerArg = "--controller=localhost:" + managementPort;
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", scriptPathArg, controllerArg});
log.debug("Restarting container");
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", "--command=:reload", controllerArg});
}
}
private void execCommand(String... command) throws IOException, InterruptedException {
Process process = Runtime.getRuntime().exec(command);
printOutput(process.getInputStream());
if (process.waitFor(10, TimeUnit.SECONDS)) {
if (process.exitValue() != 0) {
log.error("Std Error:");
printOutput(process.getErrorStream());
throw new RuntimeException("Adapter installation failed.");
}
} else {
process.destroy();
throw new RuntimeException("Timeout after 10 seconds.");
}
}
private void printOutput(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder builder = new StringBuilder();
while (reader.ready()) {
builder.append(reader.readLine());
}
log.info(builder);
}
private boolean isJBossBased(Container container) {
if (container == null) {
return false;
}
return container.getName().matches("a.*-server-wildfly")
|| container.getName().matches("a.*-server-eap.")
|| container.getName().equals("app-server-as7");
} }
/* /*
* non-javadoc * non-javadoc
* *
* check server logs (in case jboss based container) whether there are no ERRORs or SEVEREs * check server logs whether there are no ERRORs or SEVEREs
*/ */
private void checkServerLog() throws IOException { private void checkServerLog(String jbossHomePath) throws IOException {
Container container = containers.removeFirst(); File serverLog = new File(jbossHomePath + "/standalone/log/server.log");
if (container.getName().equals("auth-server-wildfly") String serverLogContent = FileUtils.readFileToString(serverLog);
|| container.getName().matches("auth-server-eap.")) {
String jbossHomePath = container.getContainerConfiguration().getContainerProperties().get("jbossHome");
log.debug("jbossHome: " + jbossHomePath + "\n");
String serverLogContent = FileUtils.readFileToString(new File(jbossHomePath + "/standalone/log/server.log")); boolean containsError
= serverLogContent.contains("ERROR")
|| serverLogContent.contains("SEVERE")
|| serverLogContent.contains("Exception ");
//There is expected string "Exception" in server log: Adding provider
//singleton org.keycloak.services.resources.ModelExceptionMapper
boolean containsError if (containsError) {
= serverLogContent.contains("ERROR") throw new RuntimeException(serverLog.getPath() + " contains ERROR.");
|| serverLogContent.contains("SEVERE")
|| serverLogContent.contains("Exception ");
//There is expected string "Exception" in server log: Adding provider
//singleton org.keycloak.services.resources.ModelExceptionMapper
if (containsError) {
throw new RuntimeException(container.getName() + ": Server log contains ERROR.");
}
} }
} }
@ -154,9 +208,7 @@ public class ContainersTestEnricher {
appServerQualifier = getAppServerQualifier(testClass); appServerQualifier = getAppServerQualifier(testClass);
if (!controller.isStarted(appServerQualifier)) { if (!controller.isStarted(appServerQualifier)) {
log.info("\nSTARTING APP SERVER: " + appServerQualifier + "\n");
controller.start(appServerQualifier); controller.start(appServerQualifier);
log.info("");
} }
initializeTestContext(testClass); initializeTestContext(testClass);

View file

@ -79,14 +79,16 @@ public abstract class AbstractAdapterTest extends AbstractAuthTest {
} }
protected void modifyClientUrls(RealmRepresentation realm, String regex, String replacement) { protected void modifyClientUrls(RealmRepresentation realm, String regex, String replacement) {
for (ClientRepresentation client : realm.getClients()) { if (realm.getClients() != null) {
String baseUrl = client.getBaseUrl(); for (ClientRepresentation client : realm.getClients()) {
if (baseUrl != null) { String baseUrl = client.getBaseUrl();
client.setBaseUrl(baseUrl.replaceAll(regex, replacement)); if (baseUrl != null) {
} client.setBaseUrl(baseUrl.replaceAll(regex, replacement));
String adminUrl = client.getAdminUrl(); }
if (adminUrl != null) { String adminUrl = client.getAdminUrl();
client.setAdminUrl(adminUrl.replaceAll(regex, replacement)); if (adminUrl != null) {
client.setAdminUrl(adminUrl.replaceAll(regex, replacement));
}
} }
} }
} }

View file

@ -21,7 +21,7 @@
{ "type" : "password", { "type" : "password",
"value" : "password" } "value" : "password" }
], ],
"realmRoles": [ "user", "admin" ], "realmRoles": [ "user" ],
"applicationRoles": { "applicationRoles": {
"account": [ "manage-account" ] "account": [ "manage-account" ]
} }
@ -34,12 +34,36 @@
"lastName": "Posolda", "lastName": "Posolda",
"credentials" : [ "credentials" : [
{ "type" : "password", { "type" : "password",
"value" : "password" } "value" : "password" }
], ],
"realmRoles": [ "user" ], "realmRoles": [ "user" ],
"applicationRoles": { "applicationRoles": {
"account": [ "manage-account" ] "account": [ "manage-account" ]
} }
},
{
"username" : "topGroupUser",
"enabled": true,
"email" : "top@redhat.com",
"credentials" : [
{ "type" : "password",
"value" : "password" }
],
"groups": [
"/top"
]
},
{
"username" : "level2GroupUser",
"enabled": true,
"email" : "level2@redhat.com",
"credentials" : [
{ "type" : "password",
"value" : "password" }
],
"groups": [
"/top/level2"
]
} }
], ],
"roles" : { "roles" : {
@ -54,6 +78,29 @@
} }
] ]
}, },
"groups" : [
{
"name": "top",
"attributes": {
"topAttribute": ["true"]
},
"realmRoles": ["user"],
"clientRoles": {
"account": ["manage-account"]
},
"subGroups": [
{
"name": "level2",
"realmRoles": ["admin"],
"attributes": {
"level2Attribute": ["true"]
}
}
]
}
],
"scopeMappings": [ "scopeMappings": [
{ {
"client": "third-party", "client": "third-party",
@ -69,38 +116,39 @@
} }
], ],
"clients": [ "applications": [
{ {
"clientId": "customer-portal", "name": "customer-portal",
"enabled": true, "enabled": true,
"adminUrl": "/customer-portal", "directAccessGrantsEnabled": true,
"baseUrl": "/customer-portal", "adminUrl": "http://localhost:8081/customer-portal",
"baseUrl": "http://localhost:8081/customer-portal",
"redirectUris": [ "redirectUris": [
"/customer-portal/*" "http://localhost:8081/customer-portal/*"
], ],
"secret": "password" "secret": "password"
}, },
{ {
"clientId": "customer-cookie-portal", "name": "customer-cookie-portal",
"enabled": true, "enabled": true,
"baseUrl": "/customer-cookie-portal", "baseUrl": "http://localhost:8081/customer-cookie-portal",
"redirectUris": [ "redirectUris": [
"/customer-cookie-portal/*" "http://localhost:8081/customer-cookie-portal/*"
], ],
"secret": "password" "secret": "password"
}, },
{ {
"clientId": "customer-portal-js", "name": "customer-portal-js",
"enabled": true, "enabled": true,
"publicClient": true, "publicClient": true,
"adminUrl": "/customer-portal-js", "adminUrl": "http://localhost:8081/customer-portal-js",
"baseUrl": "/customer-portal-js", "baseUrl": "http://localhost:8081/customer-portal-js",
"redirectUris": [ "redirectUris": [
"/customer-portal-js/*" "http://localhost:8080/customer-portal-js/*"
] ]
}, },
{ {
"clientId": "customer-portal-cli", "name": "customer-portal-cli",
"enabled": true, "enabled": true,
"publicClient": true, "publicClient": true,
"redirectUris": [ "redirectUris": [
@ -109,51 +157,56 @@
] ]
}, },
{ {
"clientId": "product-portal", "name": "product-portal",
"enabled": true, "enabled": true,
"adminUrl": "/product-portal", "adminUrl": "http://localhost:8081/product-portal",
"baseUrl": "/product-portal", "baseUrl": "http://localhost:8081/product-portal",
"redirectUris": [ "redirectUris": [
"/product-portal/*" "http://localhost:8081/product-portal/*"
], ],
"secret": "password" "secret": "password"
}, },
{ {
"clientId": "secure-portal", "name": "secure-portal",
"enabled": true, "enabled": true,
"adminUrl": "/secure-portal", "adminUrl": "http://localhost:8081/secure-portal",
"baseUrl": "/secure-portal", "baseUrl": "http://localhost:8081/secure-portal",
"clientAuthenticatorType": "client-jwt",
"redirectUris": [ "redirectUris": [
"/secure-portal/*" "http://localhost:8081/secure-portal/*"
],
"attributes": {
"jwt.credential.certificate": "MIICnTCCAYUCBgFPPLDaTzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjI0N1oXDTI1MDgxNzE3MjQyN1owEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIUjjgv+V3s96O+Za9002Lp/trtGuHBeaeVL9dFKMKzO2MPqdRmHB4PqNlDdd28Rwf5Xn6iWdFpyUKOnI/yXDLhdcuFpR0sMNK/C9Lt+hSpPFLuzDqgtPgDotlMxiHIWDOZ7g9/gPYNXbNvjv8nSiyqoguoCQiiafW90bPHsiVLdP7ZIUwCcfi1qQm7FhxRJ1NiW5dvUkuCnnWEf0XR+Wzc5eC9EgB0taLFiPsSEIlWMm5xlahYyXkPdNOqZjiRnrTWm5Y4uk8ZcsD/KbPTf/7t7cQXipVaswgjdYi1kK2/zRwOhg1QwWFX/qmvdd+fLxV0R6VqRDhn7Qep2cxwMxLsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAKE6OA46sf20bz8LZPoiNsqRwBUDkaMGXfnob7s/hJZIIwDEx0IAQ3uKsG7q9wb+aA6s+v7S340zb2k3IxuhFaHaZpAd4CyR5cn1FHylbzoZ7rI/3ASqHDqpljdJaFqPH+m7nZWtyDvtZf+gkZ8OjsndwsSBK1d/jMZPp29qYbl1+XfO7RCp/jDqro/R3saYFaIFiEZPeKn1hUJn6BO48vxH1xspSu9FmlvDOEAOz4AuM58z4zRMP49GcFdCWr1wkonJUHaSptJaQwmBwLFUkCbE5I1ixGMb7mjEud6Y5jhfzJiZMo2U8RfcjNbrN0diZl3jB6LQIwESnhYSghaTjNQ=="
}
},
{
"name": "session-portal",
"enabled": true,
"adminUrl": "http://localhost:8081/session-portal",
"baseUrl": "http://localhost:8081/session-portal",
"redirectUris": [
"http://localhost:8081/session-portal/*"
], ],
"secret": "password" "secret": "password"
}, },
{ {
"clientId": "session-portal", "name": "input-portal",
"enabled": true, "enabled": true,
"adminUrl": "/session-portal", "adminUrl": "http://localhost:8081/input-portal",
"baseUrl": "/session-portal", "baseUrl": "http://localhost:8081/input-portal",
"redirectUris": [ "redirectUris": [
"/session-portal/*" "http://localhost:8081/input-portal/*"
], ],
"secret": "password" "secret": "password"
}, }
],
"oauthClients": [
{ {
"clientId": "input-portal", "name": "third-party",
"enabled": true,
"adminUrl": "/input-portal",
"baseUrl": "/input-portal",
"redirectUris": [
"/input-portal/*"
],
"secret": "password"
},
{
"clientId": "third-party",
"enabled": true, "enabled": true,
"redirectUris": [ "redirectUris": [
"/oauth-client/*", "http://localhost:8081/oauth-client/*",
"/oauth-client-cdi/*" "http://localhost:8081/oauth-client-cdi/*"
], ],
"secret": "password" "secret": "password"
} }