ComponentPro UltimateSaml

AttributeStatement Class

See AlsoMembersMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
The AttributeStatement element describes a statement by the SAML authority asserting that the statement�s subject is associated with the specified attributes.


public class AttributeStatement : SubjectStatement


Shows how to create, sign and validate an Assertion object.

using System;
using System.Security.Cryptography.X509Certificates;
using ComponentPro.Saml;
using ComponentPro.Saml1;


static Assertion CreateAssertion()
    // Create a new instance of the Assertion class. 
    Assertion assertion = new Assertion();

    // Set Issuer 
    assertion.Issuer = "urn:test";
    // Set Conditions 
    assertion.Conditions = new Conditions(new TimeSpan(1, 0, 0));

    // Create an AuthenticationStatement. 
    AuthenticationStatement authenticationStatement = new AuthenticationStatement(AuthenticationMethodIdenfifiers.Password);
    NameIdentifier nameIdentifier = new NameIdentifier("urn:test", NameIdentifierFormats.X509SubjectName, "uid=test,ou=People,dc=test,dc=com");
    SubjectConfirmation subjectConfirmation = new SubjectConfirmation(ConfirmationMethods.Bearer);

    authenticationStatement.Subject = new Subject(nameIdentifier, subjectConfirmation);

    // Add the AuthenticationStatement to the Assertion. 

    // Add attributes to the Assertion. 
    AttributeStatement attributeStatement = new AttributeStatement();

    attributeStatement.Subject = authenticationStatement.Subject;
    attributeStatement.Attributes.Add(new ComponentPro.Saml1.Attribute("email", "urn:test", ""));
    attributeStatement.Attributes.Add(new ComponentPro.Saml1.Attribute("FirstName", "urn:test", "John"));
    attributeStatement.Attributes.Add(new ComponentPro.Saml1.Attribute("LastName", "urn:test", "Vu"));


    return assertion;

static void SignAssertion(Assertion assertion)
    // Load certificate to sign the assertion. 
    X509Certificate2 cert = new X509Certificate2("Pkey.pfx", "password");

    // Sign the assertion 

static void ValidateAssertion(Assertion assertion)
    if (assertion.IsSigned())
        bool result = assertion.Validate();

        if (result)
            System.Diagnostics.Trace.WriteLine("Assertion is validated");
            System.Diagnostics.Trace.WriteLine("Assertion cannot be validated");

static void Main()
        Assertion assertion = CreateAssertion();

    catch (SamlException samlException)
        // Handle the exception here. 
        // ... 

Inheritance Hierarchy



.NET Framework.NET Framework

Supported version: 2.0, 3.0, 3.5, 4.0, 4.5.x, 4.6.x and later
Assembly: ComponentPro.Saml (in ComponentPro.Saml.dll)

See Also