View Javadoc

1   /*
2    * Copyright [2006] [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.saml2.binding.decoding;
18  
19  
20  import org.opensaml.common.binding.SAMLMessageContext;
21  import org.opensaml.common.xml.SAMLConstants;
22  import org.opensaml.ws.message.MessageContext;
23  import org.opensaml.ws.message.decoder.MessageDecodingException;
24  import org.opensaml.ws.transport.http.HTTPInTransport;
25  import org.opensaml.xml.parse.ParserPool;
26  import org.opensaml.xml.util.DatatypeHelper;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  /** 
31   * SAML 2 Artifact Binding decoder, support both HTTP GET and POST.
32   * 
33   * <strong>NOTE: This decoder is not yet implemented.</strong>
34   * */
35  public class HTTPArtifactDecoder extends BaseSAML2MessageDecoder {
36  
37      /** Class logger. */
38      private final Logger log = LoggerFactory.getLogger(HTTPArtifactDecoder.class);
39      
40      /**
41       * Constructor.
42       * 
43       * @param pool parser pool used to deserialize messages
44       */
45      public HTTPArtifactDecoder(ParserPool pool) {
46          super(pool);
47      }
48  
49      /** {@inheritDoc} */
50      public String getBindingURI() {
51          return SAMLConstants.SAML2_ARTIFACT_BINDING_URI;
52      }
53  
54      /** {@inheritDoc} */
55      protected boolean isIntendedDestinationEndpointURIRequired(SAMLMessageContext samlMsgCtx) {
56          return false;
57      }
58      
59      /** {@inheritDoc} */
60      protected String getIntendedDestinationEndpointURI(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
61          // Not relevant in this binding/profile, there is neither SAML message
62          // nor binding parameter with this information
63          return null;
64      }
65  
66      /** {@inheritDoc} */
67      protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
68          if (!(messageContext instanceof SAMLMessageContext)) {
69              log.error("Invalid message context type, this decoder only support SAMLMessageContext");
70              throw new MessageDecodingException(
71                      "Invalid message context type, this decoder only support SAMLMessageContext");
72          }
73  
74          if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
75              log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
76              throw new MessageDecodingException(
77                      "Invalid inbound message transport type, this decoder only support HTTPInTransport");
78          }
79  
80          SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;
81  
82          HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
83          String relayState = DatatypeHelper.safeTrim(inTransport.getParameterValue("RelayState"));
84          samlMsgCtx.setRelayState(relayState);
85          
86          processArtifact(samlMsgCtx);
87  
88          populateMessageContext(samlMsgCtx);
89      }
90      
91      /**
92       * Process the incoming artifact by decoding the artifacts, dereferencing it from the artifact issuer and 
93       * storing the resulting protocol message in the message context.
94       * 
95       * @param samlMsgCtx current message context
96       * 
97       * @throws MessageDecodingException thrown if there is a problem decoding or dereferencing the artifact
98       */
99      protected void processArtifact(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
100         HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
101         String encodedArtifact = DatatypeHelper.safeTrimOrNullString(inTransport.getParameterValue("SAMLart"));
102         if (encodedArtifact == null) {
103             log.error("URL SAMLart parameter was missing or did not contain a value.");
104             throw new MessageDecodingException("URL TARGET parameter was missing or did not contain a value.");
105         }
106         
107         // TODO decode artifact; resolve issuer resolution endpoint; dereference using ArtifactResolve
108         // over synchronous backchannel binding; store resultant protocol message as the inbound SAML message.
109     }
110 }