[java-plugin-shibd] branch main updated: Bug/config fixes for SAML flow testing.

Scott Cantor cantor.2 at osu.edu
Tue Oct 1 20:54:37 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=3868a91347637f4fafc5be081194a34f79d80a81

The following commit(s) were added to refs/heads/main by this push:
     new 3868a91  Bug/config fixes for SAML flow testing.
3868a91 is described below

commit 3868a91347637f4fafc5be081194a34f79d80a81
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Oct 1 16:54:34 2024 -0400

    Bug/config fixes for SAML flow testing.
---
 .../META-INF/net.shibboleth.idp/postconfig.xml     |  1 -
 .../sp/messaging/RemotedHttpServletRequest.java    | 30 +++++++++++++++-------
 .../sp/messaging/RemotedHttpServletResponse.java   |  7 +++--
 .../net/shibboleth/sp/impl/BasicApplication.java   |  7 +++--
 .../sp/profile/impl/SelectTokenConsumerFlow.java   | 22 +++++++++++++---
 5 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/sp-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/sp-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
index ae73bef..889aaee 100644
--- a/sp-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ b/sp-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
@@ -13,7 +13,6 @@
 
     default-init-method="initialize" default-destroy-method="destroy">
     
-
     <!-- Agent reseolver service. -->
 
     <bean id="shibboleth.AgentResolver" parent="shibboleth.ReloadableService" 
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
index 831c81f..d3e8a44 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
@@ -22,9 +22,9 @@ import java.io.StringReader;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CodingErrorAction;
+import java.nio.charset.StandardCharsets;
 import java.security.Principal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -89,21 +89,33 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
     /** Field holding request URI (path without query string). */
     @Nonnull @NotEmpty public static final String REQUEST_URI = "uri";
 
+    /** Field holding method. */
+    @Nonnull @NotEmpty public static final String METHOD = "method";
+
     /** Field holding query string. */
     @Nonnull @NotEmpty public static final String QUERY_STRING = "query";
 
+    /** Field holding body. */
+    @Nonnull @NotEmpty public static final String BODY = "body";
+
+    /** Field holding content type. */
+    @Nonnull @NotEmpty public static final String CONTENT_TYPE = "content_type";
+
+    /** Field holding content length. */
+    @Nonnull @NotEmpty public static final String CONTENT_LENGTH = "content_length";
+
     /** Empty byte array for empty bodies. */
     @Nonnull private static final byte[] EMPTY_BODY = new byte[0];
     
     /** UTF-8 decoder. */
     @Nonnull private static final CharsetDecoder UTF_8 =
-            Charset.forName("UTF-8").newDecoder()
+            StandardCharsets.UTF_8.newDecoder()
                 .onMalformedInput(CodingErrorAction.REPORT)
                 .onUnmappableCharacter(CodingErrorAction.REPORT);
 
     /** ISO single byte decoder. */
     @Nonnull private static final CharsetDecoder ISO_8859_1 =
-            Charset.forName("ISO-8859-1").newDecoder()
+            StandardCharsets.ISO_8859_1.newDecoder()
                 .onMalformedInput(CodingErrorAction.REPORT)
                 .onUnmappableCharacter(CodingErrorAction.REPORT);
 
@@ -158,7 +170,7 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
 
     /** {@inheritDoc} */
     public int getContentLength() {
-        final Integer i = obj.getmember("content_length").integer();
+        final Integer i = obj.getmember(CONTENT_LENGTH).integer();
         return i != null ? i : -1;
     }
 
@@ -169,15 +181,15 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
 
     /** {@inheritDoc} */
     public String getContentType() {
-        return obj.getmember("content_type").string();
+        return obj.getmember(CONTENT_TYPE).string();
     }
 
     /** {@inheritDoc} */
     public ServletInputStream getInputStream() throws IOException {
-        final String body = obj.getmember("body").string();
+        final String body = obj.getmember(BODY).string();
         if (body != null) {
             // The body is always assumed to be safely encoded for our use cases.
-            return new BodyInputStream(body.getBytes("UTF-8"));
+            return new BodyInputStream(body.getBytes(StandardCharsets.UTF_8));
         }
         return new BodyInputStream(EMPTY_BODY);
     }
@@ -274,7 +286,7 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
 
     /** {@inheritDoc} */
     public BufferedReader getReader() throws IOException {
-        return new BufferedReader(new StringReader(obj.getmember("body").string()));
+        return new BufferedReader(new StringReader(obj.getmember(BODY).string()));
     }
 
     /** {@inheritDoc} */
