[java-identity-provider] branch main updated: Add support for legacy/fallback profile config selection.

Scott Cantor cantor.2 at osu.edu
Wed Dec 8 19:02:39 UTC 2021


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

scantor pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=8dd3737ac61124119124cde05335d09e6b86ba74

The following commit(s) were added to refs/heads/main by this push:
     new 8dd3737ac Add support for legacy/fallback profile config selection.
8dd3737ac is described below

commit 8dd3737ac61124119124cde05335d09e6b86ba74
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Dec 8 14:02:35 2021 -0500

    Add support for legacy/fallback profile config selection.
---
 .../impl/InitializeProfileRequestContext.java      | 20 +++++++++++++++
 .../profile/impl/SelectProfileConfiguration.java   | 13 ++++++++--
 .../impl/SelectProfileConfigurationTest.java       | 29 ++++++++++++++++++++--
 3 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java
index aaea98692..04a54a1c7 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java
@@ -53,6 +53,9 @@ public final class InitializeProfileRequestContext extends AbstractProfileAction
     /** The profile ID to initialize the context to. */
     @Nullable private String profileId;
 
+    /** Backup profile ID to populate as a legacy value. */
+    @Nullable private String legacyProfileId;
+    
     /** The logging ID to initialize the context to. */
     @Nullable private String loggingId;
     
@@ -72,6 +75,19 @@ public final class InitializeProfileRequestContext extends AbstractProfileAction
         
         profileId = StringSupport.trimOrNull(id);
     }
+    
+    /**
+     * Set the legacy/fallback profile ID to populate into the context.
+     * 
+     * @param id    legacy profile ID to populate into the context
+     * 
+     * @since 4.2.0
+     */
+    public void setLegacyProfileId(@Nullable final String id) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        
+        legacyProfileId = StringSupport.trimOrNull(id);
+    }
 
     /**
      * Set the logging ID to populate into the context.
@@ -123,6 +139,10 @@ public final class InitializeProfileRequestContext extends AbstractProfileAction
             prc.setProfileId(profileId);
         }
         
+        if (legacyProfileId != null) {
+            prc.setLegacyProfileId(legacyProfileId);
+        }
+        
         if (loggingId != null) {
             prc.setLoggingId(loggingId);
         }
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
index b6b4b7b76..2ac6dbfd1 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
@@ -112,8 +112,17 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
         final String profileId = profileRequestContext.getProfileId();
         final RelyingPartyConfiguration rpConfig = rpCtx.getConfiguration();
 
-        final ProfileConfiguration profileConfiguration =
-                rpConfig.getProfileConfiguration(profileRequestContext, profileId);
+        ProfileConfiguration profileConfiguration = rpConfig.getProfileConfiguration(profileRequestContext, profileId);
+        if (profileConfiguration == null && profileRequestContext.getLegacyProfileId() != null) {
+            // Try the legacy ID.
+            profileConfiguration = rpConfig.getProfileConfiguration(profileRequestContext,
+                    profileRequestContext.getLegacyProfileId());
+            if (profileConfiguration != null) {
+                // Reset the primary profile ID to the legacy value for subsequent use.
+                profileRequestContext.setProfileId(profileRequestContext.getLegacyProfileId());
+            }
+        }
+        
         if (profileConfiguration == null) {
             log.warn("{} Profile {} is not available for RP configuration {} (RPID {})",
                     new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
diff --git a/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java b/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java
index 6b3226585..9c9e293ed 100644
--- a/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java
+++ b/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java
@@ -26,7 +26,6 @@ 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.WebflowRequestContextProfileRequestContextLookup;
-import net.shibboleth.idp.profile.impl.SelectProfileConfiguration;
 import net.shibboleth.idp.profile.testing.ActionTestingSupport;
 import net.shibboleth.idp.profile.testing.MockProfileConfiguration;
 import net.shibboleth.idp.profile.testing.RequestContextBuilder;
@@ -47,6 +46,11 @@ public class SelectProfileConfigurationTest {
 
     private SelectProfileConfiguration action;
     
+    /**
+     * Test setup.
+     * 
+     * @throws ComponentInitializationException
+     */
     @BeforeMethod
     public void setUp() throws ComponentInitializationException {
         src = new RequestContextBuilder().buildRequestContext();
@@ -113,4 +117,25 @@ public class SelectProfileConfigurationTest {
         Assert.assertEquals(prc.getSubcontext(RelyingPartyContext.class).getProfileConfig().getId(), "mock");
     }
     
-}
+    /**
+     * Test that the action fails over to the legacy value if supplied.
+     * 
+     * @throws Exception if something goes wrong
+     */
+    @Test public void testFallback() throws Exception {
+        src = new RequestContextBuilder().setRelyingPartyProfileConfigurations(
+                Collections.<ProfileConfiguration>singleton(new MockProfileConfiguration("mock"))).buildRequestContext();
+        prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
+
+        prc.setProfileId("new");
+        prc.setLegacyProfileId("mock");
+
+        final Event event = action.execute(src);
+        ActionTestingSupport.assertProceedEvent(event);
+
+        Assert.assertNotNull(prc.getSubcontext(RelyingPartyContext.class).getProfileConfig());
+        Assert.assertEquals(prc.getSubcontext(RelyingPartyContext.class).getProfileConfig().getId(), "mock");
+        Assert.assertEquals(prc.getProfileId(), "mock");
+    }
+
+}
\ 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