public void WriteXmlNullSubject()
        {
            SamlAuthenticationStatement c = new SamlAuthenticationStatement();
            StringWriter sw = new StringWriter();

            using (XmlDictionaryWriter dw = CreateWriter(sw)) {
                c.WriteXml(dw, new SamlSerializer(), null);
            }
        }
        public void DefaultValues()
        {
            Assert.AreEqual("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/authentication", SamlAuthenticationStatement.ClaimType, "#0");
            SamlAuthenticationStatement a = new SamlAuthenticationStatement();

            Assert.AreEqual("urn:oasis:names:tc:SAML:1.0:am:unspecified", a.AuthenticationMethod, "#1");
            Assert.IsNull(a.DnsAddress, "#2");
            Assert.IsNull(a.IPAddress, "#3");
            Assert.IsNull(a.SamlSubject, "#4");
        }
Ejemplo n.º 3
0
        public void TestMethod()
        {
            string[]      attributeValues = { "test-value" };
            SamlAttribute samlAttribute   = new SamlAttribute("urn:namespace", "attributeName", attributeValues);

            Console.WriteLine("saml attribute: " + samlAttribute);

            SamlAuthenticationStatement samlStatement = new SamlAuthenticationStatement();

            SamlAssertion samlAssertion = new SamlAssertion();

            samlAssertion.Statements.Add(samlStatement);
        }
Ejemplo n.º 4
0
        private static SamlAssertion CreateSamlAssertion(string issuer, string domain, string subject, Dictionary <string, string> attributes)
        {
            // Here we create some SAML assertion with ID and Issuer name.
            SamlAssertion assertion = new SamlAssertion();

            assertion.AssertionId = "_" + Guid.NewGuid().ToString();
            assertion.Issuer      = issuer;

            //Not before, not after conditions
            assertion.Conditions = new SamlConditions(DateTime.UtcNow,
                                                      DateTime.UtcNow.AddMinutes(10));

            //
            // Create some SAML subject.
            SamlSubject samlSubject = new SamlSubject();

            samlSubject.Name          = subject;
            samlSubject.NameQualifier = subject;

            samlSubject.ConfirmationMethods.Add("urn:oasis:names:tc:SAML:1.0:cm:bearer");
            //
            // Now create the SAML statement containing one attribute and one subject.
            SamlAttributeStatement samlAttributeStatement = new SamlAttributeStatement();

            samlAttributeStatement.SamlSubject = samlSubject;
            //
            // Create userName SAML attributes.
            foreach (KeyValuePair <string, string> attribute in attributes)
            {
                SamlAttribute attr = new SamlAttribute();
                attr.Name      = attribute.Key;
                attr.Namespace = domain;
                attr.AttributeValues.Add(subject);
                samlAttributeStatement.Attributes.Add(attr);
            }
            // Append the statement to the SAML assertion.
            assertion.Statements.Add(samlAttributeStatement);

            IPHostEntry ipEntry =
                Dns.GetHostEntry(System.Environment.MachineName);

            SamlAuthenticationStatement samlAuthenticationStatement =
                new SamlAuthenticationStatement(samlSubject,
                                                "urn:oasis:names:tc:SAML:1.0:am:password",
                                                DateTime.UtcNow, null, ipEntry.AddressList[0].ToString(),
                                                null);

            assertion.Statements.Add(samlAuthenticationStatement);
            return(assertion);
        }
        public void WriteXml1()
        {
            SamlAuthenticationStatement c = new SamlAuthenticationStatement();

            c.SamlSubject = new SamlSubject("myFormat", "myQualifier", "myName");
            DateTime instant = DateTime.SpecifyKind(new DateTime(2000, 1, 1), DateTimeKind.Utc);

            c.AuthenticationInstant = instant;
            c.DnsAddress            = "123.45.67.89";
            c.IPAddress             = "98.76.54.32";

            StringWriter sw = new StringWriter();

            using (XmlDictionaryWriter dw = CreateWriter(sw)) {
                c.WriteXml(dw, new SamlSerializer(), null);
            }
            Assert.AreEqual(String.Format("<?xml version=\"1.0\" encoding=\"utf-16\"?><saml:AuthenticationStatement AuthenticationMethod=\"urn:oasis:names:tc:SAML:1.0:am:unspecified\" AuthenticationInstant=\"2000-01-01T00:00:00.000Z\" xmlns:saml=\"{0}\"><saml:Subject><saml:NameIdentifier Format=\"myFormat\" NameQualifier=\"myQualifier\">myName</saml:NameIdentifier></saml:Subject><saml:SubjectLocality IPAddress=\"98.76.54.32\" DNSAddress=\"123.45.67.89\" /></saml:AuthenticationStatement>",
                                          SamlConstants.Namespace), sw.ToString());
        }
Ejemplo n.º 6
0
        public void CompareSamlAuthenticationStatements()
        {
            TestUtilities.WriteHeader($"{this}.CompareSamlAuthenticationStatements", true);
            var context = new CompareContext($"{this}.CompareSamlAuthenticationStatements");
            var samlAttributeStatement1 = new SamlAuthenticationStatement(new SamlSubject(),
                                                                          Guid.NewGuid().ToString(), DateTime.Parse(Default.AuthenticationInstant), null, null,
                                                                          new List <SamlAuthorityBinding>
            {
                new SamlAuthorityBinding(new System.Xml.XmlQualifiedName(Default.AuthorityKind), Default.Location,
                                         Default.Binding)
            });
            var samlAttributeStatement2 = new SamlAuthenticationStatement(new SamlSubject(),
                                                                          Guid.NewGuid().ToString(), DateTime.Parse(Default.AuthenticationInstant), null, null,
                                                                          new List <SamlAuthorityBinding>
            {
                new SamlAuthorityBinding(new System.Xml.XmlQualifiedName(Default.AuthorityKind), Default.Location,
                                         Default.Binding)
            });

            IdentityComparer.AreEqual(samlAttributeStatement1, samlAttributeStatement2, context);

            Assert.True(context.Diffs.Count(s => s == "AuthenticationMethod:") == 1);
        }