[java-idp-plugin-oidc-rp] branch main updated: Add ACR mappings from authn context

Phil Smart philip.smart at jisc.ac.uk
Fri Jun 17 12:52:04 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=5b7e5b3fba0d8829695e48a9a30879eb93e3e9f4

The following commit(s) were added to refs/heads/main by this push:
     new 5b7e5b3  Add ACR mappings from authn context
5b7e5b3 is described below

commit 5b7e5b3fba0d8829695e48a9a30879eb93e3e9f4
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Fri Jun 17 13:51:56 2022 +0100

    Add ACR mappings from authn context
---
 idp-oidc-rp-api/pom.xml                            |   5 +
 ...DCAuthenticationContextClassLookupFunction.java | 114 ++++++++++++++++++++
 .../authn/oidc/rp/context/OAuth2ClientContext.java |  17 +++
 ...thenticationContextClassLookupFunctionTest.java | 117 +++++++++++++++++++++
 .../oidc/rp/impl/AddOIDCAuthenticationRequest.java |  36 +++++++
 .../META-INF/net.shibboleth.idp/postconfig.xml     |   6 --
 .../idp/service/relying-party/postconfig.xml       |  18 ++++
 .../plugin/authn/oidc/rp/impl/OIDCRPFlowTest.java  |  49 +++++++++
 8 files changed, 356 insertions(+), 6 deletions(-)

diff --git a/idp-oidc-rp-api/pom.xml b/idp-oidc-rp-api/pom.xml
index dd176a6..b09663f 100644
--- a/idp-oidc-rp-api/pom.xml
+++ b/idp-oidc-rp-api/pom.xml
@@ -41,6 +41,11 @@
             <groupId>${idp.groupId}</groupId>
             <artifactId>idp-authn-api</artifactId>
             <scope>provided</scope>
+        </dependency>
+         <dependency>
+            <groupId>${idp.groupId}</groupId>
+            <artifactId>idp-saml-api</artifactId>
+            <scope>provided</scope>
         </dependency>
          <dependency>
             <groupId>net.shibboleth.oidc</groupId>
