code: @SuppressWarnings("unchecked")
      static <T extends SAMLObject> MessageContext<T> toSamlObject(
              AggregatedHttpMessage msg, String name,
              Map<String, SamlIdentityProviderConfig> idpConfigs,
              @Nullable SamlIdentityProviderConfig defaultIdpConfig) {
          requireNonNull(msg, "msg");
          requireNonNull(name, "name");
          requireNonNull(idpConfigs, "idpConfigs");
  
          final SamlParameters parameters = new SamlParameters(msg);
          final T message = (T) fromDeflatedBase64(parameters.getFirstValue(name));
  
          final MessageContext<T> messageContext = new MessageContext<>();
          messageContext.setMessage(message);
  
          final Issuer issuer;
          if (message instanceof RequestAbstractType) {
              issuer = ((RequestAbstractType) message).getIssuer();
          } else if (message instanceof StatusResponseType) {
              issuer = ((StatusResponseType) message).getIssuer();
          } else {
              throw new SamlException("invalid message type: " + message.getClass().getSimpleName());
          }
  
          // Use the default identity provider config if there's no issuer.
          final SamlIdentityProviderConfig config;
          if (issuer != null) {
              final String idpEntityId = issuer.getValue();
              config = idpConfigs.get(idpEntityId);
              if (config == null) {
                  throw new SamlException("a message from unknown identity provider: " + idpEntityId);
              }
          } else {
              if (defaultIdpConfig == null) {
                  throw new SamlException("failed to get an Issuer element");
              }
              config = defaultIdpConfig;
          }
  
          // If this message is sent via HTTP-redirect binding protocol, its signature parameter should
          // be validated.
          validateSignature(config.signingCredential(), parameters, name);
  
          final String relayState = parameters.getFirstValueOrNull(RELAY_STATE);
          if (relayState != null) {
              final SAMLBindingContext context = messageContext.getSubcontext(SAMLBindingContext.class, true);
              assert context != null;
              context.setRelayState(relayState);
          }
  
          return messageContext;
      }
docs: Converts an {@link AggregatedHttpMessage} which is received from the remote entity to
  a {@link SAMLObject}.