From 8672fd12ef5f0a0ea4c51cc24aa7dfb061ed1075 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 27 May 2020 12:37:04 +0200 Subject: [PATCH 1/6] Provider as a bean defining annotation. Signed-off-by: Tomas Langer --- .../io/helidon/microprofile/cdi/HelidonContainerImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/HelidonContainerImpl.java b/microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/HelidonContainerImpl.java index f7485f9d34e..74145c9dd7d 100644 --- a/microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/HelidonContainerImpl.java +++ b/microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/HelidonContainerImpl.java @@ -141,7 +141,9 @@ void initInContext() { private HelidonContainerImpl init() { LOGGER.fine(() -> "Initializing CDI container " + id); - addHelidonBeanDefiningAnnotations("javax.ws.rs.Path", "javax.websocket.server.ServerEndpoint"); + addHelidonBeanDefiningAnnotations("javax.ws.rs.Path", + "javax.ws.rs.ext.Provider", + "javax.websocket.server.ServerEndpoint"); ResourceLoader resourceLoader = new WeldResourceLoader() { @Override From 009435b400d50030768ce2b657a8b49b0859e6e7 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 27 May 2020 13:05:05 +0200 Subject: [PATCH 2/6] Automatic discovery of JAX-RS providers. Signed-off-by: Tomas Langer --- .../server/JaxRsCdiExtension.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsCdiExtension.java b/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsCdiExtension.java index 4708f228374..9dfdb760085 100644 --- a/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsCdiExtension.java +++ b/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsCdiExtension.java @@ -41,6 +41,7 @@ import javax.ws.rs.core.Application; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; import io.helidon.common.HelidonFeatures; import io.helidon.common.HelidonFlavor; @@ -66,6 +67,7 @@ public class JaxRsCdiExtension implements Extension { private final Set> applications = new LinkedHashSet<>(); private final Set> resources = new HashSet<>(); + private final Set> providers = new HashSet<>(); private final AtomicBoolean setInStone = new AtomicBoolean(false); private void collectApplications(@Observes ProcessAnnotatedType applicationType) { @@ -82,6 +84,18 @@ private void collectResourceClasses(@Observes @WithAnnotations(Path.class) Proce resources.add(resourceClass); } + private void collectProviderClasses(@Observes @WithAnnotations(Provider.class) ProcessAnnotatedType providerType) { + Class providerClass = providerType.getAnnotatedType().getJavaClass(); + if (providerClass.isInterface()) { + // we are only interested in classes + LOGGER.finest(() -> "Discovered @Provider interface " + providerClass + .getName() + ", ignored as we only support classes"); + return; + } + LOGGER.finest(() -> "Discovered @Provider class " + providerClass.getName()); + providers.add(providerClass); + } + // once application scoped starts, we do not allow modification of applications void fixApps(@Observes @Priority(PLATFORM_BEFORE) @Initialized(ApplicationScoped.class) Object event) { this.setInStone.set(true); @@ -102,10 +116,16 @@ public List applicationsToRun() throws IllegalStateException { throw new IllegalStateException("Applications are not yet fixed. This method is only available in " + "@Initialized(ApplicationScoped.class) event, before server is started"); } + + // set of resource and provider classes that were discovered + Set> allClasses = new HashSet<>(); + allClasses.addAll(resources); + allClasses.addAll(providers); + if (applications.isEmpty() && applicationMetas.isEmpty()) { // create a synthetic application from all resource classes if (!resources.isEmpty()) { - addSyntheticApp(resources); + addSyntheticApp(allClasses); } } @@ -114,7 +134,7 @@ public List applicationsToRun() throws IllegalStateException { .stream() .map(appClass -> JaxRsApplication.builder() .applicationClass(appClass) - .config(ResourceConfig.forApplicationClass(appClass, resources)) + .config(ResourceConfig.forApplicationClass(appClass, allClasses)) .build()) .collect(Collectors.toList())); @@ -238,7 +258,7 @@ public void addSyntheticApplication(List> resourceClasses) throws Illeg // set-up synthetic application from resource classes private void addSyntheticApp(Collection> resourceClasses) { // the classes set must be created before the lambda, as the incoming collection may be mutable - Set> classes = new HashSet<>(resourceClasses); + Set> classes = Set.copyOf(resourceClasses); this.applicationMetas.add(JaxRsApplication.builder() .synthetic(true) .applicationClass(Application.class) From 26352b807f8d790fe183507ea859a0a518ddd548 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 27 May 2020 13:05:30 +0200 Subject: [PATCH 3/6] Removed provider annotation so filter is not autodiscovered, as already part of automatic feature. Signed-off-by: Tomas Langer --- .../integration/jersey/client/ClientSecurityFilter.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/security/integration/jersey-client/src/main/java/io/helidon/security/integration/jersey/client/ClientSecurityFilter.java b/security/integration/jersey-client/src/main/java/io/helidon/security/integration/jersey/client/ClientSecurityFilter.java index 5f12a85a1e0..e996a9b8474 100644 --- a/security/integration/jersey-client/src/main/java/io/helidon/security/integration/jersey/client/ClientSecurityFilter.java +++ b/security/integration/jersey-client/src/main/java/io/helidon/security/integration/jersey/client/ClientSecurityFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.Provider; import io.helidon.common.HelidonFeatures; import io.helidon.common.context.Contexts; @@ -48,7 +47,6 @@ * Only works as part of integration with Security component. * This class is public to allow unit testing from providers (without invoking an HTTP request) */ -@Provider @ConstrainedTo(RuntimeType.CLIENT) @Priority(Priorities.AUTHENTICATION) public class ClientSecurityFilter implements ClientRequestFilter { From a721b0b3254fc5342f52cf4ea3a5c2f09bc566e2 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 27 May 2020 13:51:46 +0200 Subject: [PATCH 4/6] Removed deprecated provider. Signed-off-by: Tomas Langer --- .../jersey/ClientSecurityFeature.java | 75 -------- .../jersey/ClientSecurityFilter.java | 165 ------------------ .../integration/jersey/SecureClient.java | 65 ------- .../integration/jersey/TestResource1.java | 2 - 4 files changed, 307 deletions(-) delete mode 100644 security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFeature.java delete mode 100644 security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFilter.java delete mode 100644 security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecureClient.java diff --git a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFeature.java b/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFeature.java deleted file mode 100644 index e52421fb4d8..00000000000 --- a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFeature.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.helidon.security.integration.jersey; - -import javax.ws.rs.RuntimeType; -import javax.ws.rs.core.Feature; -import javax.ws.rs.core.FeatureContext; - -/** - * Integration of Security module with Jersey clients. - * If you want to use this class, please inject it as a context and then - * register it on your {@link javax.ws.rs.client.Client}. - * - * @deprecated replaced with {@code io.helidon.security.integration.jersey.client.ClientSecurity} for constants - * the feature is no longer needed to configure security - */ -@Deprecated -public final class ClientSecurityFeature implements Feature { - - /** - * Property name for security context. Set this with - * {@link javax.ws.rs.client.Invocation.Builder#property(String, Object)}, obtained - * through {@link javax.ws.rs.client.WebTarget#request()} - * - * @deprecated use {@code ClientSecurity} constants instead - */ - @Deprecated - public static final String PROPERTY_CONTEXT = "io.helidon.security.jersey.SecureClient.context"; - /** - * Property name for outbound security provider name. Set this with - * {@link javax.ws.rs.client.Invocation.Builder#property(String, Object)}, - * obtained - * through {@link javax.ws.rs.client.WebTarget#request()} - * - * @deprecated use {@code ClientSecurity} constants instead - */ - public static final String PROPERTY_PROVIDER = "io.helidon.security.jersey.SecureClient.explicitProvider"; - - /** - * Create a new security feature. Security context must be provided through for the security context. - * This is a constructor to be used for clients that are not invoked within Jersey server - * context. - */ - public ClientSecurityFeature() { - } - - @Override - public boolean configure(FeatureContext context) { - RuntimeType runtimeType = context.getConfiguration().getRuntimeType(); - - //register client - if (runtimeType == RuntimeType.CLIENT) { - context.register(new ClientSecurityFilter()); - } else { - throw new IllegalStateException( - "ClientSecurityFeature is only available for client side Jersey. For servers, please use SecurityFeature"); - } - - return true; - } -} diff --git a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFilter.java b/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFilter.java deleted file mode 100644 index 5eff1327ac7..00000000000 --- a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/ClientSecurityFilter.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.helidon.security.integration.jersey; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.ws.rs.ConstrainedTo; -import javax.ws.rs.RuntimeType; -import javax.ws.rs.client.ClientRequestContext; -import javax.ws.rs.client.ClientRequestFilter; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.Provider; - -import io.helidon.common.context.Contexts; -import io.helidon.security.EndpointConfig; -import io.helidon.security.OutboundSecurityClientBuilder; -import io.helidon.security.OutboundSecurityResponse; -import io.helidon.security.SecurityContext; -import io.helidon.security.SecurityEnvironment; -import io.helidon.security.SecurityResponse; -import io.helidon.security.integration.common.OutboundTracing; -import io.helidon.security.integration.common.SecurityTracing; - -/** - * JAX-RS client filter propagating current context principal. - *

- * Only works as part of integration with Security component. - * This class is public to allow unit testing from providers (without invoking an HTTP request) - * - * @deprecated This class should not be used directly anyway, yet if you needed it, it is available in - * the new {@code helidon-security-integration-jersey-client} module. - */ -@Provider -@ConstrainedTo(RuntimeType.CLIENT) -@Deprecated -public class ClientSecurityFilter implements ClientRequestFilter { - - private static final Logger LOGGER = Logger.getLogger(ClientSecurityFilter.class.getName()); - - /** - * Create an instance of this filter (used by Jersey or for unit tests, do not use explicitly in your production code). - */ - public ClientSecurityFilter() { - } - - @Override - public void filter(ClientRequestContext requestContext) { - try { - doFilter(requestContext); - } catch (Throwable e) { - //If I do not log the exception here, it would be silently consumed and a 500 response provided to caller - LOGGER.log(Level.WARNING, "Failed to process client filter.", e); - throw e; - } - } - - private void doFilter(ClientRequestContext requestContext) { - //Try to have a look for @AuthenticatedClient annotation on client (if constructed as such) and use explicit provider - // from there - - // first try to find the context on request configuration - findContext(requestContext) - .or(() -> Contexts.context().flatMap(ctx -> ctx.get(SecurityContext.class))) - .ifPresentOrElse(securityContext -> outboundSecurity(requestContext, securityContext), - () -> LOGGER.finest("Security not propagated, as security context is not available " - + "neither in context, nor as the property \"" - + ClientSecurityFeature.PROPERTY_CONTEXT + "\" on request")); - } - - private void outboundSecurity(ClientRequestContext requestContext, SecurityContext securityContext) { - OutboundTracing tracing = SecurityTracing.get().outboundTracing(); - - String explicitProvider = (String) requestContext.getProperty(ClientSecurityFeature.PROPERTY_PROVIDER); - - try { - SecurityEnvironment.Builder outboundEnv = securityContext.env().derive(); - outboundEnv.method(requestContext.getMethod()) - .path(requestContext.getUri().getPath()) - .targetUri(requestContext.getUri()) - .headers(requestContext.getStringHeaders()); - - EndpointConfig.Builder outboundEp = securityContext.endpointConfig().derive(); - - for (String name : requestContext.getConfiguration().getPropertyNames()) { - outboundEp.addAtribute(name, requestContext.getConfiguration().getProperty(name)); - } - - for (String name : requestContext.getPropertyNames()) { - outboundEp.addAtribute(name, requestContext.getProperty(name)); - } - - OutboundSecurityClientBuilder clientBuilder = securityContext.outboundClientBuilder() - .outboundEnvironment(outboundEnv) - .tracingSpan(tracing.findParent().orElse(null)) - .tracingSpan(tracing.findParentSpan().orElse(null)) - .outboundEndpointConfig(outboundEp) - .explicitProvider(explicitProvider); - - OutboundSecurityResponse providerResponse = clientBuilder.buildAndGet(); - SecurityResponse.SecurityStatus status = providerResponse.status(); - tracing.logStatus(status); - switch (status) { - case FAILURE: - case FAILURE_FINISH: - providerResponse.throwable() - .ifPresentOrElse(tracing::error, - () -> tracing.error(providerResponse.description().orElse("Failed"))); - - break; - case ABSTAIN: - case SUCCESS: - case SUCCESS_FINISH: - default: - break; - } - // TODO check response status - maybe entity was updated? - // see MIC-6785; - - Map> newHeaders = providerResponse.requestHeaders(); - - LOGGER.finest(() -> "Client filter header(s). SIZE: " + newHeaders.size()); - - MultivaluedMap hdrs = requestContext.getHeaders(); - for (Map.Entry> entry : newHeaders.entrySet()) { - LOGGER.finest(() -> " + Header: " + entry.getKey() + ": " + entry.getValue()); - - //replace existing - hdrs.remove(entry.getKey()); - for (String value : entry.getValue()) { - hdrs.add(entry.getKey(), value); - } - } - tracing.finish(); - } catch (Exception e) { - tracing.error(e); - throw e; - } - } - - private Optional findContext(ClientRequestContext requestContext) { - Object value = requestContext.getProperty(ClientSecurityFeature.PROPERTY_CONTEXT); - if (null == value) { - value = requestContext.getConfiguration().getProperty(ClientSecurityFeature.PROPERTY_CONTEXT); - } - return Optional.ofNullable((SecurityContext) value); - } -} diff --git a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecureClient.java b/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecureClient.java deleted file mode 100644 index f30ff147ad6..00000000000 --- a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecureClient.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.helidon.security.integration.jersey; - -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; - -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.server.ClientBinding; - -/** - * Annotation to inject clients that have security feature configured. - * Just send security context as request parameter using {@link ClientSecurityFeature#PROPERTY_CONTEXT} and - * security will be handled for outgoing request(s) on this client. - * - *

- * @SecureClient
- * @Uri("http://service-name:8787/base_path")
- * private WebTarget target;
- *
- * @GET
- * public Response getIt(@Context SecurityContext context) {
- *  return target.request()
- *      .property(SecureClient.PROPERTY_CONTEXT, context)
- *      .get();
- * }
- *
- *
- * 
- * - * @deprecated Use the new module {@code helidon-security-integration-jersey-client} that adds security support without coding - */ -@ClientBinding(configClass = SecureClient.SecureClientConfig.class, inheritServerProviders = false) -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.PARAMETER}) -@Deprecated -public @interface SecureClient { - /** - * Configuration class for client security. - */ - class SecureClientConfig extends ClientConfig { - @SuppressWarnings("checkstyle:RedundantModifier") // public modifier required by Jersey - public SecureClientConfig() { - this.register(new ClientSecurityFeature()); - } - } -} diff --git a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java index 101ea55ab88..2a7c60d590a 100644 --- a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java +++ b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java @@ -35,7 +35,6 @@ */ @Path("/test1") public class TestResource1 { - @SecureClient @Uri("http://localhost:9998/test2") private WebTarget target; @@ -44,7 +43,6 @@ public class TestResource1 { @Produces(MediaType.APPLICATION_JSON) public TransferObject getIt(@Context SecurityContext context) { TransferObject fromTest2 = target.request() - .property(ClientSecurityFeature.PROPERTY_CONTEXT, context) .get(TransferObject.class); // we expect this NOT to be a proxy From 1ef3dc93a2954651ebfba1eb838ad4afbedf046d Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 27 May 2020 13:51:59 +0200 Subject: [PATCH 5/6] Added tests to native-image for provider discovery. Signed-off-by: Tomas Langer --- .../nativeimage/mp1/AutoFilter.java | 37 +++++++++++++++++ .../mp1/JaxRsApplicationNoClasses.java | 27 ++++++++++++ .../integration/nativeimage/mp1/Mp1Main.java | 41 +++++++++++++++---- 3 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/AutoFilter.java create mode 100644 tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/JaxRsApplicationNoClasses.java diff --git a/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/AutoFilter.java b/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/AutoFilter.java new file mode 100644 index 00000000000..14d907bcbf4 --- /dev/null +++ b/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/AutoFilter.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.tests.integration.nativeimage.mp1; + +import java.util.concurrent.atomic.AtomicInteger; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.ext.Provider; + +@Provider +public class AutoFilter implements ContainerRequestFilter { + private static final AtomicInteger COUNT = new AtomicInteger(); + + @Override + public void filter(ContainerRequestContext requestContext) { + COUNT.incrementAndGet(); + } + + static int count() { + return COUNT.get(); + } +} diff --git a/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/JaxRsApplicationNoClasses.java b/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/JaxRsApplicationNoClasses.java new file mode 100644 index 00000000000..2b118a6afd2 --- /dev/null +++ b/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/JaxRsApplicationNoClasses.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.tests.integration.nativeimage.mp1; + +import javax.enterprise.context.ApplicationScoped; +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationScoped +@ApplicationPath("/noclass") +public class JaxRsApplicationNoClasses extends Application { + // classes should be picked-up automatically from all resource and provider classes on classpath +} diff --git a/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/Mp1Main.java b/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/Mp1Main.java index 564baf59c89..bc5925dc273 100644 --- a/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/Mp1Main.java +++ b/tests/integration/native-image/mp-1/src/main/java/io/helidon/tests/integration/nativeimage/mp1/Mp1Main.java @@ -21,7 +21,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Instant; -import java.util.ArrayList; import java.util.Base64; import java.util.HashMap; import java.util.LinkedList; @@ -53,8 +52,6 @@ import io.opentracing.Tracer; import io.opentracing.util.GlobalTracer; -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.ConfigProvider; import org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException; import static io.helidon.common.http.Http.Status.FORBIDDEN_403; @@ -111,11 +108,11 @@ public static void main(final String[] args) { long time = System.currentTimeMillis() - now; System.out.println("Tests finished in " + time + " millis"); - Config config = ConfigProvider.getConfig(); - List names = new ArrayList<>(); - config.getPropertyNames() - .forEach(names::add); - names.sort(String::compareTo); + // Config config = ConfigProvider.getConfig(); + // List names = new ArrayList<>(); + // config.getPropertyNames() + // .forEach(names::add); + // names.sort(String::compareTo); // System.out.println("All configuration options:"); // names.forEach(it -> { @@ -243,10 +240,38 @@ private static void testBean(int port, String jwtToken) { // Static content validateStaticContent(collector, target); + // Make sure resource and provider classes are discovered + validateNoClassApp(collector, target); + collector.collect() .checkValid(); } + private static void validateNoClassApp(Errors.Collector collector, WebTarget target) { + String path = "/noclass"; + String expected = "Hello World "; + + Response response = target.path(path) + .request() + .get(); + + if (response.getStatus() == OK_200.code()) { + String entity = response.readEntity(String.class); + if (!expected.equals(entity)) { + collector.fatal("Endpoint " + path + "should return \"" + expected + "\", but returned \"" + entity + "\""); + } + } else { + collector.fatal("Endpoint " + path + " should be handled by JaxRsResource.java. Status received: " + + response.getStatus()); + } + + int count = AutoFilter.count(); + + if (count == 0) { + collector.fatal("Filter should have been added to JaxRsApplicationNoClass automatically"); + } + } + private static void validateStaticContent(Errors.Collector collector, WebTarget target) { String path = "/static/resource.txt"; String expected = "classpath-resource-text"; From 3b04314d979b7fd7a343670086d72444623ce83f Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 27 May 2020 14:03:17 +0200 Subject: [PATCH 6/6] Copyright fix. Signed-off-by: Tomas Langer --- .../io/helidon/security/integration/jersey/TestResource1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java index 2a7c60d590a..30d3f11cb78 100644 --- a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java +++ b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/TestResource1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.