[java-oidc-common] branch main updated: Add metadata enc and alg lookup using claim names
Phil Smart
philip.smart at jisc.ac.uk
Fri Jan 6 12:50:16 UTC 2023
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=ef6699ab16e3af6392187685baaa6da1d28d608f
The following commit(s) were added to refs/heads/main by this push:
new ef6699a Add metadata enc and alg lookup using claim names
ef6699a is described below
commit ef6699ab16e3af6392187685baaa6da1d28d608f
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Fri Jan 6 12:50:13 2023 +0000
Add metadata enc and alg lookup using claim names
Making the lookup generic to any supported values type
Similar to the version for ClientInformation metadata
---
...ProviderMetadataStringValuesLookupFunction.java | 80 ++++++++++++++++++
...iderMetadataStringValuesLookupFunctionTest.java | 96 ++++++++++++++++++++++
2 files changed, 176 insertions(+)
diff --git a/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/ProviderMetadataStringValuesLookupFunction.java b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/ProviderMetadataStringValuesLookupFunction.java
new file mode 100644
index 0000000..569a436
--- /dev/null
+++ b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/ProviderMetadataStringValuesLookupFunction.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 net.shibboleth.oidc.profile.config.navigate;
+
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
+
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * Fetches the values for the configured key as {@link String}. May return null if the value is not found or the given
+ * {@link OIDCProviderMetadata} is null.
+ */
+public class ProviderMetadataStringValuesLookupFunction implements Function<OIDCProviderMetadata, List<String>> {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(ProviderMetadataStringValuesLookupFunction.class);
+
+ /** The key for which to fetch the value for. */
+ @Nonnull private final String keyName;
+
+ /**
+ * Constructor.
+ *
+ * @param name The key for which to fetch the value for.
+ */
+ public ProviderMetadataStringValuesLookupFunction(@ParameterName(name = "keyName") @Nonnull final String name) {
+ keyName = Constraint.isNotEmpty(name, "The key name cannot be empty");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable public List<String> apply(@Nullable final OIDCProviderMetadata metadata) {
+ if (metadata == null) {
+ log.trace("No provider metadata available");
+ return null;
+ }
+
+ final Object value = metadata.toJSONObject().get(keyName);
+ if (value == null) {
+ log.trace("No metadata value found for the key {}", keyName);
+ return null;
+ }
+ if (value instanceof String) {
+ return List.of(String.valueOf(value));
+ } else if (value instanceof List) {
+ final List<?> valueList = (List<?>)value;
+ return valueList.stream().map(Object::toString).collect(Collectors.toList());
+ }
+
+ log.trace("Metadata provided an unknown type for key '{}'", keyName);
+ return null;
+ }
+
+}
diff --git a/oidc-common-profile-api/src/test/java/net/shibboleth/oidc/profile/config/navigate/ProviderMetadataStringValuesLookupFunctionTest.java b/oidc-common-profile-api/src/test/java/net/shibboleth/oidc/profile/config/navigate/ProviderMetadataStringValuesLookupFunctionTest.java
new file mode 100644
index 0000000..97ab519
--- /dev/null
+++ b/oidc-common-profile-api/src/test/java/net/shibboleth/oidc/profile/config/navigate/ProviderMetadataStringValuesLookupFunctionTest.java
@@ -0,0 +1,96 @@
+
+package net.shibboleth.oidc.profile.config.navigate;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.jose.EncryptionMethod;
+import com.nimbusds.jose.JWEAlgorithm;
+import com.nimbusds.oauth2.sdk.id.Issuer;
+import com.nimbusds.openid.connect.sdk.SubjectType;
+import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
+
+/** Tests for {@link ProviderMetadataStringValuesLookupFunction}.*/
+public class ProviderMetadataStringValuesLookupFunctionTest {
+
+ /** Function to test.*/
+ private ProviderMetadataStringValuesLookupFunction function;
+
+ /** Provider Metadata to test with.*/
+ private OIDCProviderMetadata metadata;
+
+ @BeforeMethod
+ public void setup() throws URISyntaxException {
+ metadata = new OIDCProviderMetadata(new Issuer("https://op.example.org"),
+ List.of(SubjectType.PUBLIC), new URI("https://op.example.org/keyset"));
+ }
+
+ @Test
+ public void testLookupSuccess_MultipleEncs() throws URISyntaxException {
+ function =
+ new ProviderMetadataStringValuesLookupFunction("request_object_encryption_enc_values_supported");
+
+ metadata.setRequestObjectJWEEncs(List.of(EncryptionMethod.A128CBC_HS256, EncryptionMethod.A128GCM));
+
+ final List<String> encs = function.apply(metadata);
+
+ assertNotNull(encs);
+ assertEquals(encs.size(), 2);
+ }
+
+ @Test
+ public void testLookupSuccess_OneEnc() throws URISyntaxException {
+ function =
+ new ProviderMetadataStringValuesLookupFunction("request_object_encryption_enc_values_supported");
+
+ metadata.setRequestObjectJWEEncs(List.of(EncryptionMethod.A128CBC_HS256));
+
+ final List<String> encs = function.apply(metadata);
+
+ assertNotNull(encs);
+ assertEquals(encs.size(), 1);
+ }
+
+ @Test
+ public void testLookupSuccess_NoEncs() throws URISyntaxException {
+ function =
+ new ProviderMetadataStringValuesLookupFunction("request_object_encryption_enc_values_supported");
+
+ final List<String> encs = function.apply(metadata);
+ assertNull(encs);
+
+ }
+
+ @Test
+ public void testLookupSuccess_OneAlg() throws URISyntaxException {
+ function =
+ new ProviderMetadataStringValuesLookupFunction("request_object_encryption_alg_values_supported");
+
+ metadata.setRequestObjectJWEAlgs(List.of(JWEAlgorithm.A128GCMKW));
+
+ final List<String> encs = function.apply(metadata);
+
+ assertNotNull(encs);
+ assertEquals(encs.size(), 1);
+
+ }
+
+ @Test
+ public void testLookupSuccess_NoMetadata() throws URISyntaxException {
+ function =
+ new ProviderMetadataStringValuesLookupFunction("request_object_encryption_alg_values_supported");
+
+ final List<String> encs = function.apply(null);
+
+ assertNull(encs);
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list