Class SAML
Provides common SAML definitions and helper methods.
Inherited Members
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 |
|---|---|
| string |
Properties
HttpContext
Gets or sets the HTTP context.
Declaration
public static HttpContextBase HttpContext { get; set; }
Property Value
| Type | Description |
|---|---|
| HttpContextBase | The HTTP context. |
HttpSessionState
Gets or sets the HTTP session state.
Declaration
public static HttpSessionStateBase HttpSessionState { get; set; }
Property Value
| Type | Description |
|---|---|
| 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 |
|---|---|
| bool | 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 |
|---|---|---|
| string | text | The base-64 encoded string. |
Returns
| Type | Description |
|---|---|
| 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 |
|---|---|---|
| XmlElement | xmlElement | The SAML message XML. |
Returns
| Type | Description |
|---|---|
| SAMLIdentifiers.MessageType | The SAML message type. |
IsSAMLRequest(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 |
|---|---|
| bool |
|
IsSAMLRequest(XmlElement)
Indicates whether the SAML message is a request or response.
Declaration
public static bool IsSAMLRequest(XmlElement xmlElement)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlElement | xmlElement | The SAML message XML. |
Returns
| Type | Description |
|---|---|
| bool |
|
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 |
|---|---|---|
| string | text | The string. |
Returns
| Type | Description |
|---|---|
| string | The string with unicode marker characters stripped. |
ToAbsoluteURL(string, bool)
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 |
|---|---|---|
| string | url | The rooted URL. |
| bool | resolveToHttps | The flag indicating whether the URL should always resolve to HTTPS. |
Returns
| Type | Description |
|---|---|
| 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 |
|---|---|---|
| XmlElement | xmlElement | The XML. |
Returns
| Type | Description |
|---|---|
| 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 |
|---|---|---|
| string | booleanString | The boolean string. |
Returns
| Type | Description |
|---|---|
| bool | 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 |
|---|---|---|
| string | dateTimeString | The date/time string. |
Returns
| Type | Description |
|---|---|
| DateTime | The |
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 |
|---|---|
| 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 |
|---|---|---|
| DateTime | dateTime | The date/time. |
Returns
| Type | Description |
|---|---|
| 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 |
|---|---|---|
| string | xmlString | The XML string |
Returns
| Type | Description |
|---|---|
| XmlElement | The XML element. |
Exceptions
| Type | Condition |
|---|---|
| SAMLSerializationException | Thrown when the XML deserialization fails. |