[java-identity-provider] branch main updated: Allow for profile ID to be supplied externally.

Scott Cantor cantor.2 at osu.edu
Thu Feb 10 17:03:36 UTC 2022


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=c2cbfeaaf845ee5887e70d05f70006f79ced7a29

The following commit(s) were added to refs/heads/main by this push:
     new c2cbfeaaf Allow for profile ID to be supplied externally.
c2cbfeaaf is described below

commit c2cbfeaaf845ee5887e70d05f70006f79ced7a29
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Feb 10 12:03:32 2022 -0500

    Allow for profile ID to be supplied externally.
---
 .../profile/impl/SelectProfileConfiguration.java   | 40 ++++++++++++++++++----
 1 file changed, 33 insertions(+), 7 deletions(-)

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 cc3d9f38d..9791a1653 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
@@ -28,8 +28,10 @@ import net.shibboleth.idp.profile.config.ConditionalProfileConfiguration;
 import net.shibboleth.idp.profile.config.ProfileConfiguration;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.relyingparty.RelyingPartyConfiguration;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 import org.opensaml.messaging.context.navigate.ChildContextLookup;
 import org.opensaml.profile.action.ActionSupport;
@@ -56,6 +58,9 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
      */
     @Nonnull private Function<ProfileRequestContext,RelyingPartyContext> relyingPartyContextLookupStrategy;
 
+    /** Profile ID to use if not derived from context tree. */
+    @Nullable @NotEmpty private String profileId;
+    
     /** The RelyingPartyContext to operate on. */
     @Nullable private RelyingPartyContext rpCtx;
     
@@ -83,6 +88,21 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
                 "RelyingPartyContext lookup strategy cannot be null");
     }
     
+    /**
+     * Set the profile identifier to use in selection.
+     * 
+     * <p>If not set, this defaults to using {@link ProfileRequestContext#getProfileId()}.</p>
+     * 
+     * @param id profile ID to use
+     * 
+     * @since 4.2.0
+     */
+    public void setProfileId(@Nullable @NotEmpty final String id) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        
+        profileId = StringSupport.trimOrNull(id);
+    }
+    
     /**
      * Set whether a missing profile configuration should result in an error event.
      * 
@@ -122,15 +142,20 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
         return true;
     }
     
+// Checkstyle: CyclomaticComplexity OFF
     /** {@inheritDoc} */
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
 
-        final String profileId = profileRequestContext.getProfileId();
+        String targetId = profileId;
+        if (targetId == null) {
+            targetId = profileRequestContext.getProfileId();
+        }
+        
         final RelyingPartyConfiguration rpConfig = rpCtx.getConfiguration();
 
-        ProfileConfiguration profileConfiguration = rpConfig.getProfileConfiguration(profileRequestContext, profileId);
-        if (profileConfiguration == null && profileRequestContext.getLegacyProfileId() != null) {
+        ProfileConfiguration profileConfiguration = rpConfig.getProfileConfiguration(profileRequestContext, targetId);
+        if (profileConfiguration == null && profileId == null && profileRequestContext.getLegacyProfileId() != null) {
             // Try the legacy ID.
             profileConfiguration = rpConfig.getProfileConfiguration(profileRequestContext,
                     profileRequestContext.getLegacyProfileId());
@@ -143,26 +168,27 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
         if (profileConfiguration == null) {
             if (failIfMissing) {
                 log.warn("{} Profile {} is not available for RP configuration {} (RPID {})",
-                        new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
                 ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
             } else {
                 log.debug("{} Profile {} is not available for RP configuration {} (RPID {})",
-                        new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
             }
         } else if (profileConfiguration instanceof ConditionalProfileConfiguration
                 && !((ConditionalProfileConfiguration) profileConfiguration).getActivationCondition().test(
                         profileRequestContext)) {
             if (failIfMissing) {
                 log.warn("{} Profile {} is not active for RP configuration {} (RPID {})",
-                        new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
                 ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
             } else {
                 log.debug("{} Profile {} is not active for RP configuration {} (RPID {})",
-                        new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
             }
         } else {
             rpCtx.setProfileConfig(profileConfiguration);
         }
     }
+// Checkstyle: CyclomaticComplexity ON
     
 }
\ 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