Example #1
0
        private XmlDocument GenerateLogoutRequestMetadata(SAMLLogoutRequest context)
        {
            DateTime          now     = DateTime.UtcNow;
            LogoutRequestType request = new LogoutRequestType();

            request.ID           = context.Id;
            request.Version      = SAMLConstants.SAML_VERSION;
            request.IssueInstant = now;
            request.Destination  = context.Destination;
            request.Consent      = SAMLConstants.CONSENT;
            request.Issuer       = new NameIDType();
            request.Issuer.Value = context.Issuer;
            request.NameID       = new NameIDType();
            request.NameID.Value = ConfigurationSettingsHelper.GetCriticalConfigSetting(CommonConstants.SP_ID);

            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;

            // stork extensions
            XmlElement qualityAuthnAssLevel = doc.CreateElement(ConfigurationSettingsHelper.GetCriticalConfigSetting(CommonConstants.NS_QAALEVEL_PREFIX),
                                                                "QualityAuthenticationAssuranceLevel", ConfigurationSettingsHelper.GetCriticalConfigSetting(CommonConstants.NS_QAALEVEL));

            qualityAuthnAssLevel.InnerText = context.QAALevel;
            XmlElement spSectorEl = doc.CreateElement(SAMLConstants.NS_STORK_ASSER_PREFIX,
                                                      "spSector", SAMLConstants.NS_STORK_ASSER);

            spSectorEl.InnerText = ConfigurationSettingsHelper
                                   .GetCriticalConfigIntSetting(CommonConstants.SAMLSECTOR).ToString();
            XmlElement spInstitutionEl = doc.CreateElement(SAMLConstants.NS_STORK_ASSER_PREFIX,
                                                           "spInstitution", SAMLConstants.NS_STORK_ASSER);

            spInstitutionEl.InnerText = ConfigurationSettingsHelper
                                        .GetCriticalConfigSetting(CommonConstants.SAMLINSTITUTION);
            XmlElement spApplicationEl = doc.CreateElement(SAMLConstants.NS_STORK_ASSER_PREFIX,
                                                           "spApplication", SAMLConstants.NS_STORK_ASSER);

            spApplicationEl.InnerText = ConfigurationSettingsHelper
                                        .GetCriticalConfigSetting(CommonConstants.SAMLAPPLICATION);
            XmlElement spCountryEl = doc.CreateElement(SAMLConstants.NS_STORK_ASSER_PREFIX,
                                                       "spCountry", SAMLConstants.NS_STORK_ASSER);

            spCountryEl.InnerText = ConfigurationSettingsHelper
                                    .GetCriticalConfigSetting(CommonConstants.SAMLCOUNTRY);
            XmlElement eIDSectorShareEl = doc.CreateElement(SAMLConstants.NS_STORK_PROT_PREFIX,
                                                            "eIDSectorShare", SAMLConstants.NS_STORK_PROT);

            eIDSectorShareEl.InnerText = ConfigurationSettingsHelper
                                         .GetCriticalConfigBoolSetting("SamlEIDSectorShare").ToString().ToLower();
            XmlElement eIDCrossSectorShareEl = doc.CreateElement(SAMLConstants.NS_STORK_PROT_PREFIX,
                                                                 "eIDCrossSectorShare", SAMLConstants.NS_STORK_PROT);

            eIDCrossSectorShareEl.InnerText = ConfigurationSettingsHelper
                                              .GetCriticalConfigBoolSetting("SamlEIDCrossSectorShare").ToString().ToLower();
            XmlElement eIDCrossBorderShareEl = doc.CreateElement(SAMLConstants.NS_STORK_PROT_PREFIX,
                                                                 "eIDCrossBorderShare", SAMLConstants.NS_STORK_PROT);

            eIDCrossBorderShareEl.InnerText = ConfigurationSettingsHelper
                                              .GetCriticalConfigBoolSetting("SamlEIDCrossBorderShare").ToString().ToLower();

            request.Extensions     = new ExtensionsType();
            request.Extensions.Any = new XmlElement[] { qualityAuthnAssLevel, spSectorEl,
                                                        spInstitutionEl, spApplicationEl, spCountryEl, eIDSectorShareEl,
                                                        eIDCrossSectorShareEl, eIDCrossBorderShareEl };

            MemoryStream stream = new MemoryStream();

            Serialize(request, stream);

            StreamReader reader = new StreamReader(stream);

            stream.Seek(0, SeekOrigin.Begin);
            string        xml       = reader.ReadToEnd();
            XmlTextReader xmlReader = new XmlTextReader(new StringReader(xml));

            return(Deserialize <XmlDocument>(xmlReader));
        }