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 edu.internet2.middleware.shibboleth.idp.profile.saml1;
    18
    19  import org.joda.time.DateTime;
    20  import org.joda.time.chrono.ISOChronology;
    21  import org.opensaml.common.SAMLObject;
    22  import org.opensaml.common.binding.SAMLMessageContext;
    23  import org.opensaml.common.binding.decoding.SAMLMessageDecoder;
    24  import org.opensaml.saml1.binding.decoding.BaseSAML1MessageDecoder;
    25  import org.opensaml.ws.message.MessageContext;
    26  import org.opensaml.ws.message.decoder.MessageDecodingException;
    27  import org.opensaml.ws.transport.http.HTTPInTransport;
    28  import org.opensaml.xml.util.DatatypeHelper;
    29  import org.slf4j.Logger;
    30  import org.slf4j.LoggerFactory;
    31
    32  import edu.internet2.middleware.shibboleth.idp.profile.saml1.ShibbolethSSOProfileHandler.ShibbolethSSORequestContext;
    33
    34  /**
    35   * Shibboleth 1.0 SSO authentication request message decoder.
    36   */
    37  public class ShibbolethSSODecoder extends BaseSAML1MessageDecoder implements SAMLMessageDecoder {
    38
    39      /** Class logger. */
    40      private final Logger log = LoggerFactory.getLogger(ShibbolethSSODecoder.class);
    41
    42      /** Constructor. */
    43      public ShibbolethSSODecoder(){
    44          super(null);
    45      }
    46
    47      /** {@inheritDoc} */
    48      public String getBindingURI() {
    49          return "urn:mace:shibboleth:1.0:profiles:AuthnRequest";
    50      }
    51
    52      /** {@inheritDoc} */
    53      protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
    54          if (!(messageContext instanceof ShibbolethSSORequestContext)) {
    55              log.error("Invalid message context type, this decoder only support ShibbolethSSORequestContext");
    56              throw new MessageDecodingException(
    57                      "Invalid message context type, this decoder only support ShibbolethSSORequestContext");
    58          }
    59
    60          if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
    61              log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
    62              throw new MessageDecodingException(
    63                      "Invalid inbound message transport type, this decoder only support HTTPInTransport");
    64          }
    65
    66          ShibbolethSSORequestContext requestContext = (ShibbolethSSORequestContext) messageContext;
    67          HTTPInTransport transport = (HTTPInTransport) messageContext.getInboundMessageTransport();
    68
    69          String providerId = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("providerId"));
    70          if (providerId == null) {
    71              log.error("No providerId parameter given in Shibboleth SSO authentication request.");
    72              throw new MessageDecodingException(
    73                      "No providerId parameter given in Shibboleth SSO authentication request.");
    74          }
    75          requestContext.setInboundMessageIssuer(providerId);
    76
    77          String shire = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("shire"));
    78          if (shire == null) {
    79              log.error("No shire parameter given in Shibboleth SSO authentication request.");
    80              throw new MessageDecodingException("No shire parameter given in Shibboleth SSO authentication request.");
    81          }
    82          requestContext.setSpAssertionConsumerService(shire);
    83
    84          String target = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("target"));
    85          if (target == null) {
    86              log.error("No target parameter given in Shibboleth SSO authentication request.");
    87              throw new MessageDecodingException("No target parameter given in Shibboleth SSO authentication request.");
    88          }
    89          requestContext.setRelayState(target);
    90
    91          String timeStr = DatatypeHelper.safeTrimOrNullString(transport.getParameterValue("time"));
    92          if (timeStr != null) {
    93              long time = Long.parseLong(timeStr) * 1000;
    94              requestContext.setInboundSAMLMessageIssueInstant(new DateTime(time, ISOChronology.getInstanceUTC()));
    95          }
    96
    97          populateRelyingPartyMetadata(requestContext);
    98      }
    99
    100     /** {@inheritDoc} */
    101     protected boolean isIntendedDestinationEndpointURIRequired(SAMLMessageContext samlMsgCtx) {
    102         return false;
    103     }
    104
    105     /** {@inheritDoc} */
    106     protected String getIntendedDestinationEndpointURI(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
    107         // Not relevant in this binding/profile, there is neither SAML message
    108         // nor binding parameter with this information
    109         return null;
    110     }
    111
    112 }