diff --git a/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction.java b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction.java
new file mode 100644
index 0000000..0c53f8c
--- /dev/null
+++ b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction.java
@@ -0,0 +1,114 @@
+/*
+ * 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.security.Principal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+
+import net.shibboleth.idp.authn.context.AuthenticationContext;
+import net.shibboleth.idp.authn.context.RequestedPrincipalContext;
+import net.shibboleth.oidc.authn.principal.AuthenticationContextClassReferencePrincipal;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+
+/**
+ * Implements a set of default logic for determining the custom principals to derive the
+ * OIDC ACRs from.
+ * 
+ * <p>This operates for the SAML to OIDC proxy use case. The values returned are empty unless the 
+ * parent context itself contains a child context carrying particular values. The values are either
+ * 'passed through' or mapped by the given principal mappings. All input values are either SAML ACRs or AMRs,
+ * and all output values are OIDC ACRs.</p>
+ */
+public class ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction 
+    implements Function<ProfileRequestContext,Collection<AuthenticationContextClassReferencePrincipal>> {
+    
+    /** Mappings to transform proxied Principals. */
+    @Nonnull @NonnullElements private Map<Principal,Collection<Principal>> principalMappings;
+    
+    /** Constructor. */
+    public ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction() {
+        principalMappings = Collections.emptyMap();
+    }
+    
+   /**
+    * Sets the mappings from input/proxied Principals to zero or more equivalent values to use.
+    * 
+    * <p>Any values not mapped will be assumed to be passed through.</p>
+    * 
+    * @param mappings {@link Principal} mappings
+    */
+   public void setMappings(@Nullable @NonnullElements final Map<Principal,Collection<Principal>> mappings) {
+       if (mappings == null || mappings.isEmpty()) {
+           principalMappings = Collections.emptyMap();
+           return;
+       }
+       
+       principalMappings = new HashMap<>(mappings.size());
+       mappings.forEach((k, v) -> principalMappings.put(k, List.copyOf(v)));
+   }
+
+    @Override
+    public Collection<AuthenticationContextClassReferencePrincipal> apply(final ProfileRequestContext input) {
+        
+        if (input != null && input.getParent() instanceof AuthenticationContext) {
+            
+            final RequestedPrincipalContext rpc = input.getParent().getSubcontext(RequestedPrincipalContext.class);
+            
+            if (rpc != null) {
+                
+                final List<AuthenticationContextClassReferencePrincipal> mappedAndPassedThroughPrincipals =
+                        new ArrayList<>();
+                
+                for (final Principal requestedPrincipal : rpc.getRequestedPrincipals()) {
+                    
+                    // If a mapping exists, use it
+                    if (principalMappings.containsKey(requestedPrincipal)) {
+                        final Collection<Principal> mappedPrinicipals = principalMappings.get(requestedPrincipal);
+                        for (final Principal mappedPrincipal : mappedPrinicipals) {
+                            if (mappedPrincipal instanceof AuthenticationContextClassReferencePrincipal) {
+                                mappedAndPassedThroughPrincipals.add(
+                                        (AuthenticationContextClassReferencePrincipal) mappedPrincipal);
+                            }                               
+                        }
+                    } else {
+                        // If no mapping exists, just convert to correct output type - which might not make sense
+                        // to the downstream OP.
+                        mappedAndPassedThroughPrincipals.add(
+                                new AuthenticationContextClassReferencePrincipal(requestedPrincipal.getName()));
+                    }
+                
+                }
+                return mappedAndPassedThroughPrincipals;
+            }
+        }        
+        return Collections.emptyList();
+    }
+    
+
+}
+
diff --git a/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/context/OAuth2ClientContext.java b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/context/OAuth2ClientContext.java
index a491bbf..ca8cdfd 100644
--- a/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/context/OAuth2ClientContext.java
+++ b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/context/OAuth2ClientContext.java
@@ -1,3 +1,20 @@
+/*
+ * 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.context;
 
 import java.net.URI;
diff --git a/idp-oidc-rp-api/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunctionTest.java b/idp-oidc-rp-api/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunctionTest.java
new file mode 100644
index 0000000..e4180a8
--- /dev/null
+++ b/idp-oidc-rp-api/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/config/navigate/ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunctionTest.java
@@ -0,0 +1,117 @@
+package net.shibboleth.idp.plugin.authn.oidc.rp.config.navigate;
+
+import static org.testng.Assert.assertTrue;
+
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.authn.context.AuthenticationContext;
+import net.shibboleth.idp.authn.context.RequestedPrincipalContext;
+import net.shibboleth.idp.saml.authn.principal.AuthnContextClassRefPrincipal;
+import net.shibboleth.oidc.authn.principal.AuthenticationContextClassReferencePrincipal;
+
+/** Tests for ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction.*/
+public class ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunctionTest {
+    
+    private ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction function;
+    
+    private ProfileRequestContext prc;
+    
+    private ProfileRequestContext nestedPrc;
+    
+    private AuthenticationContext ac;
+    
+    private RequestedPrincipalContext rpc;
+    
+    @BeforeMethod
+    public void setup() {
+        function = new ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction();
+        prc = new ProfileRequestContext();
+        ac = prc.getSubcontext(AuthenticationContext.class, true);
+        nestedPrc = ac.getSubcontext(ProfileRequestContext.class, true);
+        rpc = ac.getSubcontext(RequestedPrincipalContext.class, true);
+    }
+    
+    @Test
+    public void testSingleMappingSuccess() {
+        
+        
+        final List<Principal> requestedPrincipals = 
+                List.of(new AuthnContextClassRefPrincipal("http://example.org/ac/classes/mfa"));
+        rpc.setRequestedPrincipals(requestedPrincipals);
+        rpc.setOperator("exact");
+        
+        final Map<Principal,Collection<Principal>> mappings = new HashMap<>();
+        mappings.put(new AuthnContextClassRefPrincipal("http://example.org/ac/classes/mfa"), 
+                List.of(new AuthenticationContextClassReferencePrincipal("http://proxy.example.org/ac/classes/mfa")));
+        function.setMappings(mappings);
+        
+        final Collection<AuthenticationContextClassReferencePrincipal> mapped = function.apply(nestedPrc);
+        System.out.println(mapped);
+        assertTrue(mapped.contains(
+                        new AuthenticationContextClassReferencePrincipal("http://proxy.example.org/ac/classes/mfa")));
+        
+    }
+    
+    @Test
+    public void testMappedAndPassedThroughSuccess() {
+        
+        
+        // The second principal is passed-through as no mapping exists
+        final List<Principal> requestedPrincipals = 
+                List.of(new AuthnContextClassRefPrincipal("http://example.org/ac/classes/mfa"),
+                        new AuthnContextClassRefPrincipal("http://example.org/ac/classes/pass-through"));
+        rpc.setRequestedPrincipals(requestedPrincipals);
+        rpc.setOperator("exact");
+        
+        final Map<Principal,Collection<Principal>> mappings = new HashMap<>();
+        mappings.put(new AuthnContextClassRefPrincipal("http://example.org/ac/classes/mfa"), 
+                List.of(new AuthenticationContextClassReferencePrincipal("http://proxy.example.org/ac/classes/mfa")));
+        function.setMappings(mappings);
+        
+        final Collection<AuthenticationContextClassReferencePrincipal> mapped = function.apply(nestedPrc);
+        System.out.println(mapped);
+        assertTrue(mapped.contains(
+                        new AuthenticationContextClassReferencePrincipal("http://proxy.example.org/ac/classes/mfa")));
+        assertTrue(mapped.contains(
+                new AuthenticationContextClassReferencePrincipal("http://example.org/ac/classes/pass-through")));
+        
+    }
+    
+    @Test
+    public void testMultipleMappedAndPassedThroughSuccess() {
+        
+        
+        // The second principal is passed-through as no mapping exists
+        final List<Principal> requestedPrincipals = 
+                List.of(new AuthnContextClassRefPrincipal("http://example.org/ac/classes/mfa"),
+                        new AuthnContextClassRefPrincipal("http://example.org/ac/classes/pass-through"));
+        rpc.setRequestedPrincipals(requestedPrincipals);
+        rpc.setOperator("exact");
+        
+        final Map<Principal,Collection<Principal>> mappings = new HashMap<>();
+        mappings.put(new AuthnContextClassRefPrincipal("http://example.org/ac/classes/mfa"), 
+                List.of(new AuthenticationContextClassReferencePrincipal("http://proxy.example.org/ac/classes/mfa"),
+                        new AuthenticationContextClassReferencePrincipal(
+                                "http://proxy.two.example.org/ac/classes/mfa")));
+        function.setMappings(mappings);
+        
+        final Collection<AuthenticationContextClassReferencePrincipal> mapped = function.apply(nestedPrc);
+        System.out.println(mapped);
+        assertTrue(mapped.contains(
+                        new AuthenticationContextClassReferencePrincipal("http://proxy.example.org/ac/classes/mfa")));
+        assertTrue(mapped.contains(
+                new AuthenticationContextClassReferencePrincipal("http://proxy.two.example.org/ac/classes/mfa")));
+        assertTrue(mapped.contains(
+                new AuthenticationContextClassReferencePrincipal("http://example.org/ac/classes/pass-through")));
+        
+    }
+
+}
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AddOIDCAuthenticationRequest.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AddOIDCAuthenticationRequest.java
index 787f302..5864c03 100644
--- a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AddOIDCAuthenticationRequest.java
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AddOIDCAuthenticationRequest.java
@@ -17,8 +17,11 @@
 
 package net.shibboleth.idp.plugin.authn.oidc.rp.impl;
 
