Skip to content

Commit

Permalink
Nima and Reactive implementation of OIDC support separated (#6055)
Browse files Browse the repository at this point in the history
Nima and Reactive implementation of OIDC support separated

Signed-off-by: David Kral <[email protected]>
  • Loading branch information
Verdent authored Feb 3, 2023
1 parent ee3f258 commit 0f95600
Show file tree
Hide file tree
Showing 22 changed files with 472 additions and 74 deletions.
6 changes: 3 additions & 3 deletions archetypes/helidon/src/main/archetype/common/security.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates.
Copyright (c) 2022, 2023 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.
Expand Down Expand Up @@ -38,7 +38,7 @@
<list key="dependencies" if="${flavor} == 'se'">
<map>
<value key="groupId">io.helidon.security.providers</value>
<value key="artifactId">helidon-security-providers-oidc</value>
<value key="artifactId">helidon-security-providers-oidc-reactive</value>
</map>
</list>
<list key="dependencies" if="${flavor} == 'mp'">
Expand All @@ -51,7 +51,7 @@
<value>io.helidon.common.context.Contexts</value>
<value>io.helidon.security.Security</value>
<value>io.helidon.security.integration.webserver.WebSecurity</value>
<value>io.helidon.security.providers.oidc.OidcSupport</value>
<value>io.helidon.security.providers.oidc.reactive.OidcSupport</value>
</list>
<list key="Main-createRouting" if="${flavor} == 'se'">
<value><![CDATA[ Security security = Security.create(config.get("security"));]]></value>
Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@
<artifactId>helidon-security-providers-oidc</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc-reactive</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</dependency>
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc</artifactId>
<artifactId>helidon-security-providers-oidc-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.security.abac</groupId>
Expand Down
6 changes: 3 additions & 3 deletions docs/se/guides/security-oidc.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2020, 2022 Oracle and/or its affiliates.
Copyright (c) 2020, 2023 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.
Expand Down Expand Up @@ -241,7 +241,7 @@ Update the pom.xml file and add the following Helidon dependency to the `<depend
----
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc</artifactId>
<artifactId>helidon-security-providers-oidc-reactive</artifactId>
</dependency>
----
Expand Down Expand Up @@ -313,7 +313,7 @@ The `Main.createRouting` method gather all configuration properties.
----
import io.helidon.security.Security;
import io.helidon.security.integration.webserver.WebSecurity;
import io.helidon.security.providers.oidc.OidcSupport;
import io.helidon.security.providers.oidc.reactive.OidcSupport;
Security security = Security.create(config.get("security")); // <1>
Expand Down
4 changes: 2 additions & 2 deletions docs/se/security/providers.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2018, 2022 Oracle and/or its affiliates.
Copyright (c) 2018, 2023 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.
Expand Down Expand Up @@ -64,7 +64,7 @@ Open ID Connect security provider.
----
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc</artifactId>
<artifactId>helidon-security-providers-oidc-reactive</artifactId>
</dependency>
----
Expand Down
2 changes: 1 addition & 1 deletion examples/config/metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Example:
```xml
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc</artifactId>
<artifactId>helidon-security-providers-oidc-reactive</artifactId>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions examples/security/idcs-login/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018, 2022 Oracle and/or its affiliates.
Copyright (c) 2018, 2023 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.
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<!-- Open ID Connect security provider -->
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc</artifactId>
<artifactId>helidon-security-providers-oidc-reactive</artifactId>
</dependency>
<dependency>
<!-- IDCS Role Mapping security provider -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
* Copyright (c) 2018, 2023 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.
Expand Down Expand Up @@ -31,8 +31,8 @@
import io.helidon.security.integration.webserver.WebSecurity;
import io.helidon.security.providers.idcs.mapper.IdcsRoleMapperProvider;
import io.helidon.security.providers.oidc.OidcProvider;
import io.helidon.security.providers.oidc.OidcSupport;
import io.helidon.security.providers.oidc.common.OidcConfig;
import io.helidon.security.providers.oidc.reactive.OidcSupport;

import static io.helidon.config.ConfigSources.classpath;
import static io.helidon.config.ConfigSources.file;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
* Copyright (c) 2018, 2023 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.
Expand Down Expand Up @@ -28,7 +28,7 @@
import io.helidon.security.SecurityContext;
import io.helidon.security.Subject;
import io.helidon.security.integration.webserver.WebSecurity;
import io.helidon.security.providers.oidc.OidcSupport;
import io.helidon.security.providers.oidc.reactive.OidcSupport;

import static io.helidon.config.ConfigSources.classpath;
import static io.helidon.config.ConfigSources.file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.helidon.config.Config;
import io.helidon.microprofile.cdi.RuntimeStart;
import io.helidon.microprofile.server.ServerCdiExtension;
import io.helidon.security.providers.oidc.OidcService;
import io.helidon.security.providers.oidc.OidcFeature;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.Initialized;
Expand All @@ -45,7 +45,7 @@ private void registerOidcSupport(@Observes @Initialized(ApplicationScoped.class)
// only configure if security is enabled
ServerCdiExtension server = bm.getExtension(ServerCdiExtension.class);

server.serverRoutingBuilder().register(OidcService.create(config));
server.serverRoutingBuilder().addFeature(OidcFeature.create(config));
}
}
}
109 changes: 109 additions & 0 deletions security/providers/oidc-reactive/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>helidon-security-providers-project</artifactId>
<groupId>io.helidon.security.providers</groupId>
<version>4.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>helidon-security-providers-oidc-reactive</artifactId>
<name>Helidon Security Providers OIDC Reactive</name>

