/// <summary> /// Initialize the instance with an already existing metadata document. /// </summary> public Saml20MetadataDocument(XmlDocument entityDescriptor) : this() { if (XmlSignatureUtils.IsSigned(entityDescriptor)) if (!XmlSignatureUtils.CheckSignature(entityDescriptor)) throw new Saml20Exception("Metadata signature could not be verified."); ExtractKeyDescriptors(entityDescriptor); _entity = Serialization.DeserializeFromXmlString<EntityDescriptor>(entityDescriptor.OuterXml); }
private void GenerateMetadataDocument(HttpContext context) { EntityDescriptor metadata = new EntityDescriptor(); metadata.entityID = IDPConfig.ServerBaseUrl; metadata.ID = "id" + Guid.NewGuid().ToString("N"); IDPSSODescriptor descriptor = new IDPSSODescriptor(); metadata.Items = new object[] { descriptor }; descriptor.protocolSupportEnumeration = new string[] { Saml20Constants.PROTOCOL }; descriptor.KeyDescriptor = CreateKeyDescriptors(); { // Signon endpoint Endpoint endpoint = new Endpoint(); endpoint.Location = IDPConfig.ServerBaseUrl + "Signon.ashx"; endpoint.Binding = Saml20Constants.ProtocolBindings.HTTP_Redirect; descriptor.SingleSignOnService = new Endpoint[] { endpoint }; } { // Logout endpoint Endpoint endpoint = new Endpoint(); endpoint.Location = IDPConfig.ServerBaseUrl + "Logout.ashx"; endpoint.Binding = Saml20Constants.ProtocolBindings.HTTP_Redirect; descriptor.SingleLogoutService = new Endpoint[] { endpoint }; } // Create the list of attributes offered. List<SamlAttribute> atts = new List<SamlAttribute>(IDPConfig.attributes.Length); foreach (string name in IDPConfig.attributes) { SamlAttribute att = new SamlAttribute(); att.NameFormat = SamlAttribute.NAMEFORMAT_BASIC; att.Name = name; atts.Add(att); } descriptor.Attributes = atts.ToArray(); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.LoadXml(Serialization.SerializeToXmlString(metadata)); signDocument(doc); context.Response.Write( doc.OuterXml ); }
private static EntityDescriptor GetDefaultEntityInstance() { EntityDescriptor result = new EntityDescriptor(); result.ID = "id" + Guid.NewGuid().ToString("N"); return result; }
/// <summary> /// Creates a default entity in the /// </summary> /// <returns></returns> public EntityDescriptor CreateDefaultEntity() { if (_entity != null) throw new InvalidOperationException("An entity is already created in this document."); _entity = GetDefaultEntityInstance(); return _entity; }