+import java.security.Principal;
+import java.util.List;
 import java.util.Set;
 import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -38,6 +41,7 @@ import com.nimbusds.oauth2.sdk.ParseException;
 import com.nimbusds.oauth2.sdk.id.ClientID;
 import com.nimbusds.openid.connect.sdk.Nonce;
 import com.nimbusds.openid.connect.sdk.Prompt;
+import com.nimbusds.openid.connect.sdk.claims.ACR;
 
 import net.shibboleth.idp.authn.AbstractAuthenticationAction;
 import net.shibboleth.idp.authn.AuthnEventIds;
@@ -47,6 +51,7 @@ import net.shibboleth.idp.plugin.authn.oidc.rp.context.OIDCPeerEntityContext;
 import net.shibboleth.idp.plugin.authn.oidc.rp.context.ResponseTypeAndModeContext;
 import net.shibboleth.idp.profile.IdPEventIds;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
+import net.shibboleth.oidc.authn.principal.AuthenticationContextClassReferencePrincipal;
 import net.shibboleth.oidc.metadata.context.OIDCProviderMetadataContext;
 import net.shibboleth.oidc.profile.config.OIDCAuthorizationConfiguration;
 import net.shibboleth.oidc.profile.core.OIDCAuthenticationRequest;
@@ -264,12 +269,43 @@ public class AddOIDCAuthenticationRequest extends AbstractAuthenticationAction {
             }
         }
         
