Example #1
0
        protected void DownloadButton_Click(object sender, EventArgs e)
        {
            try
            {
                string partnerName = partnerNameDropDownList.SelectedValue;

                // Get the X.509 certificate.
                LocalIdentityProviderConfiguration  localIdentityProviderConfiguration  = SAMLController.Configuration.LocalIdentityProviderConfiguration;
                PartnerServiceProviderConfiguration partnerServiceProviderConfiguration = !String.IsNullOrEmpty(partnerName) ? SAMLController.Configuration.GetPartnerServiceProvider(partnerName) : null;
                IList <X509Certificate2>            x509Certificates = SAMLController.CertificateManager.GetLocalIdentityProviderSignatureCertificates(localIdentityProviderConfiguration, partnerServiceProviderConfiguration);
                X509Certificate2 x509Certificate = null;

                if (x509Certificates.Count > 0)
                {
                    x509Certificate = x509Certificates[0];
                }

                // Export the configuration as SAML metadata.
                EntityDescriptor entityDescriptor =
                    MetadataExporter.Export(
                        SAMLController.Configuration,
                        x509Certificate,
                        CreateAbsoluteURL("~/SAML/SSOService.aspx"), CreateAbsoluteURL("~/SAML/SLOService.aspx"),
                        partnerName);

                // Convert the SAML metadata to XML ready for downloading.
                XmlElement metadataElement = entityDescriptor.ToXml();

                // Download the SAML metadata.
                Response.Clear();
                Response.ContentType = "text/xml";
                Response.AddHeader("Content-Disposition", "attachment; filename=\"metadata.xml\"");

                using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8))
                {
                    xmlTextWriter.Formatting = Formatting.Indented;
                    metadataElement.OwnerDocument.Save(xmlTextWriter);
                }

                Response.End();
            }

            catch (Exception exception)
            {
                errorMessageLabel.Text = string.Format("An error occurred exporting the SAML configuration.<br/>{0}", exception.ToString());
            }
        }
Example #2
0
        private static LocalIdentityProviderConfiguration CreateIdentityProviderConfiguration()
        {
            var localIdentityProviderConfiguration = new LocalIdentityProviderConfiguration()
            {
                Name = GetProviderName()
            };

            Console.Write("Single Sign-On Service URL [None]: ");
            localIdentityProviderConfiguration.SingleSignOnServiceUrl = ReadLine();

            Console.Write("Single Logout Service URL [None]: ");
            localIdentityProviderConfiguration.SingleLogoutServiceUrl = ReadLine();

            GetCertificateConfiguration(localIdentityProviderConfiguration);

            return(localIdentityProviderConfiguration);
        }
Example #3
0
        private static EntityDescriptor CreateIdentityProviderMetadata()
        {
            var entityID = GetEntityID();

            Console.Write("X.509 signature certificate .CER file [None]: ");
            var fileName             = Console.ReadLine();
            var signatureCertificate = LoadCertificate(fileName);

            Console.Write("Single Sign-On Service URL: ");
            var singleSignOnServiceUrl = Console.ReadLine();

            if (string.IsNullOrEmpty(singleSignOnServiceUrl))
            {
                throw new ArgumentException("A single sign-on service URL must be specified.");
            }

            Console.Write("Single Logout Service URL [None]: ");
            var singleLogoutServiceUrl = Console.ReadLine();

            Console.Write("Name ID Format [None]: ");
            var nameIDFormat = Console.ReadLine();

            var wantAuthnRequestsSigned = GetBoolean("Want authn requests signed? [False]: ");

            var localIdentityProviderConfiguration = new LocalIdentityProviderConfiguration()
            {
                Name = entityID
            };

            var partnerServiceProviderConfiguration = new PartnerServiceProviderConfiguration()
            {
                NameIDFormat           = !string.IsNullOrEmpty(nameIDFormat) ? nameIDFormat : SAMLIdentifiers.NameIdentifierFormats.Unspecified,
                WantAuthnRequestSigned = wantAuthnRequestsSigned.HasValue ? wantAuthnRequestsSigned.Value : false
            };

            return(MetadataExporter.Export(localIdentityProviderConfiguration, signatureCertificate, singleSignOnServiceUrl, singleLogoutServiceUrl, partnerServiceProviderConfiguration));
        }