public CommandResult Run(HttpRequestData request, IOptions options) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var binding = options.Notifications.GetBinding(request); if (binding != null) { UnbindResult unbindResult = null; try { unbindResult = binding.Unbind(request, options); options.Notifications.MessageUnbound(unbindResult); var samlResponse = new Saml2Response(unbindResult.Data, request.StoredRequestState?.MessageId); var result = ProcessResponse(options, samlResponse, request.StoredRequestState); if (unbindResult.RelayState != null) { result.ClearCookieName = "Go2." + unbindResult.RelayState; } options.Notifications.AcsCommandResultCreated(result, samlResponse); return(result); } catch (FormatException ex) { throw new BadFormatSamlResponseException( "The SAML Response did not contain valid BASE64 encoded data.", ex); } catch (XmlException ex) { var newEx = new BadFormatSamlResponseException( "The SAML response contains incorrect XML", ex); // Add the payload to the exception if (unbindResult != null) { newEx.Data["Saml2Response"] = unbindResult.Data.OuterXml; } throw newEx; } catch (Exception ex) { if (unbindResult != null) { // Add the payload to the existing exception ex.Data["Saml2Response"] = unbindResult.Data.OuterXml; } throw; } } throw new NoSamlResponseFoundException(); }
/// <summary> /// Checks if the binding can extract a message out of the current /// http request. /// </summary> /// <param name="request">HttpRequest to check for message.</param> /// <returns>True if the binding supports the current request.</returns> protected internal abstract bool CanUnbind(HttpRequestData request);
/// <summary> /// Get a cached binding instance that can handle the current request. /// </summary> /// <param name="request">Current HttpRequest</param> /// <returns>A derived class instance that supports the requested binding, /// or null if no binding supports the current request.</returns> public static Saml2Binding Get(HttpRequestData request) { return(bindings.FirstOrDefault(b => b.Value.CanUnbind(request)).Value); }
/// <summary> /// Extracts a message out of the current HttpRequest. /// </summary> /// <param name="request">Current HttpRequest.</param> /// <param name="options">Options, used to look up certificate information /// in bindings that validate signatures. If set to null, the returned /// result will have TrustLevel.None.</param> /// <returns>Extracted message.</returns> public virtual UnbindResult Unbind(HttpRequestData request, IOptions options) { throw new NotImplementedException(); }