Refactor inbound message decoder selection into a distinct method (as in r2865 for...
authorputmanb <putmanb@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 8 Jul 2009 23:59:40 +0000 (23:59 +0000)
committerputmanb <putmanb@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 8 Jul 2009 23:59:40 +0000 (23:59 +0000)
1) consolidate logic and avoid duplication of code
2) check and avoid NPE's if decoder is null due to misconfiguration
3) allow subclasses to override decoder selection mechanism (re: uPortal work)

git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/branches/REL_2@2867 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/main/java/edu/internet2/middleware/shibboleth/idp/profile/AbstractSAMLProfileHandler.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml1/ArtifactResolution.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml1/AttributeQueryProfileHandler.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml1/ShibbolethSSOProfileHandler.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml2/ArtifactResolution.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml2/AttributeQueryProfileHandler.java
src/main/java/edu/internet2/middleware/shibboleth/idp/profile/saml2/SSOProfileHandler.java

index a7413f9..6e37287 100644 (file)
@@ -573,6 +573,35 @@ public abstract class AbstractSAMLProfileHandler extends
         }
         return encoder;
     }
+    
+    /**
+     * Get the inbound message decoder to use.
+     * 
+     * <p>The default implementation uses the binding URI from
+     * {@link #getInboundBinding()} to lookup the decoder from the supported message decoders
+     * defined in {@link #getMessageDecoders()}.
+     * </p>
+     * 
+     * <p>
+     * Subclasses may override to implement a different mechanism to determine the 
+     * decoder to use.
+     * </p>
+     * 
+     * @param requestContext current request context
+     * @return the message decoder to use
+     * @throws ProfileException if the decoder to use can not be resolved based on the request context
+     */
+    protected SAMLMessageDecoder getInboundMessageDecoder(BaseSAMLProfileRequestContext requestContext)
+            throws ProfileException {
+        SAMLMessageDecoder decoder = null;
+
+        decoder = getMessageDecoders().get(getInboundBinding());
+        if (decoder == null) {
+            log.error("No inbound message decoder configured for binding: {}", getInboundBinding());
+            throw new ProfileException("No inbound message decoder configured for binding: " + getInboundBinding());
+        }
+        return decoder;
+    }
 
     /**
      * Writes an audit log entry indicating the successful response to the attribute request.
index 8345cfc..470b10d 100644 (file)
@@ -134,7 +134,10 @@ public class ArtifactResolution extends AbstractSAML1ProfileHandler {
      */
     protected void decodeRequest(ArtifactResolutionRequestContext requestContext, HTTPInTransport inTransport,
             HTTPOutTransport outTransport) throws ProfileException {
-        log.debug("Decoding message with decoder binding '{}'", getInboundBinding());
+        if (log.isDebugEnabled()) {
+            log.debug("Decoding message with decoder binding '{}'",
+                    getInboundMessageDecoder(requestContext).getBindingURI());
+        }
 
         requestContext.setCommunicationProfileId(getProfileId());
 
@@ -150,7 +153,7 @@ public class ArtifactResolution extends AbstractSAML1ProfileHandler {
         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML11P_NS);
 
         try {
-            SAMLMessageDecoder decoder = getMessageDecoders().get(getInboundBinding());
+            SAMLMessageDecoder decoder = getInboundMessageDecoder(requestContext);
             requestContext.setMessageDecoder(decoder);
             decoder.decode(requestContext);
             log.debug("Decoded artifact resolution request from relying party '{}'", requestContext
index 6af8c1d..94cf704 100644 (file)
@@ -132,7 +132,10 @@ public class AttributeQueryProfileHandler extends AbstractSAML1ProfileHandler {
      */
     protected void decodeRequest(AttributeQueryContext requestContext, HTTPInTransport inTransport,
             HTTPOutTransport outTransport) throws ProfileException {
-        log.debug("Decoding message with decoder binding {}", getInboundBinding());
+        if (log.isDebugEnabled()) {
+            log.debug("Decoding message with decoder binding {}",
+                    getInboundMessageDecoder(requestContext).getBindingURI());
+        }
 
         requestContext.setCommunicationProfileId(getProfileId());
 
@@ -148,10 +151,7 @@ public class AttributeQueryProfileHandler extends AbstractSAML1ProfileHandler {
         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML11P_NS);
 
         try {
-            SAMLMessageDecoder decoder = getMessageDecoders().get(getInboundBinding());
-            if (decoder == null) {
-                throw new ProfileException("No message decoder configured for inbound binding " + getInboundBinding());
-            }
+            SAMLMessageDecoder decoder = getInboundMessageDecoder(requestContext);
             requestContext.setMessageDecoder(decoder);
             decoder.decode(requestContext);
             log.debug("Decoded request");
index d413966..e76e8db 100644 (file)
@@ -184,7 +184,10 @@ public class ShibbolethSSOProfileHandler extends AbstractSAML1ProfileHandler {
      */
     protected void decodeRequest(ShibbolethSSORequestContext requestContext, HTTPInTransport inTransport,
             HTTPOutTransport outTransport) throws ProfileException {
-        log.debug("Decoding message with decoder binding {}", getInboundBinding());
+        if (log.isDebugEnabled()) {
+            log.debug("Decoding message with decoder binding {}",
+                    getInboundMessageDecoder(requestContext).getBindingURI());
+        }
 
         HttpServletRequest httpRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
 
@@ -201,7 +204,7 @@ public class ShibbolethSSOProfileHandler extends AbstractSAML1ProfileHandler {
         requestContext.setOutboundMessageTransport(outTransport);
         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML11P_NS);
 
-        SAMLMessageDecoder decoder = getMessageDecoders().get(getInboundBinding());
+        SAMLMessageDecoder decoder = getInboundMessageDecoder(requestContext);
         requestContext.setMessageDecoder(decoder);
         try {
             decoder.decode(requestContext);
@@ -290,7 +293,7 @@ public class ShibbolethSSOProfileHandler extends AbstractSAML1ProfileHandler {
         ShibbolethSSORequestContext requestContext = new ShibbolethSSORequestContext();
         requestContext.setCommunicationProfileId(getProfileId());
 
-        requestContext.setMessageDecoder(getMessageDecoders().get(getInboundBinding()));
+        requestContext.setMessageDecoder(getInboundMessageDecoder(requestContext));
 
         requestContext.setLoginContext(loginContext);
         requestContext.setRelayState(loginContext.getSpTarget());
index 0c587bf..48f2b9b 100644 (file)
@@ -163,7 +163,10 @@ public class ArtifactResolution extends AbstractSAML2ProfileHandler {
      */
     protected void decodeRequest(ArtifactResolutionRequestContext requestContext, HTTPInTransport inTransport,
             HTTPOutTransport outTransport) throws ProfileException {
-        log.debug("Decoding message with decoder binding '{}'", getInboundBinding());
+        if (log.isDebugEnabled()) {
+            log.debug("Decoding message with decoder binding '{}'",
+                    getInboundMessageDecoder(requestContext).getBindingURI());
+        }
 
         requestContext.setCommunicationProfileId(getProfileId());
 
@@ -179,7 +182,7 @@ public class ArtifactResolution extends AbstractSAML2ProfileHandler {
         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML20P_NS);
 
         try {
-            SAMLMessageDecoder decoder = getMessageDecoders().get(getInboundBinding());
+            SAMLMessageDecoder decoder = getInboundMessageDecoder(requestContext);
             requestContext.setMessageDecoder(decoder);
             decoder.decode(requestContext);
             log.debug("Decoded request from relying party '{}'", requestContext.getInboundMessageIssuer());
index 6c2b300..30e6b8f 100644 (file)
@@ -139,7 +139,10 @@ public class AttributeQueryProfileHandler extends AbstractSAML2ProfileHandler {
      */
     protected void decodeRequest(AttributeQueryContext requestContext, HTTPInTransport inTransport,
             HTTPOutTransport outTransport) throws ProfileException {
-        log.debug("Decoding message with decoder binding '{}'", getInboundBinding());
+        if (log.isDebugEnabled()) {
+            log.debug("Decoding message with decoder binding '{}'",
+                    getInboundMessageDecoder(requestContext).getBindingURI());
+        }
 
         requestContext.setCommunicationProfileId(getProfileId());
 
@@ -155,7 +158,7 @@ public class AttributeQueryProfileHandler extends AbstractSAML2ProfileHandler {
         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML20P_NS);
 
         try {
-            SAMLMessageDecoder decoder = getMessageDecoders().get(getInboundBinding());
+            SAMLMessageDecoder decoder = getInboundMessageDecoder(requestContext);
             requestContext.setMessageDecoder(decoder);
             decoder.decode(requestContext);
             log.debug("Decoded request from relying party '{}'", requestContext.getInboundMessage());
index e194897..438f776 100644 (file)
@@ -278,7 +278,10 @@ public class SSOProfileHandler extends AbstractSAML2ProfileHandler {
      */
     protected void decodeRequest(SSORequestContext requestContext, HTTPInTransport inTransport,
             HTTPOutTransport outTransport) throws ProfileException {
-        log.debug("Decoding message with decoder binding '{}'", getInboundBinding());
+        if (log.isDebugEnabled()) {
+            log.debug("Decoding message with decoder binding '{}'",
+                    getInboundMessageDecoder(requestContext).getBindingURI());
+        }
 
         requestContext.setCommunicationProfileId(getProfileId());
 
@@ -294,7 +297,7 @@ public class SSOProfileHandler extends AbstractSAML2ProfileHandler {
         requestContext.setOutboundSAMLProtocol(SAMLConstants.SAML20P_NS);
 
         try {
-            SAMLMessageDecoder decoder = getMessageDecoders().get(getInboundBinding());
+            SAMLMessageDecoder decoder = getInboundMessageDecoder(requestContext);
             requestContext.setMessageDecoder(decoder);
             decoder.decode(requestContext);
             log.debug("Decoded request from relying party '{}'", requestContext.getInboundMessageIssuer());
@@ -333,7 +336,7 @@ public class SSOProfileHandler extends AbstractSAML2ProfileHandler {
         SSORequestContext requestContext = new SSORequestContext();
         requestContext.setCommunicationProfileId(getProfileId());
 
-        requestContext.setMessageDecoder(getMessageDecoders().get(getInboundBinding()));
+        requestContext.setMessageDecoder(getInboundMessageDecoder(requestContext));
 
         requestContext.setLoginContext(loginContext);