ComponentSpace Professional .NET and ActiveX components for developers
ComponentSpace Home | Products | Downloads | Support | Purchase | Services | About Us
 

Code Samples

The product includes numerous VB.NET and C# sample applications. All samples include complete source code. For more detailed sample code please refer to the sample applications.


Creating a SAML Assertion

Listing 1 demonstrates creating a SAML assertion.



Dim assertion As New Assertion

assertion.Issuer = "urn:test"
assertion.Conditions = New Conditions(New TimeSpan(1, 0, 0))

Dim authenticationStatement As New AuthenticationStatement(authenticationStatement.AuthenticationMethods.Password)
Dim nameIdentifier As New NameIdentifier("urn:test", nameIdentifier.Formats.X509SubjectName, "uid=test,ou=People,dc=test,dc=com")
Dim subjectConfirmation As New SubjectConfirmation(ConfirmationMethod.Methods.Bearer)

authenticationStatement.Subject = New Subject(nameIdentifier, subjectConfirmation)

assertion.Statements.Add(authenticationStatement)

Dim attributeStatement As New AttributeStatement

attributeStatement.Subject = authenticationStatement.Subject
attributeStatement.Attributes.Add(New Attribute("email", "urn:test", "test@test.com"))
attributeStatement.Attributes.Add(New Attribute("MemberLevel", "urn:test", "Gold"))

assertion.Statements.Add(attributeStatement)
									

Listing 1 Creating a SAML assertion


Serializing a SAML Assertion to and from XML

Listing 2 demonstrates serializing a SAML Assertion to and from XML.



Dim xmlElement as XmlElement

' Load the XML (not shown)

Dim assertion As New Assertion(xmlElement)

xmlElement = assertion.ToXml()
									

Serializing a SAML Assertion to and from XML


Generating and Verifying an XML Signature

Listing 3 demonstrates generating and verifying an XML signature contained within a SAML assertion.



' Load the SAML assertion XML, certificate and key (not shown)									
Dim samlXmlElement as XmlElement
Dim x509Certificate as X509Certificate
Dim privateKey As RSA

AssertionSignature.Generate(samlXmlElement, privateKey, x509Certificate)

AssertionSignature.Verify(samlXmlElement)
									

Listing 3 Generating and verifying an XML signature