diff --git a/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcFeature.java b/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcFeature.java index 1f9a6497f99..13054a8f154 100644 --- a/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcFeature.java +++ b/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcFeature.java @@ -656,19 +656,18 @@ public static class Builder implements io.helidon.common.Builder findMyKey(Config rootConfig, String providerName) { if (rootConfig.key().name().equals(providerName)) { - return rootConfig; + return Optional.of(rootConfig); } return rootConfig.get("security.providers") .asNodeList() - .get() + .orElseGet(List::of) .stream() .filter(it -> it.get(providerName).exists()) .findFirst() - .map(it -> it.get(providerName)) - .orElseThrow(() -> new SecurityException("No configuration found for provider named: " + providerName)); + .map(it -> it.get(providerName)); } @Override @@ -721,7 +720,10 @@ public Builder config(Config config, String providerName) { // if this is root config, we need to honor `security.enabled` config.get("security.enabled").asBoolean().ifPresent(this::enabled); - config(findMyKey(config, providerName)); + findMyKey(config, providerName) + .ifPresentOrElse(this::config, + () -> enabled(false)); + return this; } diff --git a/tests/integration/mp-gh-8493/pom.xml b/tests/integration/mp-gh-8493/pom.xml new file mode 100644 index 00000000000..e054c82a765 --- /dev/null +++ b/tests/integration/mp-gh-8493/pom.xml @@ -0,0 +1,68 @@ + + + + + io.helidon.tests.integration + helidon-tests-integration + 4.0.0-SNAPSHOT + + 4.0.0 + + helidon-tests-integration-mp-gh-8493 + Helidon Tests Integration MP GH 8493 + Reproducer for Github issue #8493 - Oidc should not fail if not configured + + + + io.helidon.microprofile.server + helidon-microprofile-server + + + io.helidon.microprofile + helidon-microprofile-oidc + + + io.helidon.microprofile + helidon-microprofile-security + + + io.helidon.logging + helidon-logging-jul + runtime + + + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest-all + test + + + io.helidon.microprofile.testing + helidon-microprofile-testing-junit5 + test + + + \ No newline at end of file diff --git a/tests/integration/mp-gh-8493/src/main/java/io/helidon/tests/integration/gh8493/Gh8493Resource.java b/tests/integration/mp-gh-8493/src/main/java/io/helidon/tests/integration/gh8493/Gh8493Resource.java new file mode 100644 index 00000000000..ab9b09e8747 --- /dev/null +++ b/tests/integration/mp-gh-8493/src/main/java/io/helidon/tests/integration/gh8493/Gh8493Resource.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 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.gh8493; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/greet") +public class Gh8493Resource { + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getDefaultMessage() { + return "Hello World!"; + } +} diff --git a/tests/integration/mp-gh-8493/src/main/resources/META-INF/beans.xml b/tests/integration/mp-gh-8493/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000000..52f89a20d18 --- /dev/null +++ b/tests/integration/mp-gh-8493/src/main/resources/META-INF/beans.xml @@ -0,0 +1,25 @@ + + + + diff --git a/tests/integration/mp-gh-8493/src/main/resources/logging.properties b/tests/integration/mp-gh-8493/src/main/resources/logging.properties new file mode 100644 index 00000000000..e50b6d44f81 --- /dev/null +++ b/tests/integration/mp-gh-8493/src/main/resources/logging.properties @@ -0,0 +1,23 @@ +# +# Copyright (c) 2024 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. +# + +handlers=io.helidon.logging.jul.HelidonConsoleHandler +java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n + +.level=WARNING + +io.helidon.level=INFO +io.helidon.security.level=FINEST \ No newline at end of file diff --git a/tests/integration/mp-gh-8493/src/test/java/io/helidon/tests/integration/gh8493/Gh8493Test.java b/tests/integration/mp-gh-8493/src/test/java/io/helidon/tests/integration/gh8493/Gh8493Test.java new file mode 100644 index 00000000000..ffdbd2e54c2 --- /dev/null +++ b/tests/integration/mp-gh-8493/src/test/java/io/helidon/tests/integration/gh8493/Gh8493Test.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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.gh8493; + +import io.helidon.microprofile.testing.junit5.HelidonTest; + +import jakarta.inject.Inject; +import jakarta.ws.rs.client.WebTarget; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@HelidonTest +public class Gh8493Test { + private final WebTarget target; + + @Inject + public Gh8493Test(WebTarget target) { + this.target = target; + } + + @Test + public void testServerStarted() { + String response = target + .path("/greet") + .request() + .get(String.class); + + assertThat(response, is("Hello World!")); + } +} diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index 8eaea624c8e..6b13443505f 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -56,6 +56,7 @@ mp-gh-8349 mp-gh-8478 mp-gh-8495 + mp-gh-8493 mp-graphql mp-security-client mp-ws-services