-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Oracle Cloud Identity Domain OpenID Connect integration (#1873)
- Loading branch information
Showing
16 changed files
with
417 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...io/micronaut/security/oauth2/endpoint/endsession/request/AuthorizationServerResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* 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 | ||
* | ||
* https://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.micronaut.security.oauth2.endpoint.endsession.request; | ||
|
||
import io.micronaut.context.annotation.DefaultImplementation; | ||
import io.micronaut.core.annotation.NonNull; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* API to resolve an {@link AuthorizationServer} based on the issuer url. | ||
* @author Sergio del Amo | ||
* @since 4.12.0 | ||
*/ | ||
@FunctionalInterface | ||
@DefaultImplementation(DefaultAuthorizationServerResolver.class) | ||
public interface AuthorizationServerResolver { | ||
/** | ||
* | ||
* @param issuer OpenID Authorization Server issuer | ||
* @return Based on substrings of the issuer url, it returns an {@link AuthorizationServer}. | ||
*/ | ||
@NonNull | ||
Optional<AuthorizationServer> resolve(@NonNull String issuer); | ||
} |
68 changes: 68 additions & 0 deletions
68
...onaut/security/oauth2/endpoint/endsession/request/DefaultAuthorizationServerResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* 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 | ||
* | ||
* https://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.micronaut.security.oauth2.endpoint.endsession.request; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.core.annotation.Nullable; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* {@link io.micronaut.context.annotation.DefaultImplementation} of {@link AuthorizationServerResolver}. | ||
* Based on substrings of the issuer url it returns an {@link AuthorizationServer}. | ||
* @author Sergio del Amo | ||
* @since 4.12.0 | ||
*/ | ||
@Internal | ||
@Singleton | ||
final class DefaultAuthorizationServerResolver implements AuthorizationServerResolver { | ||
private static final String ISSUER_PART_OKTA = "okta"; | ||
private static final String ISSUER_PART_ORACLE_CLOUD = "oraclecloud"; | ||
private static final String ISSUER_PART_COGNITO = "cognito"; | ||
private static final String ISSUER_PART_AUTH0 = "auth0"; | ||
private static final String ISSUER_PART_KEYCLOAK = "/auth/realms/"; | ||
private static final Map<String, AuthorizationServer> cache = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
@NonNull | ||
public Optional<AuthorizationServer> resolve(@NonNull String issuer) { | ||
return Optional.ofNullable(cache.computeIfAbsent(issuer, DefaultAuthorizationServerResolver::infer)); | ||
} | ||
|
||
@Nullable | ||
static AuthorizationServer infer (@NonNull String issuer) { | ||
if (issuer.contains(ISSUER_PART_ORACLE_CLOUD)) { | ||
return AuthorizationServer.ORACLE_CLOUD; | ||
} | ||
if (issuer.contains(ISSUER_PART_OKTA)) { | ||
return AuthorizationServer.OKTA; | ||
} | ||
if (issuer.contains(ISSUER_PART_COGNITO)) { | ||
return AuthorizationServer.COGNITO; | ||
} | ||
if (issuer.contains(ISSUER_PART_AUTH0)) { | ||
return AuthorizationServer.AUTH0; | ||
} | ||
if (issuer.contains(ISSUER_PART_KEYCLOAK)) { | ||
return AuthorizationServer.KEYCLOAK; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...th2/src/test/groovy/io/micronaut/security/oauth2/client/IdTokenClaimsValidatorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
package io.micronaut.security.oauth2.client | ||
|
||
import io.micronaut.security.oauth2.configuration.OauthClientConfiguration | ||
import io.micronaut.security.oauth2.configuration.OauthClientConfigurationProperties | ||
import io.micronaut.security.testutils.ApplicationContextSpecification | ||
import spock.lang.Unroll | ||
|
||
class IdTokenClaimsValidatorSpec extends ApplicationContextSpecification { | ||
|
||
void "by default no bean of type IdTokenClaimsValidator exists"() { | ||
expect: | ||
!applicationContext.containsBean(IdTokenClaimsValidator) | ||
} | ||
|
||
@Unroll | ||
void "issuer IdTokenClaimsValidator"(String configIss, String iss) { | ||
given: | ||
def oauthClientConfiguration = new OauthClientConfigurationProperties("oci"); | ||
def openId = new OauthClientConfigurationProperties.OpenIdClientConfigurationProperties("oci"); | ||
openId.setIssuer(new URL(configIss)) | ||
oauthClientConfiguration.setOpenid(openId) | ||
List<OauthClientConfiguration> l = List.of(oauthClientConfiguration) | ||
IdTokenClaimsValidator claimsValidator = new IdTokenClaimsValidator(List.of(l)) | ||
|
||
when: | ||
Optional<Boolean> validation = claimsValidator.matchesIssuer(openId, iss) | ||
|
||
then: | ||
validation.isPresent() | ||
validation.get() == true | ||
|
||
where: | ||
configIss | iss | ||
"https://idcs-227ebfb7094445cc5a3fbc0faa1fe87b.identity.oraclecloud.com" | "https://identity.oraclecloud.com/" | ||
"https://idcs-227ebfb7094445cc5a3fbc0faa1fe87b.identity.oraclecloud.com" | "https://identity.oraclecloud.com" | ||
"https://identity.oraclecloud.com" | "https://identity.oraclecloud.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...icronaut/security/oauth2/endpoint/endsession/request/AuthorizationServerResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.micronaut.security.oauth2.endpoint.endsession.request; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import java.util.stream.Stream; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
@MicronautTest(startApplication = false) | ||
class AuthorizationServerResolverTest { | ||
|
||
@Inject | ||
AuthorizationServerResolver resolver; | ||
|
||
static Stream<Arguments> paramsProvider() { | ||
return Stream.of( | ||
arguments("http://localhost:8180/auth/realms/master", AuthorizationServer.KEYCLOAK), | ||
arguments("https://dev-XXXXX.oktapreview.com/oauth2/default", AuthorizationServer.OKTA), | ||
arguments("https://cognito-idp.us-east-1.amazonaws.com/12345}/", AuthorizationServer.COGNITO), | ||
arguments("https://micronautguides.eu.auth0.com", AuthorizationServer.AUTH0), | ||
arguments("https://identity.oraclecloud.com/", AuthorizationServer.ORACLE_CLOUD)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("paramsProvider") | ||
void inferAuthorizationServer(String issuer, AuthorizationServer authorizationServer) { | ||
assertTrue(resolver.resolve(issuer).isPresent()); | ||
assertEquals(authorizationServer, resolver.resolve(issuer).get()); | ||
} | ||
|
||
@Test | ||
void inferAuthorizationServerBasedOnTheIssuerUrlMayReturnEmptyOptional() { | ||
assertFalse(resolver.resolve("http://localhost:8180/auth").isPresent()); | ||
} | ||
} |
Oops, something went wrong.