Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keycloak 22.0.4 custom SPI that depedends on resteasy does not work #500

Open
xsajkha opened this issue Oct 17, 2023 · 0 comments
Open

Keycloak 22.0.4 custom SPI that depedends on resteasy does not work #500

xsajkha opened this issue Oct 17, 2023 · 0 comments

Comments

@xsajkha
Copy link

xsajkha commented Oct 17, 2023

Describe the bug

I adding two custom adapters (UserStorageProvider & IdentityProvider). I'm using resteasy(version 6.2.4.Final) rest clients to integrate with external rest services. I have added the jboss resteasy dependencies at compile scope. When I try to build the keycloak with kc.sh build I am getting following error:

ERROR: io.quarkus.builder.BuildException: Build failure: Build failed due to errors Oct 17 13:08:46 mba-t1-websso1 kc.sh: [error]: Build step io.quarkus.resteasy.deployment.ResteasyStandaloneBuildStep#staticInit threw an exception: java.lang.LinkageError: loader constraint violation: loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @54afd745 wants to load interface org.jboss.resteasy.spi.ResteasyDeployment. A different interface with the same name was previously loaded by java.net.URLClassLoader @f99f5e0. (org.jboss.resteasy.spi.ResteasyDeployment is in unnamed module of loader java.net.URLClassLoader @f99f5e0, parent loader 'app')
I have added the file named: jakarta.ws.rs.ext.Providers file under META-INF >services folder and it contains the ref of the class org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider
Also I have two other files places under services folder for IdentityProviderFactor and UserStorageProviderFactory pointing to my custom providers.

My pom looks like:

`
4.0.0

<groupId>my.keycloak</groupId>
<artifactId>keycloak-bankid-adapter</artifactId>
<version>2.7-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BankId Keycloak Adapter</name>
<description />


<properties>
	<java.version>17</java.version>
	<maven.compiler.source>17</maven.compiler.source>
	<maven.compiler.target>17</maven.compiler.target>
	<jacoco.line.coverage>0.32</jacoco.line.coverage>
	<jacoco.branch.coverage>0.27</jacoco.branch.coverage>
	<dependency-check.failBuildOnCVSS>10</dependency-check.failBuildOnCVSS>
	<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
	<keycloak.version>22.0.4</keycloak.version>
	<jboss-servlet-api.version>2.0.0.Final</jboss-servlet-api.version>
	<jboss.logging.version>3.5.1.Final</jboss.logging.version>
	<resteasy.version>6.2.4.Final</resteasy.version>
	<jsonassert.version>1.5.1</jsonassert.version>
	<bankid-adapter.version>4.5</bankid-adapter.version>
	<bouncycastle.version>1.76</bouncycastle.version>
</properties>

<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.keycloak.bom</groupId>
			<artifactId>keycloak-bom-parent</artifactId>
			<version>${keycloak.version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

<dependencies>
	<dependency>
		<groupId>jakarta.ws.rs</groupId>
		<artifactId>jakarta.ws.rs-api</artifactId>
		<version>3.1.0</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.keycloak</groupId>
		<artifactId>keycloak-server-spi</artifactId>
		<version>${keycloak.version}</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.keycloak</groupId>
		<artifactId>keycloak-server-spi-private</artifactId>
		<version>${keycloak.version}</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.keycloak</groupId>
		<artifactId>keycloak-services</artifactId>
		<version>${keycloak.version}</version>
		<scope>provided</scope>
		<exclusions>
			<exclusion>
				<groupId>log4j</groupId>
				<artifactId>log4j</artifactId>
			</exclusion>
		</exclusions>
	</dependency>
	<dependency>
		<groupId>org.keycloak</groupId>
		<artifactId>keycloak-admin-client</artifactId>
		<version>${keycloak.version}</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.keycloak</groupId>
		<artifactId>keycloak-model-infinispan</artifactId>
		<version>${keycloak.version}</version>
		<scope>provided</scope>
	</dependency>

	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-core</artifactId>
		<version>${resteasy.version}</version>
	</dependency>
	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-client</artifactId>
		<version>${resteasy.version}</version>
	</dependency>
	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-multipart-provider</artifactId>
		<version>${resteasy.version}</version>
	</dependency>
	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-jaxb-provider</artifactId>
		<version>${resteasy.version}</version>
	</dependency>
	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-jackson2-provider</artifactId>
		<version>${resteasy.version}</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.datatype</groupId>
		<artifactId>jackson-datatype-jsr310</artifactId>
		<!-- <version>${jackson.version}</version> -->
	</dependency>
	<dependency>
		<groupId>org.jboss.spec.javax.servlet</groupId>
		<artifactId>jboss-servlet-api_4.0_spec</artifactId>
		<version>${jboss-servlet-api.version}</version>
	</dependency>

	<dependency>
		<groupId>org.bouncycastle</groupId>
		<artifactId>bcprov-jdk18on</artifactId>
		<version>${bouncycastle.version}</version>
	</dependency>

	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.mockito</groupId>
		<artifactId>mockito-junit-jupiter</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.mockito</groupId>
		<artifactId>mockito-inline</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.skyscreamer</groupId>
		<artifactId>jsonassert</artifactId>
		<version>${jsonassert.version}</version>
		<scope>test</scope>
	</dependency>


</dependencies>

<build>
	<resources>
		<resource>
			<directory>src/main/resources</directory>
			<filtering>true</filtering>
		</resource>
	</resources>
	<pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<configuration>
					<failOnError>false</failOnError>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<!-- This is required since we need to add the jboss module references
                         to the resulting jar -->
						<manifestEntries>
							<!-- Adding explicit dependencies to avoid class-loading issues at
                            runtime -->
							<Dependencies>
								<![CDATA[org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private,org.keycloak.keycloak-services,org.jboss.resteasy.resteasy-jackson2-provider,com.fasterxml.jackson.core.jackson-databind,com.fasterxml.jackson.core.jackson-annotations]]>
							</Dependencies>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
		</plugins>
	</pluginManagement>
	<plugins>

		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-shade-plugin</artifactId>
			<version>3.5.1</version>
			<configuration>
				<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
				<filters>
					<filter>
						<artifact>*:*</artifact>
						<excludes>
							<exclude>META-INF/*.SF</exclude>
							<exclude>META-INF/*.DSA</exclude>
							<exclude>META-INF/*.RSA</exclude>
							<exclude>se/kf/bankid/api/event/**</exclude>
						</excludes>
					</filter>
				</filters>
			</configuration>
			<executions>
				<execution>
					<phase>package</phase>
					<goals>
						<goal>shade</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>
`

I am building a fat/uber jar and placing it in the keycloak>providers folder to install my custom adapters. Please let me know what I'm missing. Thank you!

Version

22.0.4

Expected behavior

Custom adapters should be installed

Actual behavior

Running into issue:

ERROR: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
Oct 17 13:08:46 mba-t1-websso1 kc.sh: [error]: Build step io.quarkus.resteasy.deployment.ResteasyStandaloneBuildStep#staticInit threw an exception: java.lang.LinkageError: loader constraint violation: loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @54afd745 wants to load interface org.jboss.resteasy.spi.ResteasyDeployment. A different interface with the same name was previously loaded by java.net.URLClassLoader @f99f5e0. (org.jboss.resteasy.spi.ResteasyDeployment is in unnamed module of loader java.net.URLClassLoader @f99f5e0, parent loader 'app')

How to Reproduce?

No response

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant