KEYCLOAK-11702 Remove RestEasy 4 dependencies from core codebase
This commit is contained in:
parent
4d872d0c2c
commit
52085da520
15 changed files with 145 additions and 114 deletions
|
@ -31,5 +31,6 @@
|
||||||
<module name="org.keycloak.keycloak-server-spi-private"/>
|
<module name="org.keycloak.keycloak-server-spi-private"/>
|
||||||
<module name="org.keycloak.keycloak-services"/>
|
<module name="org.keycloak.keycloak-services"/>
|
||||||
<module name="org.jboss.modules"/>
|
<module name="org.jboss.modules"/>
|
||||||
|
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</module>
|
</module>
|
||||||
|
|
20
pom.xml
20
pom.xml
|
@ -79,7 +79,6 @@
|
||||||
<jboss.spec.javax.servlet.jsp.jboss-jsp-api_2.3_spec.version>1.0.3.Final</jboss.spec.javax.servlet.jsp.jboss-jsp-api_2.3_spec.version>
|
<jboss.spec.javax.servlet.jsp.jboss-jsp-api_2.3_spec.version>1.0.3.Final</jboss.spec.javax.servlet.jsp.jboss-jsp-api_2.3_spec.version>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
<log4j.version>1.2.17</log4j.version>
|
||||||
<resteasy.version>3.7.0.Final</resteasy.version>
|
<resteasy.version>3.7.0.Final</resteasy.version>
|
||||||
<resteasy4.version>4.3.1.Final</resteasy4.version>
|
|
||||||
<resteasy.undertow.version>3.7.0.Final</resteasy.undertow.version>
|
<resteasy.undertow.version>3.7.0.Final</resteasy.undertow.version>
|
||||||
<owasp.html.sanitizer.version>20180219.1</owasp.html.sanitizer.version>
|
<owasp.html.sanitizer.version>20180219.1</owasp.html.sanitizer.version>
|
||||||
<slf4j-api.version>1.7.22</slf4j-api.version>
|
<slf4j-api.version>1.7.22</slf4j-api.version>
|
||||||
|
@ -316,25 +315,6 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
|
||||||
<artifactId>resteasy-core</artifactId>
|
|
||||||
<version>${resteasy4.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
<groupId>org.jboss.resteasy</groupId>
|
||||||
<artifactId>resteasy-multipart-provider</artifactId>
|
<artifactId>resteasy-multipart-provider</artifactId>
|
||||||
|
|
|
@ -13,6 +13,28 @@
|
||||||
<artifactId>keycloak-quarkus-extensions</artifactId>
|
<artifactId>keycloak-quarkus-extensions</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.resteasy</groupId>
|
||||||
|
<artifactId>resteasy-core</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.keycloak</groupId>
|
||||||
|
<artifactId>keycloak-services</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package org.keycloak.provider.quarkus;
|
||||||
|
|
||||||
|
import org.jboss.resteasy.core.ResteasyContext;
|
||||||
|
import org.keycloak.common.util.ResteasyProvider;
|
||||||
|
|
||||||
|
public class Resteasy4Provider implements ResteasyProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R> R getContextData(Class<R> type) {
|
||||||
|
return ResteasyContext.getContextData(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushDefaultContextObject(Class type, Object instance) {
|
||||||
|
ResteasyContext.getContextData(org.jboss.resteasy.spi.Dispatcher.class).getDefaultContextObjects()
|
||||||
|
.put(type, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushContext(Class type, Object instance) {
|
||||||
|
ResteasyContext.pushContext(type, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearContextData() {
|
||||||
|
ResteasyContext.clearContextData();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.keycloak.provider.quarkus.Resteasy4Provider
|
|
@ -31,8 +31,11 @@
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<surefire-plugin.version>2.22.0</surefire-plugin.version>
|
|
||||||
<quarkus.version>0.23.2</quarkus.version>
|
<quarkus.version>0.23.2</quarkus.version>
|
||||||
|
<resteasy.version>4.3.0.Final</resteasy.version>
|
||||||
|
|
||||||
|
<surefire-plugin.version>2.22.0</surefire-plugin.version>
|
||||||
|
|
||||||
<wildfly.common.formmat.version>1.5.0.Final-format-001</wildfly.common.formmat.version>
|
<wildfly.common.formmat.version>1.5.0.Final-format-001</wildfly.common.formmat.version>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
|
@ -196,17 +196,14 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
<groupId>org.jboss.resteasy</groupId>
|
||||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||||
<version>${resteasy4.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
<groupId>org.jboss.resteasy</groupId>
|
||||||
<artifactId>resteasy-jackson2-provider</artifactId>
|
<artifactId>resteasy-jackson2-provider</artifactId>
|
||||||
<version>${resteasy4.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
<groupId>org.jboss.resteasy</groupId>
|
||||||
<artifactId>resteasy-core-spi</artifactId>
|
<artifactId>resteasy-core-spi</artifactId>
|
||||||
<version>${resteasy4.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wildfly.common</groupId>
|
<groupId>org.wildfly.common</groupId>
|
||||||
|
|
|
@ -113,11 +113,6 @@
|
||||||
<artifactId>resteasy-jaxrs</artifactId>
|
<artifactId>resteasy-jaxrs</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
|
||||||
<artifactId>resteasy-core</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.spec.javax.ws.rs</groupId>
|
<groupId>org.jboss.spec.javax.ws.rs</groupId>
|
||||||
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
|
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
|
|
||||||
package org.keycloak.common.util;
|
package org.keycloak.common.util;
|
||||||
|
|
||||||
import org.jboss.resteasy.core.Dispatcher;
|
import java.util.ServiceLoader;
|
||||||
import org.jboss.resteasy.core.ResteasyContext;
|
|
||||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Provides a layer of indirection to abstract invocations to Resteasy internal APIs. Making also possible to use different
|
* <p>Provides a layer of indirection to abstract invocations to Resteasy internal APIs. Making also possible to use different
|
||||||
|
@ -34,65 +32,14 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||||
*/
|
*/
|
||||||
public final class Resteasy {
|
public final class Resteasy {
|
||||||
|
|
||||||
private static final BiConsumer<Class, Object> PUSH_CONTEXT;
|
private static ResteasyProvider provider;
|
||||||
private static final BiConsumer<Class, Object> PUSH_DEFAULT_OBJECT;
|
|
||||||
private static final Function<Class, Object> PULL_CONTEXT;
|
|
||||||
private static final Runnable CLEAR_CONTEXT;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (isRestEasy4()) {
|
provider = ServiceLoader.load(ResteasyProvider.class, Resteasy.class.getClassLoader()).iterator().next();
|
||||||
PUSH_CONTEXT = new BiConsumer<Class, Object>() {
|
}
|
||||||
@Override
|
|
||||||
public void accept(Class p1, Object p2) {
|
public static ResteasyProvider getProvider() {
|
||||||
ResteasyContext.pushContext(p1, p2);
|
return provider;
|
||||||
}
|
|
||||||
};
|
|
||||||
PUSH_DEFAULT_OBJECT = new BiConsumer<Class, Object>() {
|
|
||||||
@Override
|
|
||||||
public void accept(Class p1, Object p2) {
|
|
||||||
ResteasyContext.getContextData(org.jboss.resteasy.spi.Dispatcher.class).getDefaultContextObjects()
|
|
||||||
.put(p1, p2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
PULL_CONTEXT = new Function<Class, Object>() {
|
|
||||||
@Override
|
|
||||||
public Object apply(Class p1) {
|
|
||||||
return ResteasyContext.getContextData(p1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
CLEAR_CONTEXT = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ResteasyContext.clearContextData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
PUSH_CONTEXT = new BiConsumer<Class, Object>() {
|
|
||||||
@Override
|
|
||||||
public void accept(Class p1, Object p2) {
|
|
||||||
ResteasyProviderFactory.getInstance().pushContext(p1, p2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
PUSH_DEFAULT_OBJECT = new BiConsumer<Class, Object>() {
|
|
||||||
@Override
|
|
||||||
public void accept(Class p1, Object p2) {
|
|
||||||
ResteasyProviderFactory.getInstance().getContextData(Dispatcher.class).getDefaultContextObjects()
|
|
||||||
.put(p1, p2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
PULL_CONTEXT = new Function<Class, Object>() {
|
|
||||||
@Override
|
|
||||||
public Object apply(Class p1) {
|
|
||||||
return ResteasyProviderFactory.getInstance().getContextData(p1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
CLEAR_CONTEXT = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ResteasyProviderFactory.getInstance().clearContextData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +49,7 @@ public final class Resteasy {
|
||||||
* @param instance the instance
|
* @param instance the instance
|
||||||
*/
|
*/
|
||||||
public static void pushContext(Class type, Object instance) {
|
public static void pushContext(Class type, Object instance) {
|
||||||
PUSH_CONTEXT.accept(type, instance);
|
provider.pushContext(type, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,14 +59,14 @@ public final class Resteasy {
|
||||||
* @return the instance associated with the given {@code type} or null if non-existent.
|
* @return the instance associated with the given {@code type} or null if non-existent.
|
||||||
*/
|
*/
|
||||||
public static <R> R getContextData(Class<R> type) {
|
public static <R> R getContextData(Class<R> type) {
|
||||||
return (R) PULL_CONTEXT.apply(type);
|
return provider.getContextData(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the Resteasy context associated with the current thread.
|
* Clear the Resteasy context associated with the current thread.
|
||||||
*/
|
*/
|
||||||
public static void clearContextData() {
|
public static void clearContextData() {
|
||||||
CLEAR_CONTEXT.run();
|
provider.clearContextData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,28 +76,7 @@ public final class Resteasy {
|
||||||
* @param instance the instance
|
* @param instance the instance
|
||||||
*/
|
*/
|
||||||
public static void pushDefaultContextObject(Class type, Object instance) {
|
public static void pushDefaultContextObject(Class type, Object instance) {
|
||||||
PUSH_DEFAULT_OBJECT.accept(type, instance);
|
provider.pushDefaultContextObject(type, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRestEasy4() {
|
|
||||||
try {
|
|
||||||
return Class.forName("org.jboss.resteasy.core.ResteasyContext") != null;
|
|
||||||
} catch (ClassNotFoundException ignore) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only necessary because keycloak-common is constrained to JDK 1.7.
|
|
||||||
*/
|
|
||||||
private interface BiConsumer<T, S> {
|
|
||||||
void accept(T p1, S p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only necessary because keycloak-common is constrained to JDK 1.7.
|
|
||||||
*/
|
|
||||||
private interface Function<T, R> {
|
|
||||||
R apply(T p1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.keycloak.common.util;
|
||||||
|
|
||||||
|
public interface ResteasyProvider {
|
||||||
|
|
||||||
|
<R> R getContextData(Class<R> type);
|
||||||
|
|
||||||
|
void pushDefaultContextObject(Class type, Object instance);
|
||||||
|
|
||||||
|
void pushContext(Class type, Object instance);
|
||||||
|
|
||||||
|
void clearContextData();
|
||||||
|
|
||||||
|
}
|
|
@ -108,6 +108,8 @@ public class KeycloakApplication extends Application {
|
||||||
|
|
||||||
public KeycloakApplication() {
|
public KeycloakApplication() {
|
||||||
try {
|
try {
|
||||||
|
logger.debugv("RestEasy provider: {0}", Resteasy.getProvider().getClass().getName());
|
||||||
|
|
||||||
ServletContext context = Resteasy.getContextData(ServletContext.class);
|
ServletContext context = Resteasy.getContextData(ServletContext.class);
|
||||||
|
|
||||||
if ("true".equals(context.getInitParameter(KEYCLOAK_EMBEDDED))) {
|
if ("true".equals(context.getInitParameter(KEYCLOAK_EMBEDDED))) {
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.keycloak.testsuite;
|
||||||
|
|
||||||
|
import org.jboss.resteasy.core.Dispatcher;
|
||||||
|
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||||
|
import org.keycloak.common.util.ResteasyProvider;
|
||||||
|
|
||||||
|
public class Resteasy3Provider implements ResteasyProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R> R getContextData(Class<R> type) {
|
||||||
|
return ResteasyProviderFactory.getInstance().getContextData(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushDefaultContextObject(Class type, Object instance) {
|
||||||
|
ResteasyProviderFactory.getInstance().getContextData(Dispatcher.class).getDefaultContextObjects()
|
||||||
|
.put(type, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushContext(Class type, Object instance) {
|
||||||
|
ResteasyProviderFactory.getInstance().pushContext(type, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearContextData() {
|
||||||
|
ResteasyProviderFactory.getInstance().clearContextData();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.keycloak.testsuite.Resteasy3Provider
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.keycloak.provider.wildfly;
|
||||||
|
|
||||||
|
import org.jboss.resteasy.core.Dispatcher;
|
||||||
|
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||||
|
import org.keycloak.common.util.ResteasyProvider;
|
||||||
|
|
||||||
|
public class Resteasy3Provider implements ResteasyProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R> R getContextData(Class<R> type) {
|
||||||
|
return ResteasyProviderFactory.getInstance().getContextData(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushDefaultContextObject(Class type, Object instance) {
|
||||||
|
ResteasyProviderFactory.getInstance().getContextData(Dispatcher.class).getDefaultContextObjects()
|
||||||
|
.put(type, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pushContext(Class type, Object instance) {
|
||||||
|
ResteasyProviderFactory.getInstance().pushContext(type, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearContextData() {
|
||||||
|
ResteasyProviderFactory.getInstance().clearContextData();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.keycloak.provider.wildfly.Resteasy3Provider
|
Loading…
Reference in a new issue