@@ -478,7 +490,7 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
 
     /** {@inheritDoc} */
     public String getMethod() {
-        return obj.getmember("method").string();
+        return obj.getmember(METHOD).string();
     }
 
     /** {@inheritDoc} */
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletResponse.java b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletResponse.java
index 05e8d02..2377db0 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletResponse.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletResponse.java
@@ -49,7 +49,10 @@ public class RemotedHttpServletResponse implements HttpServletResponse {
 
     /** Field holding name of {@link DDF} structure containing response. */
     @Nonnull @NotEmpty public static final String STRUCTURE_NAME = "http";
-    
+
+    /** Field holding redirect location. */
+    @Nonnull @NotEmpty public static final String REDIRECT = "redirect";
+
     /** Underlying object for remoted data. */
     @Nonnull private final DDF obj;
     
@@ -253,7 +256,7 @@ public class RemotedHttpServletResponse implements HttpServletResponse {
         }
 
         obj.getmember("response").remove();
-        obj.addmember("redirect").unsafe_string(location);
+        obj.addmember(REDIRECT).unsafe_string(location);
         committed = true;
         outputStream = null;
     }
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java
index 1f1ea2c..bd82552 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java
@@ -44,6 +44,7 @@ import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.logic.FunctionSupport;
+import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.service.ReloadableService;
 import net.shibboleth.sp.Application;
 import net.shibboleth.sp.StateTokenManager;
@@ -273,7 +274,8 @@ public class BasicApplication extends DefaultRelyingPartyConfigurationResolver i
         checkSetterPreconditions();
         
         if (initiators != null) {
-            sessionInitiatorLookupStrategy = FunctionSupport.constant(CollectionSupport.copyToList(initiators));
+            sessionInitiatorLookupStrategy = FunctionSupport.constant(
+                    CollectionSupport.copyToList(StringSupport.normalizeStringCollection(initiators)));
         } else {
             sessionInitiatorLookupStrategy = FunctionSupport.constant(CollectionSupport.emptyList());
         }
@@ -309,7 +311,8 @@ public class BasicApplication extends DefaultRelyingPartyConfigurationResolver i
         checkSetterPreconditions();
         
         if (consumers != null) {
-            tokenConsumerLookupStrategy = FunctionSupport.constant(CollectionSupport.copyToList(consumers));
+            tokenConsumerLookupStrategy = FunctionSupport.constant(
+                    CollectionSupport.copyToList(StringSupport.normalizeStringCollection(consumers)));
         } else {
             tokenConsumerLookupStrategy = FunctionSupport.constant(CollectionSupport.emptyList());
         }
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/SelectTokenConsumerFlow.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/SelectTokenConsumerFlow.java
index fe1928c..f48a293 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/SelectTokenConsumerFlow.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/SelectTokenConsumerFlow.java
@@ -70,8 +70,24 @@ public class SelectTokenConsumerFlow extends AbstractApplicationAction {
 
     /** {@inheritDoc} */
     @Override
-    protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+    protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+        if (!super.doPreExecute(profileRequestContext)) {
+            return false;
+        }
+        
+        if (ensureAgentRequestContext().getRemotedHttpServletRequest() == null) {
+            log.warn("No remoted HttpServletRequest available, malformed agent request?", getLogPrefix());
+            ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.NO_POTENTIAL_FLOW);
+            return false;
+        }
+        
+        return true;
+    }
 
+    /** {@inheritDoc} */
+    @Override
+    protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+        
         // We do the crazy stuff to accomodate flow activation conditions evaluating the servlet request.
         try {
             RemotedHttpServletRequestResponseContext.loadCurrent(ensureAgentRequestContext().getRemotedHttpServletRequest(),
@@ -80,11 +96,11 @@ public class SelectTokenConsumerFlow extends AbstractApplicationAction {
             final List<String> flows = ensureApplication().getTokenConsumers(profileRequestContext);
             for (final String flowId : flows) {
                 assert flowId != null;
-                final TokenConsumerFlowDescriptor flowDescriptor = availableFlows.get(flowId);
+                final TokenConsumerFlowDescriptor flowDescriptor = availableFlows.get("sp/consumer/" + flowId);
                 if (flowDescriptor != null) {
                     if (flowDescriptor.getActivationCondition().test(profileRequestContext)) {
                         log.debug("{} Token consumer flow {} handling request", getLogPrefix(), flowId);
-                        ActionSupport.buildEvent(profileRequestContext, flowId);
+                        ActionSupport.buildEvent(profileRequestContext, "sp/consumer/" + flowId);
                         return;
                     } else {
                         log.warn("{} Token consumer flow {} cannot handle request", getLogPrefix(), flowId);

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


More information about the commits mailing list