[java-opensaml COMMIT] in /trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml: saml1/profile/impl/AddStatusToRe...
noreply at shibboleth.net
noreply at shibboleth.net
Mon Apr 14 13:00:11 EDT 2014
Author: scantor
Date: Mon Apr 14 13:00:11 2014
New Revision: 3791
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3791&view=rev
Log:
Simple status code mapping function.
Modified:
trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/profile/impl/AddStatusToResponse.java
trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddStatusToResponse.java
Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/profile/impl/AddStatusToResponse.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/profile/impl/AddStatusToResponse.java?rev=3791&r1=3790&r2=3791&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/profile/impl/AddStatusToResponse.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml1/profile/impl/AddStatusToResponse.java Mon Apr 14 13:00:11 2014
@@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -29,6 +30,7 @@
import org.opensaml.profile.action.AbstractProfileAction;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ErrorEventContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.context.navigate.OutboundMessageContextLookup;
@@ -54,6 +56,7 @@
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
/**
* Action that sets {@link Status} content in a {@link Response} obtained from
@@ -289,4 +292,41 @@
status.setStatusMessage(sm);
}
+ /** A default method to map event IDs to SAML 1 StatusCode QNames based on {@link ErrorEventContext}. */
+ public static class StatusCodeMappingFunction implements Function<ProfileRequestContext,List<QName>> {
+
+ /** Code mappings. */
+ @Nonnull @NonnullElements private Map<String,List<QName>> codeMappings;
+
+ /**
+ * Constructor.
+ *
+ * @param mappings the status code mappings to use
+ */
+ public StatusCodeMappingFunction(@Nonnull @NonnullElements final Map<String,List<QName>> mappings) {
+ Constraint.isNotNull(mappings, "Status code mappings cannot be null");
+
+ codeMappings = Maps.newHashMapWithExpectedSize(mappings.size());
+ for (Map.Entry<String,List<QName>> entry : mappings.entrySet()) {
+ final String event = StringSupport.trimOrNull(entry.getKey());
+ if (event != null && entry.getValue() != null) {
+ codeMappings.put(event,
+ Lists.newArrayList(Collections2.filter(entry.getValue(), Predicates.notNull())));
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable public List<QName> apply(@Nullable final ProfileRequestContext input) {
+ if (input != null) {
+ final ErrorEventContext error = input.getSubcontext(ErrorEventContext.class);
+ if (error != null && error.getEvent() != null) {
+ return codeMappings.get(error.getEvent().toString());
+ }
+ }
+ return Collections.emptyList();
+ }
+ }
+
}
Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddStatusToResponse.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddStatusToResponse.java?rev=3791&r1=3790&r2=3791&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddStatusToResponse.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddStatusToResponse.java Mon Apr 14 13:00:11 2014
@@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -28,6 +29,7 @@
import org.opensaml.profile.action.AbstractProfileAction;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ErrorEventContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.context.navigate.OutboundMessageContextLookup;
@@ -53,6 +55,7 @@
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
/**
* Action that sets {@link Status} content in a {@link Response} obtained from
@@ -289,4 +292,41 @@
[... 42 lines stripped ...]
More information about the commits
mailing list