diff --git a/distribution/feature-packs/server-feature-pack/src/main/resources/modules/system/layers/keycloak/org/keycloak/keycloak-wildfly-extensions/main/module.xml b/distribution/feature-packs/server-feature-pack/src/main/resources/modules/system/layers/keycloak/org/keycloak/keycloak-wildfly-extensions/main/module.xml index 89aa901572..31d44a78c1 100755 --- a/distribution/feature-packs/server-feature-pack/src/main/resources/modules/system/layers/keycloak/org/keycloak/keycloak-wildfly-extensions/main/module.xml +++ b/distribution/feature-packs/server-feature-pack/src/main/resources/modules/system/layers/keycloak/org/keycloak/keycloak-wildfly-extensions/main/module.xml @@ -31,5 +31,6 @@ + diff --git a/pom.xml b/pom.xml index f94bd512bc..c26a9ea714 100755 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,6 @@ 1.0.3.Final 1.2.17 3.7.0.Final - 4.3.1.Final 3.7.0.Final 20180219.1 1.7.22 @@ -316,25 +315,6 @@ - - org.jboss.resteasy - resteasy-core - ${resteasy4.version} - - - log4j - log4j - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-simple - - - org.jboss.resteasy resteasy-multipart-provider diff --git a/quarkus/extensions/pom.xml b/quarkus/extensions/pom.xml index 2b917f7f58..d7a29b8c7e 100644 --- a/quarkus/extensions/pom.xml +++ b/quarkus/extensions/pom.xml @@ -13,6 +13,28 @@ keycloak-quarkus-extensions + + org.jboss.resteasy + resteasy-core + + + log4j + log4j + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-simple + + + + + org.keycloak + keycloak-services + diff --git a/quarkus/extensions/src/main/java/org/keycloak/provider/quarkus/Resteasy4Provider.java b/quarkus/extensions/src/main/java/org/keycloak/provider/quarkus/Resteasy4Provider.java new file mode 100644 index 0000000000..1209f44c5b --- /dev/null +++ b/quarkus/extensions/src/main/java/org/keycloak/provider/quarkus/Resteasy4Provider.java @@ -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 getContextData(Class 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(); + } + +} diff --git a/quarkus/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider b/quarkus/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider new file mode 100644 index 0000000000..c28f7809e0 --- /dev/null +++ b/quarkus/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider @@ -0,0 +1 @@ +org.keycloak.provider.quarkus.Resteasy4Provider \ No newline at end of file diff --git a/quarkus/pom.xml b/quarkus/pom.xml index c34a61fa21..722f31ece5 100755 --- a/quarkus/pom.xml +++ b/quarkus/pom.xml @@ -31,8 +31,11 @@ pom - 2.22.0 0.23.2 + 4.3.0.Final + + 2.22.0 + 1.5.0.Final-format-001 1.8 UTF-8 diff --git a/quarkus/server/pom.xml b/quarkus/server/pom.xml index 91fb86d196..8d321456b0 100644 --- a/quarkus/server/pom.xml +++ b/quarkus/server/pom.xml @@ -196,17 +196,14 @@ org.jboss.resteasy resteasy-jaxb-provider - ${resteasy4.version} org.jboss.resteasy resteasy-jackson2-provider - ${resteasy4.version} org.jboss.resteasy resteasy-core-spi - ${resteasy4.version} org.wildfly.common diff --git a/services/pom.xml b/services/pom.xml index c079560735..655e1de0e3 100755 --- a/services/pom.xml +++ b/services/pom.xml @@ -113,11 +113,6 @@ resteasy-jaxrs provided - - org.jboss.resteasy - resteasy-core - true - org.jboss.spec.javax.ws.rs jboss-jaxrs-api_2.1_spec diff --git a/services/src/main/java/org/keycloak/common/util/Resteasy.java b/services/src/main/java/org/keycloak/common/util/Resteasy.java index 206247dc73..754b25dbb3 100644 --- a/services/src/main/java/org/keycloak/common/util/Resteasy.java +++ b/services/src/main/java/org/keycloak/common/util/Resteasy.java @@ -17,9 +17,7 @@ package org.keycloak.common.util; -import org.jboss.resteasy.core.Dispatcher; -import org.jboss.resteasy.core.ResteasyContext; -import org.jboss.resteasy.spi.ResteasyProviderFactory; +import java.util.ServiceLoader; /** *

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 { - private static final BiConsumer PUSH_CONTEXT; - private static final BiConsumer PUSH_DEFAULT_OBJECT; - private static final Function PULL_CONTEXT; - private static final Runnable CLEAR_CONTEXT; + private static ResteasyProvider provider; static { - if (isRestEasy4()) { - PUSH_CONTEXT = new BiConsumer() { - @Override - public void accept(Class p1, Object p2) { - ResteasyContext.pushContext(p1, p2); - } - }; - PUSH_DEFAULT_OBJECT = new BiConsumer() { - @Override - public void accept(Class p1, Object p2) { - ResteasyContext.getContextData(org.jboss.resteasy.spi.Dispatcher.class).getDefaultContextObjects() - .put(p1, p2); - } - }; - PULL_CONTEXT = new Function() { - @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() { - @Override - public void accept(Class p1, Object p2) { - ResteasyProviderFactory.getInstance().pushContext(p1, p2); - } - }; - PUSH_DEFAULT_OBJECT = new BiConsumer() { - @Override - public void accept(Class p1, Object p2) { - ResteasyProviderFactory.getInstance().getContextData(Dispatcher.class).getDefaultContextObjects() - .put(p1, p2); - } - }; - PULL_CONTEXT = new Function() { - @Override - public Object apply(Class p1) { - return ResteasyProviderFactory.getInstance().getContextData(p1); - } - }; - CLEAR_CONTEXT = new Runnable() { - @Override - public void run() { - ResteasyProviderFactory.getInstance().clearContextData(); - } - }; - } + provider = ServiceLoader.load(ResteasyProvider.class, Resteasy.class.getClassLoader()).iterator().next(); + } + + public static ResteasyProvider getProvider() { + return provider; } /** @@ -102,7 +49,7 @@ public final class Resteasy { * @param instance the 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. */ public static R getContextData(Class type) { - return (R) PULL_CONTEXT.apply(type); + return provider.getContextData(type); } /** * Clear the Resteasy context associated with the current thread. */ public static void clearContextData() { - CLEAR_CONTEXT.run(); + provider.clearContextData(); } /** @@ -129,28 +76,7 @@ public final class Resteasy { * @param instance the 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 { - void accept(T p1, S p2); - } - - /** - * Only necessary because keycloak-common is constrained to JDK 1.7. - */ - private interface Function { - R apply(T p1); - } } diff --git a/services/src/main/java/org/keycloak/common/util/ResteasyProvider.java b/services/src/main/java/org/keycloak/common/util/ResteasyProvider.java new file mode 100644 index 0000000000..5cca0ffceb --- /dev/null +++ b/services/src/main/java/org/keycloak/common/util/ResteasyProvider.java @@ -0,0 +1,13 @@ +package org.keycloak.common.util; + +public interface ResteasyProvider { + + R getContextData(Class type); + + void pushDefaultContextObject(Class type, Object instance); + + void pushContext(Class type, Object instance); + + void clearContextData(); + +} diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java index e7154e39e7..8bd2965f32 100644 --- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java +++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java @@ -108,6 +108,8 @@ public class KeycloakApplication extends Application { public KeycloakApplication() { try { + logger.debugv("RestEasy provider: {0}", Resteasy.getProvider().getClass().getName()); + ServletContext context = Resteasy.getContextData(ServletContext.class); if ("true".equals(context.getInitParameter(KEYCLOAK_EMBEDDED))) { diff --git a/testsuite/utils/src/main/java/org/keycloak/testsuite/Resteasy3Provider.java b/testsuite/utils/src/main/java/org/keycloak/testsuite/Resteasy3Provider.java new file mode 100644 index 0000000000..e008396e0a --- /dev/null +++ b/testsuite/utils/src/main/java/org/keycloak/testsuite/Resteasy3Provider.java @@ -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 getContextData(Class 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(); + } + +} diff --git a/testsuite/utils/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider b/testsuite/utils/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider new file mode 100644 index 0000000000..81e6d35653 --- /dev/null +++ b/testsuite/utils/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider @@ -0,0 +1 @@ +org.keycloak.testsuite.Resteasy3Provider \ No newline at end of file diff --git a/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/Resteasy3Provider.java b/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/Resteasy3Provider.java new file mode 100644 index 0000000000..590477fc97 --- /dev/null +++ b/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/Resteasy3Provider.java @@ -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 getContextData(Class 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(); + } + +} diff --git a/wildfly/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider b/wildfly/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider new file mode 100644 index 0000000000..260db8b309 --- /dev/null +++ b/wildfly/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider @@ -0,0 +1 @@ +org.keycloak.provider.wildfly.Resteasy3Provider \ No newline at end of file