/// <summary> /// Initializes a new instance of the LogoutResponse class based on /// the complimentary logout request. /// </summary> /// <param name="identityProvider"> /// IdentityProvider of the LogoutResponse /// </param> /// <param name="serviceProvider"> /// ServiceProvider of the LogoutResponse /// </param> /// <param name="logoutRequest"> /// Logout request that requires this response /// </param> /// <param name="parameters"> /// NameValueCollection of varying parameters for use in the /// construction of the LogoutResponse. /// </param> public LogoutResponse( IIdentityProvider identityProvider, IServiceProvider serviceProvider, LogoutRequest logoutRequest, NameValueCollection parameters) { if (identityProvider == null) { throw new Saml2Exception(Resources.LogoutResponseIdentityProviderIsNull); } if (serviceProvider == null) { throw new Saml2Exception(Resources.LogoutResponseServiceProviderIsNull); } if (logoutRequest == null) { throw new Saml2Exception(Resources.LogoutResponseLogoutRequestIsNull); } if (parameters == null) { parameters = new NameValueCollection(); } var inResponseToValue = logoutRequest.Id; var issuerValue = serviceProvider.EntityId; var binding = parameters[Saml2Constants.Binding]; if (string.IsNullOrEmpty(binding)) { binding = Saml2Constants.HttpPostProtocolBinding; } string idpSvcResponseLocation = null; if (binding != Saml2Constants.HttpSoapProtocolBinding) { idpSvcResponseLocation = identityProvider.GetSingleLogoutServiceResponseLocation(binding); } m_xml = new XmlDocument { PreserveWhitespace = true }; m_nsMgr = new XmlNamespaceManager(m_xml.NameTable); m_nsMgr.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol"); m_nsMgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion"); var rawXml = new StringBuilder(); rawXml.Append("<samlp:LogoutResponse xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" "); rawXml.Append(" ID=\"" + Saml2Utils.GenerateId() + "\" Version=\"2.0\" "); rawXml.Append(" IssueInstant=\"" + Saml2Utils.GenerateIssueInstant() + "\" "); if (idpSvcResponseLocation != null) { rawXml.Append(" Destination=\"" + idpSvcResponseLocation + "\" "); } rawXml.Append(" InResponseTo=\"" + inResponseToValue + "\">"); rawXml.Append(" <saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + issuerValue + "</saml:Issuer>"); rawXml.Append(" <samlp:Status xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\">"); rawXml.Append(" <samlp:StatusCode "); rawXml.Append(" xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" "); rawXml.Append(" Value=\"" + Saml2Constants.Success + "\">"); rawXml.Append(" </samlp:StatusCode>"); rawXml.Append(" </samlp:Status>"); rawXml.Append("</samlp:LogoutResponse>"); m_xml.LoadXml(rawXml.ToString()); }
/// <summary> /// Initializes a new instance of the LogoutResponse class based on /// the complimentary logout request. /// </summary> /// <param name="identityProvider"> /// IdentityProvider of the LogoutResponse /// </param> /// <param name="serviceProvider"> /// ServiceProvider of the LogoutResponse /// </param> /// <param name="logoutRequest"> /// Logout request that requires this response /// </param> /// <param name="parameters"> /// NameValueCollection of varying parameters for use in the /// construction of the LogoutResponse. /// </param> /// <param name="saml2Utils">Utilities class</param> public LogoutResponse( IIdentityProvider identityProvider, IServiceProvider serviceProvider, LogoutRequest logoutRequest, NameValueCollection parameters, Saml2Utils saml2Utils) { if (identityProvider == null) { throw new Saml2Exception(Resources.LogoutResponseIdentityProviderIsNull); } else if (serviceProvider == null) { throw new Saml2Exception(Resources.LogoutResponseServiceProviderIsNull); } else if (logoutRequest == null) { throw new Saml2Exception(Resources.LogoutResponseLogoutRequestIsNull); } if (parameters == null) { parameters = new NameValueCollection(); } string inResponseToValue = logoutRequest.Id; string issuerValue = serviceProvider.EntityId; string binding = parameters[Saml2Constants.Binding]; if (string.IsNullOrEmpty(binding)) { binding = Saml2Constants.HttpPostProtocolBinding; } string idpSvcResponseLocation = null; if (binding != Saml2Constants.HttpSoapProtocolBinding) { idpSvcResponseLocation = identityProvider.GetSingleLogoutServiceResponseLocation(binding); } xml = new XmlDocument(); xml.PreserveWhitespace = true; nsMgr = new XmlNamespaceManager(xml.NameTable); nsMgr.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol"); nsMgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion"); var rawXml = new StringBuilder(); rawXml.Append("<samlp:LogoutResponse xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" "); rawXml.Append(" ID=\"" + saml2Utils.GenerateId() + "\" Version=\"2.0\" "); rawXml.Append(" IssueInstant=\"" + saml2Utils.GenerateIssueInstant() + "\" "); if (idpSvcResponseLocation != null) { rawXml.Append(" Destination=\"" + idpSvcResponseLocation + "\" "); } rawXml.Append(" InResponseTo=\"" + inResponseToValue + "\">"); rawXml.Append(" <saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + issuerValue + "</saml:Issuer>"); rawXml.Append(" <samlp:Status xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\">"); rawXml.Append(" <samlp:StatusCode "); rawXml.Append(" xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" "); rawXml.Append(" Value=\"" + Saml2Constants.Success + "\">"); rawXml.Append(" </samlp:StatusCode>"); rawXml.Append(" </samlp:Status>"); rawXml.Append("</samlp:LogoutResponse>"); xml.LoadXml(rawXml.ToString()); }