Show / Hide Table of Contents

Class SAML

Provides common SAML definitions and helper methods.

Inheritance
System.Object
SAML
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: ComponentSpace.SAML2.Utility
Assembly: ComponentSpace.Saml2.dll
Syntax
public static class SAML
Remarks

Refer to the Assertions and Protocol for the OASIS Security Assertion Markup Language (SAML) V2.0 specification for further details.

Fields

Version

The SAML version.

Declaration
public const string Version = "2.0"
Field Value
Type Description
System.String

Properties

HttpContext

Gets or sets the HTTP context.

Declaration
public static HttpContextBase HttpContext { get; set; }
Property Value
Type Description
System.Web.HttpContextBase

The HTTP context.

HttpSessionState

Gets or sets the HTTP session state.

Declaration
public static HttpSessionStateBase HttpSessionState { get; set; }
Property Value
Type Description
System.Web.HttpSessionStateBase

The HTTP session state.

MillisecondPrecision

Gets or sets the flag indicating whether or not times should have millisecond precision when being serialized to XML.

For example, a time with millisecond precision is 06:33:14.729 whereas a time without millisecond precision is 06:33:14.

The default is true.

Declaration
public static bool MillisecondPrecision { get; set; }
Property Value
Type Description
System.Boolean

The flag indicating whether or not times should have millisecond precision.

Methods

FromBase64String(String)

Converts the base-64 encoded string into XML.

Declaration
public static XmlElement FromBase64String(string text)
Parameters
Type Name Description
System.String text

The base-64 encoded string.

Returns
Type Description
System.Xml.XmlElement

The XML.

Exceptions
Type Condition
SAMLSerializationException

Thrown when the conversion fails.

GetSAMLMessageType(XmlElement)

Returns the SAML message type.

Declaration
public static SAMLIdentifiers.MessageType GetSAMLMessageType(XmlElement xmlElement)
Parameters
Type Name Description
System.Xml.XmlElement xmlElement

The SAML message XML.

Returns
Type Description
SAMLIdentifiers.MessageType

The SAML message type.

IsSAMLRequest(SAMLIdentifiers.MessageType)

Indicates whether the SAML message is a request or response.

Declaration
public static bool IsSAMLRequest(SAMLIdentifiers.MessageType messageType)
Parameters
Type Name Description
SAMLIdentifiers.MessageType messageType

The SAML message type.

Returns
Type Description
System.Boolean

true if the SAML message is a request; otherwise false.

IsSAMLRequest(XmlElement)

Indicates whether the SAML message is a request or response.

Declaration
public static bool IsSAMLRequest(XmlElement xmlElement)
Parameters
Type Name Description
System.Xml.XmlElement xmlElement

The SAML message XML.

Returns
Type Description
System.Boolean

true if the SAML message is a request; otherwise false.

RemoveUnicodeMarkerCharacters(String)

Removes unicode marker characters from the string.

0x200E is the left-to-right marker.

0x200F is the right-to-left marker.

Declaration
public static string RemoveUnicodeMarkerCharacters(string text)
Parameters
Type Name Description
System.String text

The string.

Returns
Type Description
System.String

The string with unicode marker characters stripped.

ToAbsoluteURL(String, Boolean)

Converts a rooted URL to an absolute URL.

A rooted URL starts with the tilde (~) character.

The call must be made in the context of processing an HTTP request.

Declaration
public static string ToAbsoluteURL(string url, bool resolveToHttps)
Parameters
Type Name Description
System.String url

The rooted URL.

System.Boolean resolveToHttps

The flag indicating whether the URL should always resolve to HTTPS.

Returns
Type Description
System.String

The absolute URL.

ToBase64String(XmlElement)

Converts the XML into a base-64 encoded string.

Declaration
public static string ToBase64String(XmlElement xmlElement)
Parameters
Type Name Description
System.Xml.XmlElement xmlElement

The XML.

Returns
Type Description
System.String

The base-64 encoded string.

ToBoolean(String)

Returns the boolean value represented by a string.

Declaration
public static bool ToBoolean(string booleanString)
Parameters
Type Name Description
System.String booleanString

The boolean string.

Returns
Type Description
System.Boolean

The boolean.

Remarks

Valid values, as defined by the XML schema specification, are "true", "false", "1", "0".

Exceptions
Type Condition
SAMLSerializationException

Thrown when the boolean string value is illegal.

ToDateTime(String)

Returns the DateTime represented by the formatted date/time string.

Declaration
public static DateTime ToDateTime(string dateTimeString)
Parameters
Type Name Description
System.String dateTimeString

The date/time string.

Returns
Type Description
System.DateTime

The DateTime.

Remarks

The date/time string should be formatted as: yyyy-mm-ddThh:mm:ssZ.

As per the SAML specification, all date/time values should be coordinated universal time (UTC).

Exceptions
Type Condition
SAMLSerializationException

Thrown when the conversion fails.

ToDateTimeString()

Returns the current UTC date/time formatted as: yyyy-mm-ddThh:mm:ssZ.

Declaration
public static string ToDateTimeString()
Returns
Type Description
System.String

The formatted string.

ToDateTimeString(DateTime)

Returns a date/time string formatted as: yyyy-mm-ddThh:mm:ss.sssZ.

Declaration
public static string ToDateTimeString(DateTime dateTime)
Parameters
Type Name Description
System.DateTime dateTime

The date/time.

Returns
Type Description
System.String

The formatted string.

Remarks

As per the SAML specification, all date/time values should be coordinated universal time (UTC).

ToXmlElement(String)

Loads an XML element from an XML string.

Declaration
public static XmlElement ToXmlElement(string xmlString)
Parameters
Type Name Description
System.String xmlString

The XML string

Returns
Type Description
System.Xml.XmlElement

The XML element.

Exceptions
Type Condition
SAMLSerializationException

Thrown when the XML deserialization fails.

In This Article
Back to top Copyright © ComponentSpace Pty Ltd 2004-2022. All rights reserved.