+        final List<ACR> acrs = buildRequestedAuthnContext(profileRequestContext);  
+        if (acrs != null) {
+            log.debug("{} setting ACRs to '{}'", getLogPrefix(), acrs);
+            request.setAcrs(acrs);
+        }
+        
         log.debug("{} Built authorization request for endpoint '{}' for client '{}'",getLogPrefix(), 
                 request.getEndpointURI(), oauth2ClientContext.getClientId());
         profileRequestContext.getOutboundMessageContext().setMessage(request);
         
         
     }
+    
+    /**
+     * Build a list of {@link ACR}s if warranted. Converted from any default authentication method {@link Principal}s.
+     * 
+     * <p>By default for this proxy case, the authentication methods are 
+     * 
+     * @param profileRequestContext current profile request context
+     * 
+     * @return the list of ACRs. 
+     */
+    @Nullable private List<ACR> buildRequestedAuthnContext(
+            @Nullable final ProfileRequestContext profileRequestContext) {
+        
+        // RequestedAuthnContext also based on profile configuration.
+        final List<Principal> principals = profileConfiguration.getDefaultAuthenticationMethods(profileRequestContext);
+        if (principals.isEmpty()) {
+            return null;
+        }
+        
+        return principals.stream()
+            .filter(AuthenticationContextClassReferencePrincipal.class::isInstance)
+            .map(AuthenticationContextClassReferencePrincipal.class::cast)
+            .map(p -> new ACR(p.getName()))
+            .collect(Collectors.toUnmodifiableList());
+    }
 
 
 }
diff --git a/idp-oidc-rp-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/idp-oidc-rp-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
index 72d54eb..c8d8250 100644
--- a/idp-oidc-rp-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ b/idp-oidc-rp-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
@@ -95,12 +95,6 @@
         p:inactivityTimeout="%{idp.authn.oidc.rp.inactivityTimeout:%{idp.authn.defaultTimeout:PT30M}}"
         p:reuseCondition-ref="#{'%{idp.authn.oidc.rp.reuseCondition:shibboleth.Conditions.TRUE}'.trim()}"
         p:activationCondition-ref="#{'%{idp.authn.oidc.rp.activationCondition:shibboleth.Conditions.TRUE}'.trim()}">
-        <property name="supportedPrincipals">
-            <list>
-                <bean parent="shibboleth.SAML2AuthnContextClassRef" c:classRef="class-ref" />
-                <bean parent="shibboleth.SAML1AuthenticationMethod" c:method="auth-ref" />
-            </list>
-        </property>
         <property name="supportedPrincipalsByString">
             <bean parent="shibboleth.CommaDelimStringArray"
                 c:_0="#{'%{idp.authn.oidc.rp.supportedPrincipals:}'.trim()}" />
diff --git a/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml b/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml
index fa28105..dd554f4 100644
--- a/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml
+++ b/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml
@@ -39,7 +39,25 @@
         <property name="forceAuthnPredicate">
             <bean class="net.shibboleth.idp.saml.profile.config.logic.ProxyAwareForceAuthnPredicate" />
         </property>
+         <property name="defaultAuthenticationMethodsLookupStrategy">
+            <bean class="net.shibboleth.idp.plugin.authn.oidc.rp.config.navigate.ProxyAwareDefaultOIDCAuthenticationContextClassLookupFunction"
+                p:mappings="#{getObject('shibboleth.authn.oidc.rp.PrincipalProxyRequestMappings')}" />        
+        </property>
    </bean>
+   
+   <!-- TODO Move this out to its own file? -->
+    <util:map id="shibboleth.authn.oidc.rp.PrincipalProxyRequestMappings">        
+        <entry>
+            <key>
+                <bean parent="shibboleth.SAML2AuthnContextClassRef"
+                    c:classRef="http://example.org/ac/classes/mfa" />
+            </key>
+            <list>
+                <bean class="net.shibboleth.oidc.authn.principal.AuthenticationContextClassReferencePrincipal"
+                    c:classRef="https://proxy.example.org/context2" />
+            </list>
+        </entry>
+    </util:map>
 
 
     <!-- Security Configuration Defaults. These settings establish the default security configurations for signatures and 
diff --git a/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/OIDCRPFlowTest.java b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/OIDCRPFlowTest.java
index 13e6fa1..12a27f8 100644
--- a/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/OIDCRPFlowTest.java
+++ b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/OIDCRPFlowTest.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.plugin.authn.oidc.rp.impl;
 import java.net.InetAddress;
 import java.net.URI;
 import java.net.UnknownHostException;
