diff --git a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientAnnotationProviderBuildItem.java b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientAnnotationProviderBuildItem.java index 57898d4361e4f..afe6d2982b18e 100644 --- a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientAnnotationProviderBuildItem.java +++ b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientAnnotationProviderBuildItem.java @@ -2,12 +2,12 @@ import org.jboss.jandex.DotName; -import io.quarkus.builder.item.SimpleBuildItem; +import io.quarkus.builder.item.MultiBuildItem; /** * Used to mark a custom annotation and its associated JAX-RS client provider */ -public final class RestClientAnnotationProviderBuildItem extends SimpleBuildItem { +public final class RestClientAnnotationProviderBuildItem extends MultiBuildItem { private final DotName annotationName; private final Class providerClass; @@ -17,6 +17,11 @@ public RestClientAnnotationProviderBuildItem(DotName annotationName, Class pr this.providerClass = providerClass; } + public RestClientAnnotationProviderBuildItem(String annotationName, Class providerClass) { + this.annotationName = DotName.createSimple(annotationName); + this.providerClass = providerClass; + } + public DotName getAnnotationName() { return annotationName; } diff --git a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java index 530b86500bb86..e5903c814d783 100644 --- a/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java +++ b/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java @@ -170,7 +170,7 @@ void processInterfaces( BeanArchiveIndexBuildItem beanArchiveIndexBuildItem, Capabilities capabilities, PackageConfig packageConfig, - Optional restClientAnnotationProvider, + List restClientAnnotationProviders, BuildProducer proxyDefinition, BuildProducer reflectiveClass, BuildProducer reflectiveHierarchy, @@ -237,20 +237,28 @@ public void register(RegistrationContext registrationContext) { configurator.addQualifier(REST_CLIENT); final String configPrefix = computeConfigPrefix(restClientName.toString(), entry.getValue()); final ScopeInfo scope = computeDefaultScope(capabilities, config, entry, configPrefix); - final Class annotationProvider = checkAnnotationProviders(entry.getValue(), - restClientAnnotationProvider.orElse(null)); + final List> annotationProviders = checkAnnotationProviders(entry.getValue(), + restClientAnnotationProviders); configurator.scope(scope); configurator.creator(m -> { // return new RestClientBase(proxyType, baseUri).create(); ResultHandle interfaceHandle = m.loadClass(restClientName.toString()); ResultHandle baseUriHandle = m.load(getAnnotationParameter(entry.getValue(), "baseUri")); ResultHandle configPrefixHandle = m.load(configPrefix); - ResultHandle annotationProviderHandle = annotationProvider == null ? m.loadNull() - : m.loadClass(annotationProvider); + ResultHandle annotationProvidersHandle = null; + if (!annotationProviders.isEmpty()) { + annotationProvidersHandle = m.newArray(Class.class, annotationProviders.size()); + for (int i = 0; i < annotationProviders.size(); i++) { + m.writeArrayValue(annotationProvidersHandle, i, m.loadClass(annotationProviders.get(i))); + } + } else { + annotationProvidersHandle = m.loadNull(); + } ResultHandle baseHandle = m.newInstance( - MethodDescriptor.ofConstructor(RestClientBase.class, Class.class, String.class, String.class, - Class.class), - interfaceHandle, baseUriHandle, configPrefixHandle, annotationProviderHandle); + MethodDescriptor.ofConstructor(RestClientBase.class, Class.class, String.class, + String.class, + Class[].class), + interfaceHandle, baseUriHandle, configPrefixHandle, annotationProvidersHandle); ResultHandle ret = m.invokeVirtualMethod( MethodDescriptor.ofMethod(RestClientBase.class, "create", Object.class), baseHandle); m.returnValue(ret); @@ -262,13 +270,10 @@ public void register(RegistrationContext registrationContext) { })); } - private static Class checkAnnotationProviders(ClassInfo classInfo, - RestClientAnnotationProviderBuildItem restClientAnnotationProvider) { - if (restClientAnnotationProvider != null - && classInfo.classAnnotation(restClientAnnotationProvider.getAnnotationName()) != null) { - return restClientAnnotationProvider.getProviderClass(); - } - return null; + private static List> checkAnnotationProviders(ClassInfo classInfo, + List restClientAnnotationProviders) { + return restClientAnnotationProviders.stream().filter(p -> (classInfo.classAnnotation(p.getAnnotationName()) != null)) + .map(p -> p.getProviderClass()).collect(Collectors.toList()); } @BuildStep diff --git a/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientBase.java b/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientBase.java index de032210683f9..21bb933bdf6e5 100644 --- a/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientBase.java +++ b/extensions/rest-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientBase.java @@ -49,14 +49,14 @@ public class RestClientBase { private final Class proxyType; private final String baseUriFromAnnotation; private final String propertyPrefix; - private final Class annotationProvider; + private final Class[] annotationProviders; public RestClientBase(Class proxyType, String baseUriFromAnnotation, String propertyPrefix, - Class annotationProvider) { + Class[] annotationProviders) { this.proxyType = proxyType; this.baseUriFromAnnotation = baseUriFromAnnotation; this.propertyPrefix = propertyPrefix; - this.annotationProvider = annotationProvider; + this.annotationProviders = annotationProviders; } public Object create() { @@ -202,8 +202,10 @@ private void configureProviders(RestClientBuilder builder) { if (maybeProviders.isPresent()) { registerProviders(builder, maybeProviders.get()); } - if (annotationProvider != null) { - builder.register(annotationProvider); + if (annotationProviders != null) { + for (Class annotationProvider : annotationProviders) { + builder.register(annotationProvider); + } } } diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java index de0b2406f5a7b..8e6ca3308c1e8 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java @@ -401,6 +401,24 @@ public void testProjectWithExtension() throws MavenInvocationException, IOExcept assertEquals(3, extDepWarnings.size()); } + @Test + public void testRestClientCustomHeadersExtension() throws MavenInvocationException, IOException { + testDir = getTargetDir("projects/rest-client-custom-headers-extension"); + runAndCheck(); + + final List extDepWarnings = Files + .readAllLines(testDir.toPath().resolve("build-rest-client-custom-headers-extension.log")) + .stream() + .filter(s -> s.startsWith( + "[WARNING] [io.quarkus.bootstrap.devmode.DependenciesFilter] Local Quarkus extension dependency ")) + .collect(Collectors.toList()); + assertTrue(extDepWarnings + .contains( + "[WARNING] [io.quarkus.bootstrap.devmode.DependenciesFilter] Local Quarkus extension dependency org.acme:rest-client-custom-headers will not be hot-reloadable")); + + assertThat(DevModeTestUtils.getHttpResponse("/app/frontend")).isEqualTo("CustomValue1 CustomValue2"); + } + @Test public void testThatTheApplicationIsReloadedMultiModule() throws MavenInvocationException, IOException { testDir = initProject("projects/multimodule", "projects/multimodule-with-deps"); diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/pom.xml b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/pom.xml new file mode 100644 index 0000000000000..22d6d5dca21a6 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + org.acme + quarkus-extensions-parent + 1.0-SNAPSHOT + pom + + + io.quarkus + quarkus-bom + @project.version@ + @project.version@ + 3.0.0-M5 + UTF-8 + 1.8 + 1.8 + + + rest-client-custom-headers + runner + + + + + + io.quarkus + quarkus-maven-plugin + \${quarkus-plugin.version} + + + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + org.acme + rest-client-custom-headers + 1.0-SNAPSHOT + + + + + diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/deployment/pom.xml b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/deployment/pom.xml new file mode 100644 index 0000000000000..0cccf718e385b --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/deployment/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + org.acme + rest-client-custom-headers-parent + 1.0-SNAPSHOT + ../pom.xml + + + rest-client-custom-headers-deployment + Rest Client Custom Headers - Deployment + + + + io.quarkus + quarkus-arc-deployment + + + io.quarkus + quarkus-core-deployment + + + io.quarkus + quarkus-rest-client-deployment + + + org.acme + rest-client-custom-headers + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + \${quarkus.version} + + + + + + + diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/deployment/src/main/java/org/acme/deployment/ExtensionBuildStep.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/deployment/src/main/java/org/acme/deployment/ExtensionBuildStep.java new file mode 100644 index 0000000000000..7044b472a7a5f --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/deployment/src/main/java/org/acme/deployment/ExtensionBuildStep.java @@ -0,0 +1,24 @@ +package org.acme.deployment; + +import io.quarkus.arc.deployment.AdditionalBeanBuildItem; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.restclient.deployment.RestClientAnnotationProviderBuildItem; +import org.acme.CustomHeader1Filter; +import org.acme.CustomHeader2Filter; + + +public class ExtensionBuildStep { + + @BuildStep + void registerProvider(BuildProducer additionalBeans, + BuildProducer restAnnotationProvider) { + additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(CustomHeader1Filter.class)); + additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(CustomHeader2Filter.class)); + + restAnnotationProvider.produce(new RestClientAnnotationProviderBuildItem("org.acme.CustomHeader1", + CustomHeader1Filter.class)); + restAnnotationProvider.produce(new RestClientAnnotationProviderBuildItem("org.acme.CustomHeader2", + CustomHeader2Filter.class)); + } +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/pom.xml b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/pom.xml new file mode 100644 index 0000000000000..b623a23860d0a --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + org.acme + quarkus-extensions-parent + 1.0-SNAPSHOT + ../pom.xml + + + rest-client-custom-headers-parent + Rest Client Custom Headers - Parent + + pom + + + UTF-8 + UTF-8 + 1.8 + 1.8 + true + @project.version@ + 3.8.1 + + + + runtime + deployment + + + + + + org.apache.maven.plugins + maven-compiler-plugin + \${compiler-plugin.version} + + + + + diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/pom.xml b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/pom.xml new file mode 100644 index 0000000000000..53e512ecc0416 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + org.acme + rest-client-custom-headers-parent + 1.0-SNAPSHOT + ../pom.xml + + + rest-client-custom-headers + Rest Client Custom Headers - Runtime + + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-core + + + io.quarkus + quarkus-rest-client + + + + + + + io.quarkus + quarkus-bootstrap-maven-plugin + \${quarkus.version} + + + + extension-descriptor + + compile + + org.acme:rest-client-custom-headers-deployment:1.0-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + \${quarkus.version} + + + + + + + diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader1.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader1.java new file mode 100644 index 0000000000000..d86abe91e51a8 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader1.java @@ -0,0 +1,13 @@ +package org.acme; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface CustomHeader1 { +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader1Filter.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader1Filter.java new file mode 100644 index 0000000000000..312dd854f53b6 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader1Filter.java @@ -0,0 +1,21 @@ +package org.acme; + +import java.io.IOException; + +import javax.annotation.Priority; +import javax.inject.Singleton; +import javax.ws.rs.Priorities; +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientRequestFilter; +import javax.ws.rs.ext.Provider; + +@Provider +@Singleton +@Priority(Priorities.AUTHENTICATION) +public class CustomHeader1Filter implements ClientRequestFilter { + + @Override + public void filter(ClientRequestContext requestContext) throws IOException { + requestContext.getHeaders().add("CustomHeader1", "CustomValue1"); + } +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader2.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader2.java new file mode 100644 index 0000000000000..d51202b65f9d6 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader2.java @@ -0,0 +1,13 @@ +package org.acme; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface CustomHeader2 { +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader2Filter.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader2Filter.java new file mode 100644 index 0000000000000..007ff31e966c7 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/rest-client-custom-headers/runtime/src/main/java/org/acme/CustomHeader2Filter.java @@ -0,0 +1,21 @@ +package org.acme; + +import java.io.IOException; + +import javax.annotation.Priority; +import javax.inject.Singleton; +import javax.ws.rs.Priorities; +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientRequestFilter; +import javax.ws.rs.ext.Provider; + +@Provider +@Singleton +@Priority(Priorities.AUTHENTICATION) +public class CustomHeader2Filter implements ClientRequestFilter { + + @Override + public void filter(ClientRequestContext requestContext) throws IOException { + requestContext.getHeaders().add("CustomHeader2", "CustomValue2"); + } +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/pom.xml b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/pom.xml new file mode 100644 index 0000000000000..c5085569b958f --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + + org.acme + quarkus-extensions-parent + 1.0-SNAPSHOT + + org.acme + quarkus-extensions-main + 1.0-SNAPSHOT + + + + + io.quarkus + quarkus-resteasy + + + org.acme + rest-client-custom-headers + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + + maven-surefire-plugin + \${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + \${maven.home} + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + build + + + + + + + + + + + native + + + native + + + + native + + + + + org.apache.maven.plugins + maven-surefire-plugin + + \${native.surefire.skip} + + + + maven-failsafe-plugin + \${surefire-plugin.version} + + + + integration-test + verify + + + + \${project.build.directory}/\${project.build.finalName}-runner + org.jboss.logmanager.LogManager + \${maven.home} + + + + + + + + + + diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/DownstreamService.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/DownstreamService.java new file mode 100644 index 0000000000000..cf0fa28643af6 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/DownstreamService.java @@ -0,0 +1,14 @@ +package org.acme; + +import javax.ws.rs.HeaderParam; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/downstream") +public class DownstreamService { + + @GET + public String getHeaders(@HeaderParam("CustomHeader1") String customHeader1, @HeaderParam("CustomHeader2") String customHeader2) { + return customHeader1 + " " + customHeader2; + } +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/DownstreamServiceClient.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/DownstreamServiceClient.java new file mode 100644 index 0000000000000..cb7593fc50209 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/DownstreamServiceClient.java @@ -0,0 +1,18 @@ +package org.acme; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.acme.CustomHeader1; +import org.acme.CustomHeader2; +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@RegisterRestClient +@CustomHeader1 +@CustomHeader2 +@Path("/") +public interface DownstreamServiceClient { + + @GET + String getHeaders(); +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/FrontendService.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/FrontendService.java new file mode 100644 index 0000000000000..640c18524440e --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/FrontendService.java @@ -0,0 +1,19 @@ +package org.acme; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.eclipse.microprofile.rest.client.inject.RestClient; + +@Path("/frontend") +public class FrontendService { + @Inject + @RestClient + DownstreamServiceClient client; + + @GET + public String getHeaders() { + return client.getHeaders(); + } +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/HelloResource.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/HelloResource.java new file mode 100644 index 0000000000000..e05e3fc81410a --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/HelloResource.java @@ -0,0 +1,16 @@ +package org.acme; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/MyApplication.java b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/MyApplication.java new file mode 100644 index 0000000000000..2b41cd0385afb --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/java/org/acme/MyApplication.java @@ -0,0 +1,9 @@ +package org.acme; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/app") +public class MyApplication extends Application { + +} diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/resources/META-INF/resources/index.html b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/resources/META-INF/resources/index.html new file mode 100644 index 0000000000000..b5da1d7d71f02 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,155 @@ + + + + + getting-started - 1.0-SNAPSHOT + + + + + + +
+
+

Congratulations, you have created a new Quarkus application.

+ +

Why do you see this?

+ +

This page is served by Quarkus. The source is in + src/main/resources/META-INF/resources/index.html.

+ +

What can I do from here?

+ +

If not already done, run the application in dev mode using: mvn compile quarkus:dev. +

+
    +
  • Add REST resources, Servlets, functions and other services in src/main/java.
  • +
  • Your static assets are located in src/main/resources/META-INF/resources.
  • +
  • Configure your application in src/main/resources/META-INF/microprofile-config.properties. +
  • +
+ +

Do you like Quarkus?

+

Go give it a star on GitHub.

+ +

How do I get rid of this page?

+

Just delete the src/main/resources/META-INF/resources/index.html file.

+
+
+
+

Application

+
    +
  • GroupId: org.acme
  • +
  • ArtifactId: getting-started
  • +
  • Version: 1.0-SNAPSHOT
  • +
  • Quarkus Version: 0.11.0
  • +
+
+ +
+
+ + + + \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/resources/application.properties b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/resources/application.properties new file mode 100644 index 0000000000000..07ee2d7dd9084 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/rest-client-custom-headers-extension/runner/src/main/resources/application.properties @@ -0,0 +1 @@ +org.acme.DownstreamServiceClient/mp-rest/url=http://localhost:8080/app/downstream diff --git a/integration-tests/oidc-token-propagation/pom.xml b/integration-tests/oidc-token-propagation/pom.xml index 9f93166d5f6d7..109801f856868 100644 --- a/integration-tests/oidc-token-propagation/pom.xml +++ b/integration-tests/oidc-token-propagation/pom.xml @@ -72,6 +72,23 @@ + + io.quarkus + quarkus-oidc-client-filter + + + io.quarkus + quarkus-oidc-client-filter-deployment + ${project.version} + pom + test + + + * + * + + + io.quarkus diff --git a/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/FrontendResource.java b/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/FrontendResource.java index b03713bdafdfa..742a206b563f6 100644 --- a/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/FrontendResource.java +++ b/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/FrontendResource.java @@ -7,19 +7,26 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; -import io.quarkus.security.Authenticated; - @Path("/frontend") -@Authenticated public class FrontendResource { @Inject @RestClient - ProtectedResourceService protectedResourceService; + TokenPropagationService tokenPropagationService; + + @Inject + @RestClient + ServiceAccountService serviceAccountService; @GET - @Path("user") + @Path("token-propagation") @RolesAllowed("user") - public String userName() { - return protectedResourceService.getUserName(); + public String userNameTokenPropagation() { + return tokenPropagationService.getUserName(); + } + + @GET + @Path("service-account") + public String userNameServiceAccount() { + return serviceAccountService.getUserName(); } } diff --git a/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/ServiceAccountService.java b/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/ServiceAccountService.java new file mode 100644 index 0000000000000..014fcdee418d6 --- /dev/null +++ b/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/ServiceAccountService.java @@ -0,0 +1,17 @@ +package io.quarkus.it.keycloak; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +import io.quarkus.oidc.client.filter.OidcClientFilter; + +@RegisterRestClient +@OidcClientFilter +@Path("/") +public interface ServiceAccountService { + + @GET + String getUserName(); +} diff --git a/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/ProtectedResourceService.java b/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/TokenPropagationService.java similarity index 86% rename from integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/ProtectedResourceService.java rename to integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/TokenPropagationService.java index eee833b25119c..ac1c20bea4666 100644 --- a/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/ProtectedResourceService.java +++ b/integration-tests/oidc-token-propagation/src/main/java/io/quarkus/it/keycloak/TokenPropagationService.java @@ -10,7 +10,7 @@ @RegisterRestClient @AccessToken @Path("/") -public interface ProtectedResourceService { +public interface TokenPropagationService { @GET String getUserName(); diff --git a/integration-tests/oidc-token-propagation/src/main/resources/application.properties b/integration-tests/oidc-token-propagation/src/main/resources/application.properties index 472429c69500b..db1575f3f07a7 100644 --- a/integration-tests/oidc-token-propagation/src/main/resources/application.properties +++ b/integration-tests/oidc-token-propagation/src/main/resources/application.properties @@ -2,5 +2,13 @@ quarkus.oidc.auth-server-url=${keycloak.url}/realms/quarkus/ quarkus.oidc.client-id=quarkus-app quarkus.oidc.credentials.secret=secret -io.quarkus.it.keycloak.ProtectedResourceService/mp-rest/uri=http://localhost:8081/protected +quarkus.oidc-client.auth-server-url=${quarkus.oidc.auth-server-url} +quarkus.oidc-client.client-id=${quarkus.oidc.client-id} +quarkus.oidc-client.credentials.secret=${quarkus.oidc.credentials.secret} +quarkus.oidc-client.grant.type=password +quarkus.oidc-client.grant-options.password.username=bob +quarkus.oidc-client.grant-options.password.password=bob + +io.quarkus.it.keycloak.TokenPropagationService/mp-rest/uri=http://localhost:8081/protected +io.quarkus.it.keycloak.ServiceAccountService/mp-rest/uri=http://localhost:8081/protected diff --git a/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/KeycloakRealmResourceManager.java b/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/KeycloakRealmResourceManager.java index 10acd87334896..f2fbe961d02cb 100644 --- a/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/KeycloakRealmResourceManager.java +++ b/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/KeycloakRealmResourceManager.java @@ -34,6 +34,7 @@ public Map start() { realm.getClients().add(createClient("quarkus-app")); realm.getUsers().add(createUser("alice", "user")); + realm.getUsers().add(createUser("bob", "user")); try { RestAssured diff --git a/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/OidcTokenPropagationTest.java b/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/OidcTokenPropagationTest.java index b745844378a97..9c97d867425c1 100644 --- a/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/OidcTokenPropagationTest.java +++ b/integration-tests/oidc-token-propagation/src/test/java/io/quarkus/it/keycloak/OidcTokenPropagationTest.java @@ -13,11 +13,19 @@ public class OidcTokenPropagationTest { @Test - public void testGetUserNameOidcClient() { + public void testGetUserNameWithTokenPropagation() { RestAssured.given().auth().oauth2(KeycloakRealmResourceManager.getAccessToken("alice")) - .when().get("/frontend/user") + .when().get("/frontend/token-propagation") .then() .statusCode(200) .body(equalTo("alice")); } + + @Test + public void testGetUserNameFromServiceAccount() { + RestAssured.when().get("/frontend/service-account") + .then() + .statusCode(200) + .body(equalTo("bob")); + } }