[java-plugin-shibd] branch main updated: Test cleanup, adjust final redirect handling in ACS base class.

Scott Cantor cantor.2 at osu.edu
Wed Sep 18 21:59:15 UTC 2024


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

scantor pushed a commit to branch main
in repository java-plugin-shibd.

View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-shibd.git;a=commit;h=baa2ba7196e20cf3a512771f16f311d2d69cbfe5

The following commit(s) were added to refs/heads/main by this push:
     new baa2ba7  Test cleanup, adjust final redirect handling in ACS base class.
baa2ba7 is described below

commit baa2ba7196e20cf3a512771f16f311d2d69cbfe5
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Sep 18 17:59:08 2024 -0400

    Test cleanup, adjust final redirect handling in ACS base class.
---
 .../AbstractTokenConsumerResponseAction.java       | 39 +++++++++++-----------
 .../shibboleth/sp/profile/ConsumerConstants.java   |  3 ++
 .../sp/profile/impl/BaseAgentRequestTest.java      |  3 +-
 .../sp/profile/impl/BaseAgplicationActionTest.java |  6 ++++
 4 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/profile/AbstractTokenConsumerResponseAction.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/AbstractTokenConsumerResponseAction.java
index 2358c17..be5ab05 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/profile/AbstractTokenConsumerResponseAction.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/AbstractTokenConsumerResponseAction.java
@@ -15,6 +15,7 @@
 package net.shibboleth.sp.profile;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.function.Function;
 
 import javax.annotation.Nonnull;
@@ -82,22 +83,6 @@ public abstract class AbstractTokenConsumerResponseAction extends AbstractApplic
         attributeContextLookupStrategy =
                 Constraint.isNotNull(strategy, "AttributeContext lookup strategy cannot be null");
     }
-    
-    /** {@inheritDoc} */
-    @Override
-    protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-        if (!super.doPreExecute(profileRequestContext)) {
-            return false;
-        }
-        
-        final DDF input = ensureAgentRequestContext().getInput();
-        if (input == null) {
-            log.debug("{} Input message was absent", getLogPrefix());
-            return true;
-        }
-        
-        return true;
-    }
 
     /** {@inheritDoc} */
     @Override
@@ -120,7 +105,7 @@ public abstract class AbstractTokenConsumerResponseAction extends AbstractApplic
         final AttributeContext attributeContext = attributeContextLookupStrategy.apply(profileRequestContext);
         if (attributeContext != null) {
             log.debug("{} Serializing attributes for agent", getLogPrefix());
-            final DDF attrlist = output.getmember(ConsumerConstants.SESSION_ATTRIBUTES).list();
+            final DDF attrlist = output.addmember(ConsumerConstants.SESSION_ATTRIBUTES).list();
             attributeContext.getIdPAttributes().forEach((id, attr) -> {
                 final DDF obj = new DDF(id).list();
                 for (final IdPAttributeValue value : attr.getValues()) {
@@ -135,6 +120,8 @@ public abstract class AbstractTokenConsumerResponseAction extends AbstractApplic
                         obj.add(new DDF(null).longinteger(datetime.getValue().getEpochSecond()));
                     } else if (value instanceof ByteAttributeValue bytes) {
                         obj.add(new DDF(null).unsafe_string(bytes.getValue()));
+                    } else {
+                        log.warn("{} Unsupported attribute value type: {}", getLogPrefix(), value.getClass().getName());
                     }
                 }
                 attrlist.add(obj);
@@ -147,14 +134,28 @@ public abstract class AbstractTokenConsumerResponseAction extends AbstractApplic
         if (sessionData != null) {
             output.addmember(ConsumerConstants.SESSION_OPAQUE).string(sessionData);
         }
+
+        // Issue redirect to proper resource URL. Either recovered from protocol state,
+        // or falling back to an input parameter from the agent. Final backtop is a relative
+        // redirect to the site root.
         
         final RemotedHttpServletResponse remotedResponse = agentRequestContext.getRemotedHttpServletResponse();
         assert remotedResponse != null;
 
-        final byte[] resource = recoverState(profileRequestContext, agentRequestContext);
-        if (resource != null) {
+        byte[] resource = recoverState(profileRequestContext, agentRequestContext);
+        if (resource != null && resource.length > 0) {
             remotedResponse.sendRedirect(resource);
+            return;
+        }
+        
+        final DDF in = agentRequestContext.getInput();
+        if (in != null) {
+            resource = in.getmember(ConsumerConstants.BASE_URL).unsafe_string();
+        }
+        if (resource == null || resource.length == 0) {
+            resource = "/".getBytes(StandardCharsets.UTF_8);
         }
+        remotedResponse.sendRedirect(resource);
     }
     
     /**
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java
index f3aa694..aecc24f 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java
@@ -23,6 +23,9 @@ import net.shibboleth.shared.annotation.constraint.NotEmpty;
  */
 public final class ConsumerConstants {
 
+    /** Base URL input parameter name. */
+    @Nonnull @NotEmpty public static final String BASE_URL = "base_url";
+
     /** Opaque session data member. */
     @Nonnull @NotEmpty public static final String SESSION_OPAQUE = "session.opaque";
 
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgentRequestTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgentRequestTest.java
index f0b6bc7..25b92ec 100644
--- a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgentRequestTest.java
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgentRequestTest.java
@@ -14,6 +14,7 @@
 
 package net.shibboleth.sp.profile.impl;
 
+import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.springframework.webflow.execution.RequestContext;
 
@@ -26,7 +27,7 @@ import net.shibboleth.sp.impl.BasicAgent;
 /**
  * Base class for unit tests that rely on set up of an agent request.
  */
-public abstract class BaseAgentRequestTest {
+public abstract class BaseAgentRequestTest extends OpenSAMLInitBaseTestCase {
 
     protected RequestContext src;
     protected ProfileRequestContext prc;
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgplicationActionTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgplicationActionTest.java
index d8cfdb7..25aeeb8 100644
--- a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgplicationActionTest.java
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/impl/BaseAgplicationActionTest.java
@@ -17,6 +17,7 @@ package net.shibboleth.sp.profile.impl;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.testing.MockReloadableService;
 import net.shibboleth.sp.impl.BasicApplication;
+import net.shibboleth.sp.impl.PassthroughStateTokenManager;
 
 /**
  * Base class for unit tests that rely on set up of an agent request with an application.
@@ -41,6 +42,11 @@ public abstract class BaseAgplicationActionTest extends BaseAgentRequestTest {
         application.setAttributeFilter(new MockReloadableService<>(null));
         application.setAttributeTranscoderRegistry(new MockReloadableService<>(null));
         
+        final PassthroughStateTokenManager manager = new PassthroughStateTokenManager();
+        manager.setId("test");
+        manager.initialize();
+        application.setStateTokenManager(manager);
+        
         //application.initialize();
         
         arc.setApplication(application);

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


More information about the commits mailing list