+import java.security.Principal;
 import java.time.Duration;
 import java.util.HashMap;
 import java.util.List;
@@ -68,6 +69,7 @@ import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
 import net.shibboleth.ext.spring.config.IdentifiableBeanPostProcessor;
 import net.shibboleth.idp.authn.context.AuthenticationContext;
 import net.shibboleth.idp.authn.context.ExternalAuthenticationContext;
+import net.shibboleth.idp.authn.context.RequestedPrincipalContext;
 import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
 import net.shibboleth.idp.authn.impl.ExternalAuthenticationImpl;
 import net.shibboleth.idp.authn.principal.UsernamePrincipal;
@@ -78,6 +80,7 @@ import net.shibboleth.idp.plugin.authn.test.flow.AbstractAuthnXmlFlowExecutionTe
 import net.shibboleth.idp.plugin.authn.test.flow.mock.MockFlowBuilder;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.relyingparty.RelyingPartyConfiguration;
+import net.shibboleth.idp.saml.authn.principal.AuthnContextClassRefPrincipal;
 import net.shibboleth.oidc.metadata.context.OIDCProviderMetadataContext;
 import net.shibboleth.oidc.profile.config.OIDCAuthorizationConfiguration;
 import net.shibboleth.oidc.profile.config.OIDCSecurityConfiguration;
@@ -274,6 +277,11 @@ public class OIDCRPFlowTest extends AbstractAuthnXmlFlowExecutionTests {
                 genericBeanDefinition(org.opensaml.storage.impl.MemoryStorageService.class).getBeanDefinition());
         
         
+        addBeanDefinition(builderContext, "shibboleth.SAML2AuthnContextClassRef",BeanDefinitionBuilder.
+                genericBeanDefinition(net.shibboleth.idp.saml.authn.principal.AuthnContextClassRefPrincipal.class)
+                .setAbstract(true).getBeanDefinition());
+        
+        
         try {
             // Create a HttpClient which turns off hostname verification and trusts all certificates (for TESTS!)
             addBeanSingleton(builderContext, "shibboleth.InternalHttpClient", 
@@ -497,6 +505,47 @@ public class OIDCRPFlowTest extends AbstractAuthnXmlFlowExecutionTests {
         assertCurrentStateEquals("AuthRequest");
     }
     
+    @Test
+    public void testFlowToAuthorizationRedirect_WithACRs() throws Exception {
+        setFlowPath(FLOW);
+        setFlowModelResources(flowResources);
+        setSubflows(subflows);
+        
+        final Map<String,String> mockProperties = Map.of(
+                "idp.service.clientinfo.failFast","false",
+                "idp.entityID", "http://idp.example.com/",
+                "idp.authn.oidc.rp.proxyIssuer",OP_ISSUER_ID,
+                "idp.oidc.rp.redirecturl.allowedOrigins", RP_ALLOWED_ORIGINS);
+        
+        setMockProperties(mockProperties);
+        
+        final MockWebServer mockOPServer = createSimpleServer();
+        // First is metadata exchange
+        mockOPServer.enqueue(new MockResponse().setResponseCode(200)
+                .setHeader("content-type", "application/json")
+                .setBody(GOOD_PROVIDER_CONFIGURATION_INFO));
+       
+        mockOPServer.start(9918);
+        
+        final LocalAttributeMap<Object> inputMap = new LocalAttributeMap<Object>();
+        inputMap.put("calledAsSubflow", true);
+
+        final FlowExecution flowExecution = getFlowExecutionFactory().createFlowExecution(getFlowDefinition());  
+        final ProfileRequestContext prc = buildProfileRequestContext("authn/OIDCRelyingParty",false,true);
+        
+        final RequestedPrincipalContext rpc = new RequestedPrincipalContext();
+        final List<Principal> requestedPrincipals = 
+                List.of(new AuthnContextClassRefPrincipal("http://example.org/ac/classes/mfa"));
+        rpc.setRequestedPrincipals(requestedPrincipals);
+        rpc.setOperator("exact");
+        prc.getSubcontext(AuthenticationContext.class).addSubcontext(rpc);
+        
+        flowExecution.getConversationScope().put("opensamlProfileRequestContext", prc);
+        updateFlowExecution(flowExecution);
+        flowExecution.start(inputMap, externalContext);    
+        assertCurrentStateEquals("AuthRequest");
+    }
+    
     /**
      * Create a basic security configuration, which can be overriden per test if required.
      * 

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


More information about the commits mailing list