[java-oidc-common] branch main updated: Add grant type setting for token profile.

Scott Cantor cantor.2 at osu.edu
Mon Feb 14 16:53:11 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor 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=fd4928d55d2e786a26b13a14a43fb7c0cc9f6a25

The following commit(s) were added to refs/heads/main by this push:
     new fd4928d  Add grant type setting for token profile.
fd4928d is described below

commit fd4928d55d2e786a26b13a14a43fb7c0cc9f6a25
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Feb 14 11:53:08 2022 -0500

    Add grant type setting for token profile.
---
 .../profile/config/OIDCTokenConfiguration.java     | 65 ++++++++++++++++++++++
 .../config/navigate/GrantTypesLookupFunction.java  | 63 +++++++++++++++++++++
 2 files changed, 128 insertions(+)

diff --git a/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/OIDCTokenConfiguration.java b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/OIDCTokenConfiguration.java
index 99bf239..829a306 100644
--- a/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/OIDCTokenConfiguration.java
+++ b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/OIDCTokenConfiguration.java
@@ -17,9 +17,25 @@
 
 package net.shibboleth.oidc.profile.config;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.function.Function;
+
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+
+import com.nimbusds.oauth2.sdk.GrantType;
 
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.logic.FunctionSupport;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /**
  * OIDC-aware OAuth 2 token endpoint profile configuration.
@@ -29,11 +45,16 @@ public class OIDCTokenConfiguration extends AbstractOIDCSSOConfiguration {
     /** ID for this profile configuration. */
     @Nonnull @NotEmpty public static final String PROFILE_ID = "http://shibboleth.net/ns/profiles/oidc/token";
 
+    /** Enabled grant types. */
+    @Nonnull private Function<ProfileRequestContext,Set<String>> grantTypesLookupStrategy;
+
     /**
      * Constructor.
      */
     public OIDCTokenConfiguration() {
         this(PROFILE_ID);
+        
+        grantTypesLookupStrategy = FunctionSupport.constant(Set.of(GrantType.AUTHORIZATION_CODE.toString()));
     }
 
     /**
@@ -45,4 +66,48 @@ public class OIDCTokenConfiguration extends AbstractOIDCSSOConfiguration {
         super(profileId);
     }
 
+
+    /**
+     * Get the enabled grant types.
+     * 
+     * @param profileRequestContext profile request context
+     * 
+     * @return enabled grant types
+     */
+    @Nonnull @NonnullElements @NotLive @Unmodifiable public Set<String> getGrantTypes(
+            @Nullable final ProfileRequestContext profileRequestContext) {
+        
+        final Collection<String> types = grantTypesLookupStrategy.apply(profileRequestContext);
+        if (types != null) {
+            return Set.copyOf(types);
+        }
+        return Collections.emptySet();
+    }
+
+    /**
+     * Set the enabled grant types
+     * 
+     * @param types types to enable
+     */
+    public void setGrantTypes(@Nonnull @NonnullElements final Collection<String> types) {
+        Constraint.isNotNull(types, "Collection of types cannot be null");
+
+        if (types != null) {
+            grantTypesLookupStrategy =
+                    FunctionSupport.constant(Set.copyOf(StringSupport.normalizeStringCollection(types)));
+        } else {
+            grantTypesLookupStrategy = FunctionSupport.constant(null);
+        }
+    }
+
+    /**
+     * Set a lookup strategy for the enabled grant types.
+     *
+     * @param strategy  lookup strategy
+     */
+    public void setGrantTypesLookupStrategy(
+            @Nonnull final Function<ProfileRequestContext,Set<String>> strategy) {
+        grantTypesLookupStrategy = Constraint.isNotNull(strategy, "Lookup strategy cannot be null");
+    }
+    
 }
\ No newline at end of file
diff --git a/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/GrantTypesLookupFunction.java b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/GrantTypesLookupFunction.java
new file mode 100644
index 0000000..786633d
--- /dev/null
+++ b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/GrantTypesLookupFunction.java
@@ -0,0 +1,63 @@
+/*
+ * 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.Set;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nullable;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+
+import com.nimbusds.oauth2.sdk.GrantType;
+
+import net.shibboleth.idp.profile.config.ProfileConfiguration;
+import net.shibboleth.idp.profile.context.RelyingPartyContext;
+import net.shibboleth.idp.profile.context.navigate.AbstractRelyingPartyLookupFunction;
+import net.shibboleth.oidc.profile.config.OIDCTokenConfiguration;
+
+/**
+ * A function that obtains
+ * {@link OIDCTokenConfiguration#getGrantTypes(ProfileRequestContext)}
+ * if such a profile is available from a {@link RelyingPartyContext} obtained via a lookup function,
+ * by default a child of the {@link ProfileRequestContext}. That result is then transformed into a list
+ * of {@link GrantType}s.
+ * 
+ * <p>If a specific setting is unavailable, a null value is returned.</p>
+ */
+public class GrantTypesLookupFunction extends AbstractRelyingPartyLookupFunction<Set<GrantType>> {
+
+    /** {@inheritDoc} */
+    @Nullable public Set<GrantType> apply(@Nullable final ProfileRequestContext input) {
+        final RelyingPartyContext rpc = getRelyingPartyContextLookupStrategy().apply(input);
+        if (rpc != null) {
+            final ProfileConfiguration pc = rpc.getProfileConfig();
+            if (pc instanceof OIDCTokenConfiguration) {
+                final Set<String> types = ((OIDCTokenConfiguration)pc).getGrantTypes(input);
+                if (types != null) {
+                    return types.stream()
+                            .map(GrantType::new)
+                            .collect(Collectors.toUnmodifiableSet());
+                }
+            }
+        }
+        
+        return null;
+    }
+
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list