<description>
OIDC (Open ID Connect) security provider for reactive server
</description>

<dependencies>
<dependency>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver-cors</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-oidc</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.security.integration</groupId>
<artifactId>helidon-security-integration-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webserver</groupId>
<artifactId>helidon-reactive-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webserver</groupId>
<artifactId>helidon-reactive-webserver-cors</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webclient</groupId>
<artifactId>helidon-reactive-webclient</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.common.features</groupId>
<artifactId>helidon-common-features-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-metadata</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.helidon.common.features</groupId>
<artifactId>helidon-common-features-processor</artifactId>
<version>${helidon.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.helidon.security.providers.oidc;
package io.helidon.security.providers.oidc.reactive;

import java.lang.System.Logger.Level;
import java.net.URI;
Expand Down Expand Up @@ -53,6 +53,7 @@
import io.helidon.reactive.webserver.cors.CorsSupport;
import io.helidon.security.Security;
import io.helidon.security.integration.webserver.WebSecurity;
import io.helidon.security.providers.oidc.OidcProviderService;
import io.helidon.security.providers.oidc.common.OidcConfig;
import io.helidon.security.providers.oidc.common.OidcCookieHandler;
import io.helidon.security.providers.oidc.common.Tenant;
Expand Down Expand Up @@ -192,7 +193,7 @@ public static OidcSupport create(Config config) {
/**
* Load OIDC support for webserver from {@link OidcConfig} instance.
* When programmatically configuring your environment, this is the best approach, to share configuration
* between this class and {@link OidcProvider}.
* between this class and {@link io.helidon.security.providers.oidc.OidcProvider}.
*
* @param oidcConfig configuration of OIDC integration
* @return OIDC webserver integration based on the configuration
Expand Down Expand Up @@ -377,7 +378,10 @@ private void processCodeWithTenant(String code, ServerRequest req, ServerRespons
.uri(tenant.tokenEndpointUri())
.accept(HttpMediaType.APPLICATION_JSON);

OidcUtil.updateRequest(OidcConfig.RequestType.CODE_TO_TOKEN, tenantConfig, form);
if (tenantConfig.tokenEndpointAuthentication() == OidcConfig.ClientAuthentication.CLIENT_SECRET_POST) {
form.add("client_id", tenantConfig.clientId());
form.add("client_secret", tenantConfig.clientSecret());
}

OidcConfig.postJsonResponse(post,
form.build(),
Expand Down Expand Up @@ -553,7 +557,7 @@ private CorsSupport prepareCrossOriginSupport(String path, CrossOriginConfig cro
}

/**
* A fluent API builder for {@link io.helidon.security.providers.oidc.OidcSupport}.
* A fluent API builder for {@link OidcSupport}.
*/
public static class Builder implements io.helidon.common.Builder<Builder, OidcSupport> {

Expand Down Expand Up @@ -631,7 +635,7 @@ public Builder config(OidcConfig config) {
* Config located either at the configuration root, or at the provider node.
*
* @param config configuration to use
* @param providerName name of the security provider used for the {@link io.helidon.security.providers.oidc.OidcSupport}
* @param providerName name of the security provider used for the {@link OidcSupport}
* configuration
* @return updated builder instance
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2023 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.
*/

/**
* Integration with Open ID Connect providers for reactive server.
*/
package io.helidon.security.providers.oidc.reactive;
Loading

0 comments on commit 0f95600

Please sign in to comment.