[java-idp-plugin-oidc-rp] branch main updated: Add support for max_age parameter

Phil Smart philip.smart at jisc.ac.uk
Mon Dec 19 16:04:21 UTC 2022


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

philsmart pushed a commit to branch main
in repository java-idp-plugin-oidc-rp.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-oidc-rp.git;a=commit;h=853a814cc9c241bea893704f990010718cc20b30

The following commit(s) were added to refs/heads/main by this push:
     new 853a814  Add support for max_age parameter
853a814 is described below

commit 853a814cc9c241bea893704f990010718cc20b30
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Mon Dec 19 16:04:18 2022 +0000

    Add support for max_age parameter
---
 .../navigate/MaxAgeFromProfileLookupFunction.java  | 70 ++++++++++++++++++++++
 .../oidc/rp/messaging/impl/AddMaxAgeHandler.java   | 31 ++++++++++
 .../oidc/rp/messaging/impl/SignJWTHandler.java     |  2 +-
 .../oidc-relying-party-authn-beans.xml             | 10 +++-
 4 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/MaxAgeFromProfileLookupFunction.java b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/MaxAgeFromProfileLookupFunction.java
new file mode 100644
index 0000000..caaf2c7
--- /dev/null
+++ b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/MaxAgeFromProfileLookupFunction.java
@@ -0,0 +1,70 @@
+/*
+ * 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.idp.plugin.authn.oidc.rp.config.navigate;
+
+import java.time.Duration;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+
+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.OIDCAuthorizationConfiguration;
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/** Locate the maximum authentication age from the profile request context. Returning a default value if not found.*/
+ at ThreadSafe
+public class MaxAgeFromProfileLookupFunction extends AbstractRelyingPartyLookupFunction<Duration> {
+    
+    /** Default max authentication age if none can be found on the profile context.*/
+    private final Duration maxAgeDefault;
+    
+    /**
+     * Constructor.
+     *
+     * @param defaultAge the default value to use for maximum authentication age
+     */
+    public MaxAgeFromProfileLookupFunction(@ParameterName(name = "maxAgeDefault") @Nonnull final Duration defaultAge) {
+        maxAgeDefault = Constraint.isNotNull(defaultAge, "Max Age default can not be null");
+    }
+
+    @Override
+    @Nonnull
+    public Duration apply(@Nullable final ProfileRequestContext input) {
+        
+        final RelyingPartyContext rpc = getRelyingPartyContextLookupStrategy().apply(input);
+        if (rpc != null) {
+            final ProfileConfiguration pc = rpc.getProfileConfig();
+            if (pc instanceof OIDCAuthorizationConfiguration){
+                   final Duration maxAge = ((OIDCAuthorizationConfiguration)pc).getMaxAuthenticationAge(input);
+                   if (maxAge == null) {
+                       return maxAgeDefault;
+                   } else {
+                       return maxAge;
+                   }
+            }
+        }
+        return maxAgeDefault;
+    }
+
+}
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddMaxAgeHandler.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddMaxAgeHandler.java
new file mode 100644
index 0000000..75650fd
--- /dev/null
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddMaxAgeHandler.java
@@ -0,0 +1,31 @@
+
+package net.shibboleth.idp.plugin.authn.oidc.rp.messaging.impl;
+
+import java.time.Duration;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.messaging.handler.MessageHandlerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AddMaxAgeHandler extends AbstractOIDCAuthenticationRequestActionMessageHandler {
+
+    /** Logger. */
+    @Nonnull private final Logger log = LoggerFactory.getLogger(AddMaxAgeHandler.class);
+
+    @Override protected void doInvoke(@Nonnull final MessageContext messageContext) 
+            throws MessageHandlerException {   
+       
+        final Duration maxAge = 
+                getProfileConfiguration().getMaxAuthenticationAge(lookupProfileRequestContext(messageContext));
+        
+        if (maxAge != null) {
+            log.trace("{} Added max_age parameter '{}'", getLogPrefix(), maxAge);
+            getAuthenticationRequest().setMaxAge(maxAge);
+        }
+  
+    }
+
+}
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/SignJWTHandler.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/SignJWTHandler.java
index 6e97bd7..147fdd1 100644
--- a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/SignJWTHandler.java
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/SignJWTHandler.java
@@ -88,7 +88,7 @@ public class SignJWTHandler extends AbstractMessageHandler {
     /** "typ" header to insert while signing. */
     @Nullable @NotEmpty private String typeHeader;
     
-    /** A friendly name to log as the subject of encryption parameter resolution.*/
+    /** A friendly name to log as the subject of signing.*/
     @Nonnull private String logName;
     
     /** Constructor.*/
diff --git a/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml b/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml
index d9a9942..226e007 100644
--- a/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml
+++ b/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml
@@ -116,6 +116,8 @@
                     <list>
                         <bean id="AddResponseTypeAndMode" scope="prototype"
                             class="net.shibboleth.idp.plugin.authn.oidc.rp.messaging.impl.AddResponseTypeAndModeHandler"/> 
+                        <bean id="AddMaxAge" scope="prototype"
+                            class="net.shibboleth.idp.plugin.authn.oidc.rp.messaging.impl.AddMaxAgeHandler"/> 
                         <bean id="AddScopes" scope="prototype"
                             class="net.shibboleth.idp.plugin.authn.oidc.rp.messaging.impl.AddScopesHandler"/>
                         <bean id="AddNonce" scope="prototype"
@@ -217,7 +219,6 @@
                 </constructor-arg>
             </bean>
         </property>
-
     </bean>
 
 
@@ -321,7 +322,6 @@
         p:httpServletRequest-ref="shibboleth.authn.oidc.rp.internal.HttpServletRequest" />
 
 
-
     <!-- After authentication response -->
     <bean id="ValidateExternalAuthenticationContext" scope="prototype"
         class="net.shibboleth.idp.plugin.authn.oidc.rp.impl.ValidateExternalAuthenticationContext" />
@@ -647,10 +647,14 @@
     
     <bean id="AuthenticationTimeClaimValidator" 
                 class="net.shibboleth.oidc.security.jwt.claims.impl.AuthenticationTimeClaimsValidator"
-                p:authnLifetime="%{idp.authn.oidc.rp.client.idtoken.jwt.verifier.authLifetime:PT60S}"
+                p:authnLifetimeLookupStrategy-ref="MaxAgeFromProfileLookupFunction"
                 p:clockSkew="%{idp.authn.oidc.rp.client.idtoken.jwt.verifier.clockSkew:PT60S}"
                 p:activationCondition="#{getObject('shibboleth.authn.oidc.rp.jwt.AuthTimeActivationCondition') ?: 
                                 getObject('shibboleth.authn.oidc.rp.jwt.DefaultAuthTimeActivationCondition')}"/>
+                                
+    <bean id="MaxAgeFromProfileLookupFunction" 
+        class="net.shibboleth.idp.plugin.authn.oidc.rp.config.navigate.MaxAgeFromProfileLookupFunction"
+        c:maxAgeDefault="%{idp.authn.oidc.rp.client.idtoken.jwt.verifier.authnLifetime:PT60S}"/>
 
     <bean id="shibboleth.authn.oidc.rp.jwt.DefaultAuthTimeActivationCondition" 
             class="net.shibboleth.oidc.security.jwt.claims.impl.AuthTimeRequestedActivationCondition"

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


More information about the commits mailing list