[java-opensaml COMMIT] /trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/logic/DefaultLocalErr...

noreply at shibboleth.net noreply at shibboleth.net
Thu May 8 22:39:27 EDT 2014


Author: scantor
Date: Thu May  8 22:39:27 2014
New Revision: 3852

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3852&view=rev
Log:
Handle case where last event hasn't propagated to PreviousEventContext yet.

Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/logic/DefaultLocalErrorPredicate.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/logic/DefaultLocalErrorPredicate.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/logic/DefaultLocalErrorPredicate.java?rev=3852&r1=3851&r2=3852&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/logic/DefaultLocalErrorPredicate.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/logic/DefaultLocalErrorPredicate.java Thu May  8 22:39:27 2014
@@ -24,6 +24,7 @@
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.opensaml.profile.context.EventContext;
 import org.opensaml.profile.context.PreviousEventContext;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.profile.context.navigate.OutboundMessageContextLookup;
@@ -63,8 +64,8 @@
     /** Strategy function for access to {@link SAMLEndpointContext} to check. */
     @Nonnull private Function<ProfileRequestContext,SAMLEndpointContext> endpointContextLookupStrategy;
 
-    /** Strategy function for access to {@link PreviousEventContext} to check. */
-    @Nonnull private Function<ProfileRequestContext,PreviousEventContext> previousEventContextLookupStrategy;
+    /** Strategy function for access to {@link EventContext} to check. */
+    @Nonnull private Function<ProfileRequestContext,EventContext> eventContextLookupStrategy;
     
     /** Error events to handle locally, even if possible to do so with a response. */
     @Nonnull @NonnullElements private Set<String> localEvents;
@@ -81,7 +82,7 @@
                 Functions.compose(new ChildContextLookup<>(SAMLPeerEntityContext.class),
                         new OutboundMessageContextLookup()));
         
-        previousEventContextLookupStrategy = new ChildContextLookup<>(PreviousEventContext.class);
+        eventContextLookupStrategy = new CurrentOrPreviousEventLookupFunction();
         
         localEvents = Collections.emptySet();
     }
@@ -109,14 +110,12 @@
     }
 
     /**
-     * Set lookup strategy for {@link PreviousEventContext} to check.
+     * Set lookup strategy for {@link EventContext} to check.
      * 
      * @param strategy  lookup strategy
      */
-    public void setPreviousEventContextLookupStrategy(
-            @Nonnull final Function<ProfileRequestContext,PreviousEventContext> strategy) {
-        previousEventContextLookupStrategy = Constraint.isNotNull(strategy,
-                "PreviousEventContext lookup strategy cannot be null");
+    public void setEventContextLookupStrategy(@Nonnull final Function<ProfileRequestContext,EventContext> strategy) {
+        eventContextLookupStrategy = Constraint.isNotNull(strategy, "EventContext lookup strategy cannot be null");
     }
     
     /**
@@ -159,13 +158,13 @@
             return true;
         }
 
-        final PreviousEventContext previousEventCtx = previousEventContextLookupStrategy.apply(input);
-        if (previousEventCtx == null || previousEventCtx.getEvent() == null) {
+        final EventContext eventCtx = eventContextLookupStrategy.apply(input);
+        if (eventCtx == null || eventCtx.getEvent() == null) {
             log.debug("No event found, assuming error handled with response");
             return false;
         }
         
-        final String event = previousEventCtx.getEvent().toString();
+        final String event = eventCtx.getEvent().toString();
         if (localEvents.contains(event)) {
             log.debug("Error event {} will be handled locally", event);
             return true;
@@ -176,4 +175,23 @@
     }
 // Checkstyle: CyclomaticComplexity ON
     
+    /** Access either current or previous event from context tree. */
+    private class CurrentOrPreviousEventLookupFunction implements Function<ProfileRequestContext,EventContext> {
+
+        /** {@inheritDoc} */
+        @Override
+        @Nullable public EventContext apply(@Nullable final ProfileRequestContext input) {
+            if (input != null) {
+                final EventContext eventCtx = input.getSubcontext(EventContext.class);
+                if (eventCtx != null) {
+                    return eventCtx;
+                } else {
+                    return input.getSubcontext(PreviousEventContext.class);
+                }
+            } else {
+                return null;
+            }
+        }
+        
+    }
 }



More information about the commits mailing list