View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.saml1.binding.decoding;
18  
19  import java.util.List;
20  
21  import org.opensaml.common.binding.SAMLMessageContext;
22  import org.opensaml.common.binding.artifact.SAMLArtifactMap;
23  import org.opensaml.common.xml.SAMLConstants;
24  import org.opensaml.ws.message.MessageContext;
25  import org.opensaml.ws.message.decoder.MessageDecodingException;
26  import org.opensaml.ws.transport.http.HTTPInTransport;
27  import org.opensaml.xml.parse.ParserPool;
28  import org.opensaml.xml.util.DatatypeHelper;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  /**
33   * SAML 1.X HTTP Artifact message decoder.
34   * 
35   * <strong>NOTE: This decoder is not yet implemented.</strong>
36   */
37  public class HTTPArtifactDecoder extends BaseSAML1MessageDecoder {
38  
39      /** Class logger. */
40      private final Logger log = LoggerFactory.getLogger(HTTPArtifactDecoder.class);
41  
42      /**
43       * Constructor.
44       * 
45       * @param map used to map artifacts to SAML
46       * @param pool parser pool used to deserialize messages
47       */
48      public HTTPArtifactDecoder(SAMLArtifactMap map, ParserPool pool) {
49          super(map, pool);
50      }
51  
52      /** {@inheritDoc} */
53      public String getBindingURI() {
54          return SAMLConstants.SAML1_ARTIFACT_BINDING_URI;
55      }
56  
57      /** {@inheritDoc} */
58      protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
59          if (!(messageContext instanceof SAMLMessageContext)) {
60              log.error("Invalid message context type, this decoder only support SAMLMessageContext");
61              throw new MessageDecodingException(
62                      "Invalid message context type, this decoder only support SAMLMessageContext");
63          }
64  
65          if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
66              log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
67              throw new MessageDecodingException(
68                      "Invalid inbound message transport type, this decoder only support HTTPInTransport");
69          }
70  
71          SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;
72          
73          decodeTarget(samlMsgCtx);
74          processArtifacts(samlMsgCtx);
75  
76          populateMessageContext(samlMsgCtx);
77      }
78  
79      /**
80       * Decodes the TARGET parameter and adds it to the message context.
81       * 
82       * @param samlMsgCtx current message context
83       * 
84       * @throws MessageDecodingException thrown if there is a problem decoding the TARGET parameter.
85       */
86      protected void decodeTarget(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
87          HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
88  
89          String target = DatatypeHelper.safeTrim(inTransport.getParameterValue("TARGET"));
90          if (target == null) {
91              log.error("URL TARGET parameter was missing or did not contain a value.");
92              throw new MessageDecodingException("URL TARGET parameter was missing or did not contain a value.");
93          }
94          samlMsgCtx.setRelayState(target);
95      }
96  
97      /**
98       * Process the incoming artifacts by decoding the artifacts, dereferencing them from the artifact source and 
99       * storing the resulting response (with assertions) in the message context.
100      * 
101      * @param samlMsgCtx current message context
102      * 
103      * @throws MessageDecodingException thrown if there is a problem decoding or dereferencing the artifacts
104      */
105     protected void processArtifacts(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
106         HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
107         List<String> encodedArtifacts = inTransport.getParameterValues("SAMLart");
108         if (encodedArtifacts == null || encodedArtifacts.size() == 0) {
109             log.error("URL SAMLart parameter was missing or did not contain a value.");
110             throw new MessageDecodingException("URL SAMLart parameter was missing or did not contain a value.");
111         }
112         
113         // TODO decode artifact(s); resolve issuer resolution endpoint; dereference using 
114         // Request/AssertionArtifact(s) over synchronous backchannel binding;
115         // store response as the inbound SAML message.
116     }
117 
118     /** {@inheritDoc} */
119     protected boolean isIntendedDestinationEndpointURIRequired(SAMLMessageContext samlMsgCtx) {
120         return false;
121     }
122     
123     /** {@inheritDoc} */
124     protected String getIntendedDestinationEndpointURI(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
125         // Not relevant in this binding/profile, there is neither SAML message
126         // nor binding parameter with this information
127         return null;
128     }
129 }