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

                // Get the X.509 certificate.
                LocalServiceProviderConfiguration    localServiceProviderConfiguration    = SAMLController.Configuration.LocalServiceProviderConfiguration;
                PartnerIdentityProviderConfiguration partnerIdentityProviderConfiguration = !String.IsNullOrEmpty(partnerName) ? SAMLController.Configuration.GetPartnerIdentityProvider(partnerName) : null;
                IList <X509Certificate2>             x509Certificates = SAMLController.CertificateManager.GetLocalServiceProviderSignatureCertificates(localServiceProviderConfiguration, partnerIdentityProviderConfiguration);
                X509Certificate2 x509Certificate = null;

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

                // Export the configuration as SAML metadata.
                EntityDescriptor entityDescriptor =
                    MetadataExporter.Export(
                        SAMLController.Configuration,
                        x509Certificate, null,
                        CreateAbsoluteURL("~/SAML/AssertionConsumerService.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());
            }
        }
示例#2
0
        private static LocalServiceProviderConfiguration CreateServiceProviderConfiguration()
        {
            var localServiceProviderConfiguration = new LocalServiceProviderConfiguration()
            {
                Name = GetProviderName()
            };

            Console.Write("Assertion Consumer Service URL [None]: ");
            localServiceProviderConfiguration.AssertionConsumerServiceUrl = ReadLine();

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

            GetCertificateConfiguration(localServiceProviderConfiguration);

            return(localServiceProviderConfiguration);
        }
示例#3
0
        private static EntityDescriptor CreateServiceProviderMetadata()
        {
            var entityID = GetEntityID();

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

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

            Console.Write("Assertion Consumer Service URL: ");
            var assertionConsumerServiceUrl = Console.ReadLine();

            if (string.IsNullOrEmpty(assertionConsumerServiceUrl))
            {
                throw new ArgumentException("An assertion consumer 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 authnRequestsSigned  = GetBoolean("Authn requests signed? [False]: ");
            var wantAssertionsSigned = GetBoolean("Want assertions signed? [False]: ");

            var localServiceProviderConfiguration = new LocalServiceProviderConfiguration()
            {
                Name = entityID
            };

            var partnerIdentityProviderConfiguration = new PartnerIdentityProviderConfiguration()
            {
                NameIDFormat        = !string.IsNullOrEmpty(nameIDFormat) ? nameIDFormat : SAMLIdentifiers.NameIdentifierFormats.Unspecified,
                SignAuthnRequest    = authnRequestsSigned.HasValue ? authnRequestsSigned.Value : false,
                WantAssertionSigned = wantAssertionsSigned.HasValue ? wantAssertionsSigned.Value : false
            };

            return(MetadataExporter.Export(localServiceProviderConfiguration, signatureCertificate, encryptionCertificate, assertionConsumerServiceUrl, singleLogoutServiceUrl, partnerIdentityProviderConfiguration));
        }