SAML v2.0 Developer Guide
SAML v2.0 Developer Guide
NET
Developer Guide
Contents
1
2
3
Introduction ................................................................................................................. 1
1.1 Features ................................................................................................................ 1
1.2 Benefits................................................................................................................. 1
1.3 Prerequisites ......................................................................................................... 2
Getting Started ............................................................................................................ 2
An Introduction to SAML SSO .................................................................................. 2
3.1 IdP-Initiated SSO ................................................................................................. 2
3.2 SP-Initiated SSO .................................................................................................. 3
3.3 IdP-Initiated SLO ................................................................................................. 4
3.4 SP-Initiated SLO .................................................................................................. 5
3.5 Security Considerations........................................................................................ 6
3.5.1 Transport Level Security................................................................................. 6
3.5.2 XML Signatures .............................................................................................. 6
3.5.3 XML Encryption ............................................................................................. 7
Using the Class Library .............................................................................................. 8
4.1 Adding a Reference .............................................................................................. 8
4.2 Distribution........................................................................................................... 9
SAML High Level API ............................................................................................... 9
5.1 SAML Identity Provider APIs.............................................................................. 9
5.1.1 SAMLIdentityProvider.InitiateSSO................................................................ 9
5.1.2 SAMLIdentityProvider.ReceiveSSO ............................................................ 10
5.1.3 SAMLIdentityProvider.SendSSO ................................................................. 10
5.1.4 SAMLIdentityProvider.InitiateSLO ............................................................. 10
5.1.5 SAMLIdentityProvider.ReceiveSLO ............................................................ 10
5.1.6 SAMLIdentityProvider.SendSLO ................................................................. 11
5.2 SAML Service Provider APIs ............................................................................ 11
5.2.1 SAMLServiceProvider.InitiateSSO .............................................................. 11
5.2.2 SAMLServiceProvider.ReceiveSSO ............................................................ 12
5.2.3 SAMLServiceProvider.InitiateSLO .............................................................. 12
5.2.4 SAMLServiceProvider.ReceiveSLO ............................................................ 13
5.2.5 SAMLServiceProvider.SendSLO ................................................................. 13
5.3 Configuration Management................................................................................ 13
5.4 ICertificateManager Interface ............................................................................ 13
5.4.1 CertificateManager ....................................................................................... 14
5.4.2 Custom ICertificateManager ......................................................................... 14
5.5 IIDCache Interface ............................................................................................. 15
5.5.1 InMemoryIDCache ....................................................................................... 15
5.5.2 DatabaseIDCache .......................................................................................... 15
5.5.3 Custom IDCache ........................................................................................... 16
5.6 ISSOSessionStore Interface ............................................................................... 17
5.6.1 HttpSSOSessionStore ................................................................................... 17
5.6.2 DatabaseSSOSessionStore ............................................................................ 17
5.6.3 Custom ISSOSessionStore ............................................................................ 19
SAML High Level API Configuration ..................................................................... 19
ii
iii
iv
11.11
Metadata Examples ..................................................................................... 171
11.11.1 Import Metadata Example Application ................................................. 171
11.11.2 Export Metadata Example Application ................................................. 171
11.11.3 SAML Metadata Example Application ................................................. 172
11.11.4 ReadMetadata ........................................................................................ 172
11.12
Signature Examples .................................................................................... 172
11.12.1 SHA-256 Signature Example Application ............................................ 172
11.12.2 SignSAML ............................................................................................ 172
11.12.3 VerifySAML ......................................................................................... 173
11.13
Utility Applications ..................................................................................... 173
11.13.1 ValidateConfig ...................................................................................... 173
11.13.2 ValidateXML ........................................................................................ 173
11.13.3 EncryptSAML ....................................................................................... 174
11.13.4 DecryptSAML ....................................................................................... 174
11.13.5 ParseHttpRedirectUrl ............................................................................ 174
11.13.6 Java Utilities .......................................................................................... 174
12 Creating your own SSO Application ...................................................................... 175
12.1
Considerations............................................................................................. 175
12.1.1 Error Handling .......................................................................................... 175
12.1.2 Configuration ............................................................................................ 175
12.1.3 Key Management ...................................................................................... 176
12.1.4 Security ..................................................................................................... 176
13 Test Certificates and Keys ...................................................................................... 176
13.1
Makecert ..................................................................................................... 176
13.1.1 Makecert and SHA-256 XML Signatures................................................. 177
13.2
Microsoft Certificate Server ....................................................................... 177
13.3
Keytool ........................................................................................................ 178
14 SAML Metadata...................................................................................................... 178
14.1
Metadata Production ................................................................................... 178
14.2
Metadata Consumption ............................................................................... 179
14.3
Importing and Exporting Metadata ............................................................. 179
15 Troubleshooting ...................................................................................................... 179
15.1
Tracing ........................................................................................................ 179
15.1.1 Diagnostic Tracing in Web Applications .................................................. 179
15.1.2 Diagnostic Tracing in Non-Web Applications ......................................... 181
15.2
Troubleshooting XML Signatures .............................................................. 182
15.2.1 VerifySAML ............................................................................................. 182
15.2.2 VerifySAML Log File .............................................................................. 182
15.2.3 Java VerifyXMLSignature ........................................................................ 183
15.2.4 XML Signatures and Prefixes ................................................................... 183
15.3
Troubleshooting Loading Certificates ........................................................ 184
15.3.1 Certificates Stored in Files ........................................................................ 184
15.3.2 Certificates Stored in the Windows Certificate Store ............................... 187
16 Generating and Verifying Signatures ...................................................................... 188
16.1
Signature Generation .................................................................................. 188
16.2
Signature Verification ................................................................................. 189
16.3
SHA-256 Support........................................................................................ 190
16.3.1 .NET 4.5 Framework Support ................................................................... 190
16.3.2 CLR Security Update ................................................................................ 190
17 Extracting SAML Assertions from SAML Responses ........................................... 192
17.1
Extracting a SAML Assertion ..................................................................... 193
17.2
Extracting a Signed SAML Assertion......................................................... 193
17.3
Extracting an Encrypted Assertion ............................................................. 193
18 Encrypted Assertions .............................................................................................. 193
19 Extracting Statements from SAML Assertions....................................................... 194
20 Extracting SAML Attributes ................................................................................... 195
21 Class Library Reference .......................................................................................... 195
22 Class Library Version ............................................................................................. 195
23 Frequently Asked Questions ................................................................................... 197
24 Support .................................................................................................................... 200
vi
1 Introduction
The ComponentSpace SAML v2.0 component is a .NET class library that provides
SAML v2.0 assertions, protocol messages, bindings and profiles functionality.
You can use this functionality to easily enable your ASP.NET applications to participate
in SAML v2.0 federated single sign-on (SSO) either as an Identity Provider (IdP) or
Service Provider (SP). Samples applications with full source code are included.
If youre looking for SAML v1.1 support, please refer to the separate ComponentSpace
SAML v1.1 component.
1.1 Features
The class library supports the SAML v2.0 Assertions, Protocol, Bindings and Profiles as
defined by the OASIS standard (www.oasis-open.org) including:
SAML 2.0 assertions and all protocol messages
SAML 2.0 metadata
All bindings (SOAP, PAOS, HTTP Redirect, HTTP POST, HTTP Artifact and
SAML URI)
Web browser single sign-on profile
Single logout profile
Artifact resolution profile
Identity provider discovery profile
Authentication, attribute, assertion query profiles
Name identifier management and mapping profiles
Generation and verification of XML signatures
XML encryption
The library features classes for:
Creating, modifying and accessing SAML assertions and protocol messages
Sending and receiving SAML protocol messages across the various SAML
bindings.
Supporting the SAML profiles
1.2 Benefits
Easy to use class library enabling single sign-on support to be quickly added to
your ASP.NET applications
Developer based licensing with no runtime royalties meaning you dont pay per
deployment or end user
Developed in C# with full source code available for purchase
Includes class library reference and example applications with full source code
1.3 Prerequisites
The class library requires the .NET v2.0 framework or above and is for use with Visual
Studio 2005 or above.
The class library has been tested with .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0 and
.NET4.5 using Visual Studio 2005, 2008, 2010, 2012 and 2013.
It has been tested on 32-bit and 64-bit Windows Server 2003, 2008, and 2012, as well as
Windows 7 and 8.
2 Getting Started
1. If you haven't already done so, install this product by double clicking the
Microsoft Installer (MSI) file and following the installation steps.
A free evaluation copy is available from our web site.
2. If youre not familiar with SAML single sign-on, refer to section 3 for a brief
introduction to SAML.
3. See section 5 for assistance in determining the most applicable example project to
review.
4. Compile and run the example applications (see section 9).
5. See section 12 for assistance in enabling single sign-on in your own applications.
Please feel free to contact us if you need any assistance (see section 24).
In IdP-initiated SSO, the user starts at the IdP site, logs in and clicks a link to the SP site
which initiates SSO.
The following diagram outlines the IdP-initiated SSO flow.
Browser
Identity Provider
Service Provider
Browser
Service Provider
Identity Provider
1. Browse to SP site
Browser
Identity Provider
Service Provider
1.
2.
3.
4.
5.
6.
Note that steps 4 through 6 are repeated for each service provider.
Browser
Service Provider
Identity Provider
1. Browse to SP site
1.
2.
3.
4.
5.
6.
Note that the identity provider sends a logout request and expects a logout response from
every other service provider apart from the initiating service provider. This occurs
between steps 5 and 6.
A signer signs with their private key and the verifier verifies with the signers public key.
For example, the IdP signs the SAML response using the IdPs private key. The SP
verifies the SAML response signature using the IdPs public key or certificate.
Note that, in some circumstances, HTTPS transport level security may be considered
sufficient for the protection of any confidential data.
The following is an example of an encrypted SAML assertion.
An encrypter encrypts with the decrypters public key and the decrypter decrypts with
their private key. For example, the IdP encrypts the SAML assertion using the SPs
public key or certificate. The SP decrypts the SAML assertion using the SPs private key.
XML encryption involves the creation of a random symmetric key which is used to
encrypt the data. The symmetric key is then encrypted using the public asymmetric key.
To decrypt, the private asymmetric key is used to decrypt the random symmetric key
which in turn is used to decrypt the data. A symmetric key is used for performance
reasons.
Once the reference has been added you can refer to the various SAML v2.0 classes from
within your project.
4.2 Distribution
The class library's runtime is royalty free which means it may be freely distributed with
your application. The only file that should be distributed is the class library DLL.
5.1.1 SAMLIdentityProvider.InitiateSSO
The InitiateSSO method sends a SAML response to the specified service provider as part
of IdP-initiated SSO.
For example:
SAMLIdentityProvider.InitiateSSO(
Response,
testuser,
new Dictionary<string, string>() {
{ membership-level, platinum },
{ membership-number, 12345678 } },
null,
null);
The Response is used to send the SAML response to the service provider via the browser.
The second parameter is the name of the user.
The third parameter is the users optional attribute names and values.
The fourth parameter is the target service provider URL or null if the default page should
be displayed.
The fifth parameter is the partner service providers name or null if theres only one
configured partner service provider.
5.1.2 SAMLIdentityProvider.ReceiveSSO
The ReceiveSSO method receives an authn request from a service provider as part of SPinitiated SSO.
For example:
SAMLIdentityProvider.ReceiveSSO(
Request,
out partnerSP);
5.1.3 SAMLIdentityProvider.SendSSO
The SendSSO method sends a SAML response to the service provider as part of SPinitiated SSO.
For example:
SAMLIdentityProvider.SendSSO(
Response,
testuser,
new Dictionary<string, string>() {
{ membership-level, platinum },
{ membership-number, 12345678 } });
The Response is used to send the SAML response to the service provider via the browser.
The second parameter is the name of the user.
The third parameter is the users optional attribute names and values.
5.1.4 SAMLIdentityProvider.InitiateSLO
The InitiateSLO method sends a logout request to each service provider in session as part
of IdP-initiated SLO.
For example:
SAMLIdentityProvider.InitiateSLO(
Response,
null);
The Response is used to send the logout request to the service provider via the browser.
The second parameter is the logout reason or null if none.
5.1.5 SAMLIdentityProvider.ReceiveSLO
The ReceiveSLO method receives a logout request from a service provider as part of SPinitiated SLO or a logout response from a service provider as part of IdP-initiated SLO.
10
For example:
SAMLIdentityProvider.ReceiveSLO(
Request,
Response,
out isRequest,
out hasCompleted,
out logoutReason,
out partnerSP);
5.1.6 SAMLIdentityProvider.SendSLO
The SendSLO method sends a logout message to the service provider.
For example:
SAMLIdentityProvider.SendSLO(
Response,
null);
The Response is used to send the logout message to the service provider via the browser.
The second parameter is the error message or null if none.
5.2.1 SAMLServiceProvider.InitiateSSO
The InitiateSSO method sends an authn request to the specified identity provider as part
of SP-initiated SSO.
For example:
SAMLServiceProvider.InitiateSSO(
Response,
null,
null);
11
The Response object is used to send the authn request to the identity provider via the
browser.
The second parameter is the relay state (e.g. target URL) or null if not required.
The third parameter is the partner identity providers name or null if theres only one
configured partner identity provider.
5.2.2 SAMLServiceProvider.ReceiveSSO
The ReceiveSSO method receives a SAML response from an identity provider as part of
either IdP-initiated SSO or SP-initiated SSO.
For example:
SAMLServiceProvider.ReceiveSSO(
Request,
out isInResponseTo,
out partnerIdP,
out userName,
out attributes,
out targetUrl);
5.2.3 SAMLServiceProvider.InitiateSLO
The InitiateSLO method sends a logout request to the identity provider as part of SPinitiated SLO.
For example:
SAMLServiceProvider.InitiateSLO(
Response,
null,
null);
The Response is used to send the logout request to the service provider via the browser.
The second parameter is the logout reason or null if none.
The third parameter is the partner identity providers name or null if theres only one
configured partner identity provider.
12
5.2.4 SAMLServiceProvider.ReceiveSLO
The ReceiveSLO method receives a logout request from a service provider as part of SPinitiated SLO or a logout response from a service provider as part of IdP-initiated SLO.
For example:
SAMLServiceProvider.ReceiveSLO(
Request,
out isRequest,
out logoutReason,
out partnerIdP);
5.2.5 SAMLServiceProvider.SendSLO
The SendSLO method sends a logout message to the identity provider.
For example:
SAMLServiceProvider.SendSLO(
Response,
null);
The Response is used to send the logout message to the identity provider via the browser.
The second parameter is the error message or null if none.
13
5.4.1 CertificateManager
A default implementation, CertificateManager, is included which supports X.509
certificates specified by configuration.
The following code assume a CustomCertificateManager class has been implemented and
configures this as the certificate manager.
14
5.5.1 InMemoryIDCache
A default implementation, InMemoryIDCache, is included.
The InMemoryIDCache stores identifiers in an in-memory cache which is suitable in a
single server configuration but is not suitable in a web farm.
5.5.2 DatabaseIDCache
In a web farm, an IIDCache implementation backed by a database, for example, is
required.
The DatabaseIDCache stores identifiers in a database table which is suitable in a web
farm.
The following code configures the database ID cache.
SAMLConfiguration.IDCache = new DatabaseIDCache();
The IDCache property should be set before any other SAML API calls (eg in the
applications Global.asax).
The ID cache is stored in a single table, SAMLIdentifiers, with the following schema.
The ID column is the SAML identifier e.g. the SAML assertion ID. The
ExpirationDateTime is the UTC date/time when the SAML identifier expires.
The following SQL script creates the SAMLIdentifiers table in a SQL Server 2014
database.
USE [SAML]
GO
DROP TABLE [dbo].[SAMLIdentifiers]
GO
SET ANSI_NULLS ON
15
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SAMLIdentifiers](
[ID] [nvarchar](256) NOT NULL,
[ExpirationDateTime] [datetime] NOT NULL,
CONSTRAINT [PK_SAMLIdentifiers] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
16
The following code assume a CustomIDCache class has been implemented and
configures this as the ID cache.
SAMLConfiguration.IDCache = new CustomIDCache();
5.6.1 HttpSSOSessionStore
A default implementation, HttpSSOSessionStore, is included.
The HttpSSOSessionStore stores SSO session state information as part of the ASP.NET
HTTP session state.
The HttpSSOSessionStore is suitable in a single server configuration using the ASP.NET
InProc session mode or in a web farm using the StateServer, SQLServer or equivalent
Custom mode.
5.6.2 DatabaseSSOSessionStore
In a web farm, an ISSOSessionStore implementation backed by a database, for example,
is required.
The DatabaseSSOSessionStore stores SSO session data in a database table which is
suitable in a web farm.
The following code configures the database SSO session store.
SAMLConfiguration.SSOSessionStore = new DatabaseSSOSessionStore();
The SSOSessionStore property should be set before any other SAML API calls (eg in the
applications Global.asax).
The SSO session data is stored in a single table, SSOSessions, with the following
schema.
The SessionID column is the unique identifier for the SSO session data. The
UpdateDateTime is the UTC date/time when the SSO session data was last updated. The
SessionObject is the opaque session data stored as a byte array.
The following SQL script creates the SAMLIdentifiers table in a SQL Server 2014
database.
17
USE [SAML]
GO
DROP TABLE [dbo].[SSOSessions]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SSOSessions](
[SessionID] [nvarchar](64) NOT NULL,
[UpdateDateTime] [datetime] NOT NULL,
[SessionObject] [varbinary](max) NOT NULL,
CONSTRAINT [PK_SSOSessions] PRIMARY KEY CLUSTERED
(
[SessionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
18
19
type="saml:PartnerServiceProviderType" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
<attribute name="ReloadOnConfigurationChange" type="boolean"
default="true"/>
<attribute name="TraceLevel" type="saml:TraceLevelType"/>
</complexType>
<!-- Identity Provider -->
<complexType name="IdentityProviderType">
<complexContent>
<extension base="saml:LocalProviderType"/>
</complexContent>
</complexType>
<!-- Service Provider -->
<complexType name="ServiceProviderType">
<complexContent>
<extension base="saml:LocalProviderType">
<attribute name="AssertionConsumerServiceUrl" type="string"
use="required"/>
</extension>
</complexContent>
</complexType>
<!-- Partner Identity Provider -->
<complexType name="PartnerIdentityProviderType">
<complexContent>
<extension base="saml:PartnerProviderType">
<attribute name="SingleSignOnServiceUrl" type="string"
use="required"/>
<attribute name="SingleSignOnServiceBinding"
type="saml:SAMLBindingType"
default="urn:oasis:names:tc:SAML:2.0:bindings:HTTPRedirect"/>
<attribute name="SignAuthnRequest" type="boolean"
default="false"/>
<attribute name="ForceAuthn" type="boolean"
default="false"/>
<attribute name="WantResponseSigned" type="boolean"
default="false"/>
<attribute name="WantAssertionSigned" type="boolean"
default="false"/>
<attribute name="WantAssertionEncrypted" type="boolean"
default="false"/>
<attribute name="DisableAudienceRestrictionCheck"
type="boolean" default="false"/>
<attribute name="OverridePendingAuthnRequest"
type="boolean" default="false"/>
<attribute name="RequestedAuthnContext" type="string"/>
<attribute name="ProviderName" type="string"/>
</extension>
</complexContent>
</complexType>
<!-- Partner Service Provider -->
<complexType name="PartnerServiceProviderType">
20
<complexContent>
<extension base="saml:PartnerProviderType">
<attribute name="AssertionConsumerServiceUrl" type="string"/>
<attribute name="WantAuthnRequestSigned" type="boolean"
default="false"/>
<attribute name="SignSAMLResponse" type="boolean"
default="false"/>
<attribute name="SignAssertion" type="boolean"
default="false"/>
<attribute name="EncryptAssertion" type="boolean"
default="false"/>
<attribute name="AssertionLifeTime" type="string"
default="00:03:00"/>
<attribute name="AuthnContext" type="string"
default="urn:oasis:names:tc:saml:2.0:ac:classes:unspecified"/>
</extension>
</complexContent>
</complexType>
<!-- Local and partner provider types -->
<complexType name="LocalProviderType" abstract="true">
<complexContent>
<extension base="saml:ProviderType"/>
</complexContent>
</complexType>
<complexType name="PartnerProviderType" abstract="true">
<complexContent>
<extension base="saml:ProviderType">
<attribute name="PartnerCertificateFile" type="string"/>
<attribute name="PartnerCertificateSerialNumber"
type="string"/>
<attribute name="PartnerCertificateThumbprint" type="string"/>
<attribute name="PartnerCertificateSubject" type="string"/>
<attribute name="SingleLogoutServiceUrl" type="string"/>
<attribute name="SingleLogoutServiceResponseUrl"
type="string"/>
<attribute name="SingleLogoutServiceBinding"
type="saml:SAMLBindingType"
default="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"/>
<attribute name="LogoutRequestLifeTime" type="string"
default="00:03:00"/>
<attribute name="DisableInboundLogout" type="boolean"
default="false"/>
<attribute name="DisableOutboundLogout" type="boolean"
default="false"/>
<attribute name="DisableInResponseToCheck" type="boolean"
default="false"/>
<attribute name="SignLogoutRequest" type="boolean"
default="false"/>
<attribute name="SignLogoutResponse" type="boolean"
default="false"/>
<attribute name="WantLogoutRequestSigned" type="boolean"
default="false"/>
<attribute name="WantLogoutResponseSigned" type="boolean"
default="false"/>
<attribute name="UseEmbeddedCertificate" type="boolean"
21
default="false"/>
<attribute name="NameIDFormat" type="string"
default="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"/>
<attribute name="DigestMethod"
type="saml:DigestMethodType"
default="http://www.w3.org/2000/09/xmldsig#sha1"/>
<attribute name="SignatureMethod"
type="saml:SignatureMethodType"
default="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<attribute name="KeyEncryptionMethod"
type="saml:KeyEncryptionMethodType"
default="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<attribute name="DataEncryptionMethod"
type="saml:DataEncryptionMethodType"
default="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
<attribute name="ClockSkew" type="string" default="00:00:00"/>
</extension>
</complexContent>
<complexType name="ProviderType" abstract="true">
<attribute name="Name" type="string" use="required"/>
<attribute name="LocalCertificateFile" type="string"/>
<attribute name="LocalCertificatePassword" type="string"/>
<attribute name="LocalCertificatePasswordKey" type="string"/>
<attribute name="LocalCertificateSerialNumber" type="string"/>
<attribute name="LocalCertificateThumbprint" type="string"/>
<attribute name="LocalCertificateSubject" type="string"/>
</complexType>
<!-- Bindings -->
<simpleType name="SAMLBindingType">
<restriction base="string">
<enumeration value="urn:oasis:names:tc:SAML:2.0:bindings:HTTPPOST"/>
<enumeration value="urn:oasis:names:tc:SAML:2.0:bindings:HTTPRedirect"/>
</restriction>
</simpleType>
<!-- Security -->
<simpleType name="KeyEncryptionMethodType">
<restriction base="string">
<enumeration value="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<enumeration value="http://www.w3.org/2001/04/xmlenc#rsa-oaepmgf1p"/>
</restriction>
</simpleType>
<simpleType name="DataEncryptionMethodType">
<restriction base="string">
<enumeration value="http://www.w3.org/2001/04/xmlenc#tripledescbc"/>
<enumeration value="http://www.w3.org/2001/04/xmlenc#aes128cbc"/>
<enumeration value="http://www.w3.org/2001/04/xmlenc#aes192cbc"/>
22
<enumeration value="http://www.w3.org/2001/04/xmlenc#aes256cbc"/>
</restriction>
</simpleType>
<simpleType name="DigestMethodType">
<restriction base="string">
<enumeration value="http://www.w3.org/2000/09/xmldsig#sha1"/>
<enumeration value="http://www.w3.org/2001/04/xmlenc#sha256"/>
</restriction>
</simpleType>
<simpleType name="SignatureMethodType">
<restriction base="string">
<enumeration value="http://www.w3.org/2000/09/xmldsig#rsasha1"/>
<enumeration value="http://www.w3.org/2001/04/xmldsig-more#rsasha256"/>
</restriction>
</simpleType>
<!-- Trace -->
<simpleType name="TraceLevelType">
<restriction base="string">
<enumeration value="Off"/>
<enumeration value="Verbose"/>
</restriction>
</simpleType>
</schema>
Figure 7 Saml.config XML Schema
TraceLevel
The optional TraceLevel attribute specifies the trace level for logging.
Tracing configuration is specified in the applications web.config. Refer to section
15.1 for more details. The trace switch value in the <system.diagnostics> section
specifies whether verbose trace is enabled or not.
The trace switch may be overridden by specifying a trace level. For example, if the
trace switch value in <system.diagnostics> is Off, the trace level may be set to
Verbose to enable trace without modifying web.config.
In most scenarios, its preferable to modify the trace switch value in
<system.diagnostics>.
By default, the trace level is not specified and therefore the trace switch value in
<system.diagnostics> applies.
24
WantAssertionSigned
The optional WantAssertionSigned attribute specifies whether the SAML assertion
from the partner identity provider should be signed. The default is false.
WantAssertionEncrypted
The optional WantAssertionEncrypted attribute specifies whether the SAML
assertion from the partner identity provider should be encrypted. The default is
false.
DisableAudienceRestrictionCheck
The optional DisableAudienceRestrictionCheck attribute specifies whether the
audience restriction condition in the SAML assertion should be checked. This
attribute should only be set to true to work around limitations in the partner identity
provider. The default is false.
OverridePendingAuthnRequest
The optional OverridePendingAuthnRequest attribute specifies whether a pending
authentication request may be overridden and an IdP-initiated SAML response
received. Setting this flag to true supports an SP-initiated SSO flow being
supplanted by an IdP-initiated SSO. The default is false.
RequestedAuthnContext
The optional RequestedAuthnContext attribute specifies the requested
authentication context to include in authentication requests sent to the partner
identity provider. The default is none.
ProviderName
The optional ProviderName attribute specifies the provider name to include in
authentication requests sent to the partner identity provider. The default is none.
25
SignSAMLResponse
The optional SignSAMLResponse attribute specifies whether SAML responses
sent to the partner service provider should be signed. The default is false.
SignAssertion
The optional SignAssertion attribute specifies whether SAML assertions sent to the
partner service provider should be signed. The default is false.
EncryptAssertion
The optional EncryptAssertion attribute specifies whether SAML assertions sent to
the partner service provider should be encrypted. The default is false.
AssertionLifeTime
The optional AssertionLifeTime attribute specifies the NotBefore/NotOnOrAfter
time interval for the SAML assertion. The format is hh:mm:ss. The default is 3
minutes.
AuthnContext
The optional AuthnContext attribute specifies the authentication context to include
in SAML assertions sent to the partner service provider. The default is
urn:oasis:names:tc:saml:2.0:ac:classes:unspecified.
26
SingleLogoutServiceResponseUrl
The SingleLogoutServiceResponseUrl attribute specifies the partner providers
single logout (SLO) service response URL. Logout responses will be sent to the
SLO response service. If not specified then logout responses are sent to the same
URL as logout requests.
SingleLogoutServiceBinding
The optional SingleLogoutServiceBinding attribute specifies the transport binding
to use when sending logout messages to the partner providers SLO service. The
default is to use the HTTP-Redirect binding.
LogoutRequestLifeTime
The optional LogoutRequestLifeTime attribute specifies the NotOnOrAfter time
interval for the logout request. The format is hh:mm:ss. The default is 3 minutes.
DisableInboundLogout
The optional DisableInboundLogout attribute specifies whether logout requests
sent by the partner provider are not supported. The default is false.
DisableOutboundLogout
The optional DisableOutboundLogout attribute specifies whether logout requests
sent to the partner provider are not supported. The default is false.
DisableInResponseToCheck
The optional DisableInResponseToCheck attribute specifies whether the SAML
messages InResponseTo should be checked. This attribute should only be set to
true to work around limitations in the partner provider. The default is false.
SignLogoutRequest
The optional SignLogoutRequest attribute specifies whether logout requests sent to
the partner provider should be signed. The default is false.
SignLogoutResponse
The optional SignLogoutResponse attribute specifies whether logout responses sent
to the partner provider should be signed. The default is false.
WantLogoutRequestSigned
The optional WantLogoutRequestSigned attribute specifies whether the logout
request from the partner provider should be signed. The default is false.
WantLogoutResponseSigned
The optional WantLogoutResponseSigned attribute specifies whether the logout
response from the partner provider should be signed. The default is false.
UseEmbeddedCertificate
The optional UseEmbeddedCertificate attribute specifies whether the certificate
embedded in the XML signature should be used when verifying the signature. If
27
false then a configured certificate retrieved from the certificate manager is used.
The default is false.
NameIDFormat
The optional NameIDFormat attribute specifies the name identifier format to
include in SAML assertions sent to the partner service provider or in authn requests
sent to the partner identity provider. The default is
urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified.
DigestMethod
The optional DigestMethod attribute specifies the XML signature digest method.
The default is http://www.w3.org/2000/09/xmldsig#sha1.
SignatureMethod
The optional SignatureMethod attribute specifies the XML signature method. The
default is "http://www.w3.org/2000/09/xmldsig#rsa-sha1.
KeyEncryptionMethod
The optional KeyEncryptionMethod attribute specifies the XML encryption key
encryption method. The default is http://www.w3.org/2001/04/xmlenc#rsa-1_5.
DataEncryptionMethod
The optional DataEncryptionMethod attribute specifies the XML encryption data
encryption method. The default is http://www.w3.org/2001/04/xmlenc#aes128-cbc.
ClockSkew
The optional ClockSkew attribute specifies the time span to allow for differences
between local and partner computer clocks when checking time intervals. The
default is no clock skew.
28
The certificate password must be kept secure. In a test environment using a test
certificate, specifying the password using the LocalCertificatePassword attribute is
acceptable.
For a production certificate, the password should be stored encrypted in
web.config. Refer to the LocalCertificatePasswordKey attribute for more details.
LocalCertificatePasswordKey
The optional LocalCertificatePasswordKey attribute specifies the web.configs
appSettings key for the certificate file password.
For example, if the LocalCertificatePasswordKey attribute value is
localCertificatePassword, then under the web.configs appSettings section, an entry
with the key name localCertificatePassword is expected and the entry value is used
as the password.
By encrypting the appSettings section using the aspnet_regiis utility, the certificate
file password is secured.
LocalCertificateSerialNumber
The optional LocalCertificateSerialNumber attribute specifies the X.509 certificate
by serial number for this provider. The certificate is retrieved from the local
computers X.509 certificate store.
LocalCertificateThumbprint
The optional LocalCertificateThumbprint attribute specifies the X.509 certificate
by thumbprint for this provider. The certificate is retrieved from the local
computers X.509 certificate store.
LocalCertificateSubject
The optional LocalCertificateSubject attribute specifies the X.509 certificate by
subject name for this provider. The certificate is retrieved from the local
computers X.509 certificate store.
29
And the following code configures the local identity provider and one partner service
provider.
SAMLConfiguration samlConfiguration = new SAMLConfiguration();
samlConfiguration.LocalIdentityProviderConfiguration =
new LocalIdentityProviderConfiguration() {
Name = "urn:componentspace:ExampleIdentityProvider",
LocalCertificateFile = "idp.pfx",
LocalCertificatePassword = "password"
};
samlConfiguration.AddPartnerServiceProvider(
new PartnerServiceProviderConfiguration() {
Name = "urn:componentspace:ExampleServiceProvider",
WantAuthnRequestSigned = false,
SignSAMLResponse = true,
SignAssertion = false,
EncryptAssertion = false,
AssertionConsumerServiceUrl =
"http://localhost/ExampleServiceProvider/SAML/AssertionConsumerService.
aspx",
SingleLogoutServiceUrl =
"http://localhost/ExampleServiceProvider/SAML/SLOService.aspx",
PartnerCertificateFile = "sp.cer"
});
SAMLConfiguration.Current = samlConfiguration;
30
The certificate file path is not an absolute path and therefore is assumed to be relative to
the applications folder.
The following configuration entry specifies an absolute file path.
<IdentityProvider Name="ExampleIdentityProvider"
LocalCertificateFile="C:\\Certificates\\idp.pfx"
LocalCertificatePassword="password"/>
The certificate file path is not an absolute path and therefore is assumed to be relative to
the applications folder.
No password is required with a partner certificate file as the file does not contain the
private key.
The following configuration entry specifies an absolute file path.
<PartnerServiceProvider Name=" ExampleServiceProvider"
PartnerCertificateFile=
"C:\\Certificates\\sp.cer"/>
The following configuration entry specifies the local providers certificate is contained in
the file idp.pfx which is protected by an encrypted password.
<IdentityProvider Name="ExampleIdentityProvider"
LocalCertificateFile="idp.pfx"
LocalCertificatePasswordKey=
"certificateFilePassword"/>
The applications web.config appSettings section must include the certificate password
key.
<appSettings>
<add key="certificateFilePassword" value="password"/>
</appSettings>
The IIS account under which the application runs must be granted permission to decrypt
web.config.
aspnet_regiis -pa NetFrameworkConfigurationKey "IIS_IUSRS"
32
2. From the menu, click Action > All Tasks > Import
33
34
4. Supply the password and optionally check the check box to mark the key as
exportable.
35
36
37
38
39
40
41
42
2. Add permissions for the application account. For example, give the IIS_IUSRS
group read permission. The user or group to permit is dependent on the version of
IIS and its configuration.
43
2. From the menu, click Action > All Tasks > Import
44
45
46
47
48
49
50
51
The following configuration entry specifies the local providers certificate is contained in
the Windows certificate store and is identified by the certificates thumbprint.
Thumbprints optionally may include separating space characters for readability.
52
If copying/pasting from the Windows certificate store, invisible Unicode characters may
be included. Its best to first paste to Notepad etc. to avoid these issues.
<IdentityProvider Name="ExampleIdentityProvider"
LocalCertificateThumbprint=
"371629967909a351de5017d6a3a51c6c15f3505c"/>
The following configuration entry specifies the local providers certificate is contained in
the Windows certificate store and is identified by the certificate subjects distinguished
name.
<IdentityProvider Name="ExampleIdentityProvider"
LocalCertificateSubject="CN=www.idp.com"/>
Alternatively, some subset of the subjects distinguished name that uniquely identifies the
certificate may be used.
<IdentityProvider Name="ExampleIdentityProvider"
LocalCertificateSubject="www.idp.com"/>
The following configuration entry specifies the partner providers certificate is contained
in the Windows certificate store and is identified by the certificates thumbprint.
<PartnerServiceProvider Name="ExampleServiceProvider"
PartnerCertificateThumbprint=
"2d7b862dcbb6103207cdd75138c04ad2f1fb844c"/>
The following configuration entry specifies the partner providers certificate is contained
in the Windows certificate store and is identified by the certificate subjects distinguished
name.
<PartnerServiceProvider Name="ExampleServiceProvider"
PartnerCertificateSubject="CN=www.sp.com"/>
Alternatively, some subset of the subjects distinguished name that uniquely identifies the
certificate may be used.
<PartnerServiceProvider Name="ExampleServiceProvider"
PartnerCertificateSubject="www.sp.com "/>
53
Web Forms
IdP
ExampleIdentityProvider project.
IdP
MVCExampleIdentityProvider
project.
SP
ExampleServiceProvider
project.
MVC
Is my site the Identity
Provider or Service
Provider?
SP
MVCExampleServiceProvider
project.
whether your site is the identity provider or service provider. See section 10.1.7 for more
information.
Which example
project is right for
me?
Connecting to a specific
provider?
Yes
No
Google Apps?
No
Salesforce?
No
ADFS?
Yes
Yes
Yes
GoogleIdP project.
SalesforceIdP project.
ADFSSP project.
No
Shibboleth?
No
IdP-initiated SSO
IdP
SAML2IdP project.
SP
SAML2SP project.
SP-initiated SSO
Yes
IdP
ShibbolethIdP project.
SP
ShibbolethSP project.
If youre connecting to a specific provider such as Google Apps etc then refer to the
corresponding example project. If the provider is not listed then use one of the generic
projects or contact us for assistance.
55
10.1.1
10.1.2
57
10.1.3
10.1.4
58
10.1.5
In this example, the user starts at the identity provider site and is attempting to access a
protected resource on the service provider. Rather than performing a local login at the
service provider, SSO is initiated with a local login occurring at the identity provider and
the asserted identity, passed to the service provider in a SAML assertion, is used to
perform an automatic login at the service provider.
1. Browse to http://localhost/ExampleIdentityProvider.
2. You should be presented with the form shown in Figure 12.
If you are not then you must already have logged in at the identity provider. To
force a login, close the browser and start again.
3. Login using the user name idp-user and a password of password.
4. You should then be presented with the identity providers default page (see Figure
13).
5. Click the link to single sign-on to the service provider.
6. You should then be presented with the service providers default page (see Figure
14).
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
59
10.1.6
In this example, the user starts at the service provider site and is attempting to access a
protected resource on the service provider. Rather than performing a local login at the
service provider, SSO is initiated with a local login occurring at the identity provider and
the asserted identity, passed to the service provider in a SAML assertion, is used to
perform an automatic login at the service provider.
1. Browse to http://localhost/ExampleServiceProvider.
2. You should then be presented with the service providers login page.
3. Click the link to single sign-on to the identity provider.
4. You should be presented with the form shown in Figure 15.
If you are not then you must already have logged in at the identity provider. To
force a login, close the browser and start again.
5. Login using the user name idp-user and a password of password.
60
6. You should then be presented with the service providers default page (see Figure
16).
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
10.1.7
The following section follows the flow of IdP-initiated SSO between the
ExampleIdentityProvider and ExampleServiceProvider.
1. The user clicks the link on the ExampleIdentityProviders Default.aspx page and
the SAMLIdentityProvider.InitiateSSO method is called to initiate SSO.
2. A SAML response containing a SAML assertion is constructed and sent to the
service providers assertion consumer service URL.
61
10.1.8
The following section follows the flow of SP-initiated SSO between the
ExampleIdentityProvider and ExampleServiceProvider.
1. The user browses to the ExampleServiceProviders Default.aspx page and the
SAMLServiceProvider.InitiateSSO method is called to initiate SSO.
2. An authentication request is constructed and sent to the identity providers SSO
service URL.
3. The ExampleIdentityProviders SAML/SSOService.aspx page calls the
SAMLIdentityProvider.ReceiveSSO method to receive and process the
authentication request.
4. The user is prompted to login at the ExampleIdentityProvider if not already
logged in.
5. The ExampleIdentityProviders SAML/SSOService.aspx page calls the
SAMLIdentityProvider.SendSSO method.
6. A SAML response containing a SAML assertion is constructed and sent to the
service providers assertion consumer service URL.
7. The ExampleServiceProviders SAML/AssertionConsumerService.aspx page
calls the SAMLServiceProvider.ReceiveSSO method to receive and process the
SAML response.
8. The user is logged in automatically at the ExampleServiceProvider.
10.2.1
62
10.2.2
63
10.2.3
10.2.4
64
10.2.5
In this example, the user starts at the identity provider site and is attempting to access a
protected resource on the service provider. Rather than performing a local login at the
service provider, SSO is initiated with a local login occurring at the identity provider and
the asserted identity, passed to the service provider in a SAML assertion, is used to
perform an automatic login at the service provider.
1. Browse to http://localhost/MvcExampleIdentityProvider.
2. You should be presented with the form shown in Figure 19.
If you are not then you must already have logged in at the identity provider. To
force a login, close the browser and start again.
3. Login using the user name idp-user and a password of password.
4. You should then be presented with the identity providers default page (see Figure
20).
5. Click the link to single sign-on to the service provider.
6. You should then be presented with the service providers default page (see Figure
21).
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
65
10.2.6
In this example, the user starts at the service provider site and is attempting to access a
protected resource on the service provider. Rather than performing a local login at the
service provider, SSO is initiated with a local login occurring at the identity provider and
the asserted identity, passed to the service provider in a SAML assertion, is used to
perform an automatic login at the service provider.
1. Browse to http://localhost/MvcExampleServiceProvider.
2. You should then be presented with the service providers login.
3. Click the link to single sign-on to the identity provider.
4. You should be presented with the form shown in Figure 22.
If you are not then you must already have logged in at the identity provider. To
force a login, close the browser and start again.
5. Login using the user name idp-user and a password of password.
66
6. You should then be presented with the service providers default page (see Figure
23).
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
10.2.7
The following section follows the flow of IdP-initiated SSO between the
MvcExampleIdentityProvider and MvcExampleServiceProvider.
1. The user clicks the link on the MvcExampleIdentityProviders home page and the
HomeController calls the SAMLIdentityProvider.InitiateSSO method to initiate
SSO.
2. A SAML response containing a SAML assertion is constructed and sent to the
service providers assertion consumer service URL.
67
10.2.8
The following section follows the flow of SP-initiated SSO between the
MvcExampleIdentityProvider and MvcExampleServiceProvider.
1. The user browses to the MvcExampleServiceProviders home page and the
AccountController calls the SAMLServiceProvider.InitiateSSO method to initiate
SSO.
2. An authentication request is constructed and sent to the identity providers SSO
service URL.
3. The MvcExampleIdentityProviders SAMLController calls the
SAMLIdentityProvider.ReceiveSSO method to receive and process the
authentication request.
4. The user is prompted to login at the MvcExampleIdentityProvider if not already
logged in.
5. The MvcExampleIdentityProviders SAMLController calls the
SAMLIdentityProvider.SendSSO method.
6. A SAML response containing a SAML assertion is constructed and sent to the
service providers assertion consumer service URL.
7. The MvcExampleServiceProviders SAMLController calls the
SAMLServiceProvider.ReceiveSSO method to receive and process the SAML
response.
8. The user is logged in automatically at the MvcExampleServiceProvider.
10.3.1
Miscellaneous Configuration
For the purposes of these examples, the host name of the ComponentSpace example
applications is cs.test and the host name of the ADFS server is adfs.test.
68
If using these host names, update the Windows\System32\drivers\etc\hosts file on the test
and ADFS servers to include entries for cs.test and adfs.test. For example:
192.168.1.20
192.168.1.21
10.3.2
cs.test
adfs.test
The following sections describe interoperability between the example service provider
and ADFS acting as the claims provider (i.e. identity provider).
The saml.config file includes the following entry for the ADFS partner identity provider.
<PartnerIdentityProvider Name="http://adfs.test/adfs/services/trust"
SignAuthnRequest="true"
WantResponseSigned="false"
WantAssertionSigned="true"
WantAssertionEncrypted="true"
UseEmbeddedCertificate="true"
SingleSignOnServiceUrl=
"https://adfs.test/adfs/ls/"/>
The name must match with the issuer name ADFS uses in the returned SAML response.
For example, if ADFS is deployed to the myadfs server then the name must be
http://myadfs/adfs/services/trust.
The ADFS federation services properties lists the federation service identifier.
69
The UseEmbeddedCertificate flag is set to simplify the configuration. If not set then the
ADFS signature certificate needs to be imported to the service provider and configured in
the SAML configuration certificate manager.
The web.configs PartnerIdP setting specifies the partner identity provider for SPinitiated SSO and should be set to http://www.idp.com/adfs/services/trust.
<add key="PartnerIdP" value="http://adfs.test/adfs/services/trust"/>
10.3.3
In the ADFS terminology, the service provider is a relying party. Using the ADFS
management console, add a relying party trust for the service provider.
Note that strings in ADFS, including URLs, are case sensitive.
Confirm that the /adfs/ls endpoint for SAML v2.0 exists. If it doesnt, refer to the ADFS
documentation.
70
Confirm that the service communications, token decrypting and token encrypting
certificates exist. If they dont, refer to the ADFS documentation.
Add a relying party trust and select the option to enter the relying party information
manually.
71
Specify a display name. The display name does not have to match with any other
configuration.
72
73
Browse to sp.cer to specify it as the token encryption certificate. Ignore any warnings
about the key length.
The token encryption certificate is used to encrypt the SAML assertion. The service
provider decrypts the SAML assertion using the associated private key.
74
Enable support for SAML v2.0 and specify the service providers assertion consumer
service URL. ADFS sends the SAML response to this URL. For example:
https://cs.test/ExampleServiceProvider/SAML/AssertionConsumerService.aspx
75
Specify the relying party trust identifier. This identifier must match the issuer field in the
authn request sent by the service provider. The ServiceProvider name attribute in the
saml.config configuration file is used as the issuer and so this name and the relying party
trust identifier must match.
For example, if the saml.config includes:
<ServiceProvider Name="urn:componentspace:ExampleServiceProvider"
AssertionConsumerServiceUrl=
"~/SAML/AssertionConsumerService.aspx"/>
Then the relying party trust identifier must be:
urn:componentspace:ExampleServiceProvider.
76
77
78
The service provider should be included in the list of relying party trusts.
The authn request sent by the service provider is signed. To specify the certificate to use
to verify the signature, open the relying party trusts properties and, under the Signature
tab, add the service provider certificate.
79
Although the SAML v2.0 component supports SHA-256 signatures, for this example
SHA-1 is used. To specify this, under the Advanced tab, select SHA-1.
80
81
Note that even after logout, ADFS may persist the authentication session depending on
which local authentication type is used. For example, if Integrated authentication is used
then after logout the next login, in the same browser session, uses the persisted
authentication session and the user doesnt have to re-enter their credentials. If Forms
authentication is used then a login is required after logout. The following section from the
adfs/ls web.config shows the Forms authentication taking precedence over the Integrated
authentication.
<localAuthenticationTypes>
<add name="Forms" page="FormsSignIn.aspx" />
<add name="Integrated" page="auth/integrated/" />
<add name="TlsClient" page="auth/sslclient/" />
<add name="Basic" page="auth/basic/" />
</localAuthenticationTypes>
82
Map the Active Directory user principal name to the outgoing Name ID. Map additional
Active Directory attributes to include in the SAML assertion as SAML attributes.
83
84
ADFS should now be ready to communicate with the example service provider.
To review the metadata published by ADFS browse to:
https:/adfs.test/FederationMetadata/2007-06/FederationMetadata.xml
10.3.4
In this example, the user is attempting to access a protected resource on the service
provider and, rather than performing a local login at the service provider, SSO is initiated
with a local login occurring at the ADFS identity provider and the asserted identity,
passed to the service provider in a SAML assertion, is used to perform an automatic login
at the service provider.
1. Browse to https://cs.test/ExampleServiceProvider, ignoring any browser
certificate warnings.
2. If more than one claim provider is configured on ADFS, you will be presented
with the following page. Select the appropriate claim provider for authentication
against Active Directory. For example, adfs.test.
85
3. You should then be presented with the identity provider login prompt.
4. Login using the user name and password of a user defined in Active Directory.
5. You should then be presented with the service providers default page.
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
86
10.3.5
In this example, the user logs in at ADFS and initiates SSO to the service provider. The
asserted identity, passed to the service provider in a SAML assertion, is used to perform
an automatic login at the service provider.
1. Browse to https://adfs.test/adfs/ls/IdpInitiatedSignon.aspx, ignoring any browser
certificate warnings.
2. You should then be presented with the identity provider sign-in page.
3. Select the sign in to this site radio button and click the continue button.
Alternatively, selecting the sign in to one of the following sites radio button
performs SSO to the selected service provider immediately after login.
You should then be presented with the identity provider login prompt.
87
4. Login using the user name and password of a user defined in Active Directory.
5. Select the service provider and click Go to initiate SSO.
6. You should then be presented with the service providers default page.
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
88
10.3.6
The following sections describe interoperability between the example identity provider
and ADFS acting as the relying party (i.e. service provider).
The saml.config file includes the following entry for the ADFS partner service provider.
<PartnerServiceProvider Name="http://adfs.test/adfs/services/trust"
WantAuthnRequestSigned="false"
SignSAMLResponse="false"
SignAssertion="true"
EncryptAssertion="false"
AssertionConsumerServiceUrl=
"https://adfs.test/adfs/ls/"/>
The name must match with the issuer name ADFS uses in the authn request. For
example, if ADFS is deployed to the myadfs server then the name must be
http://myadfs/adfs/services/trust.
The web.configs PartnerSP setting specifies the partner service provider for IdPinitiated SSO and should be set to http://adfs.test/adfs/services/trust.
<add key="PartnerSP" value="http://adfs.test/adfs/services/trust"/>
The web.configs TargetUrl setting specifies, for IdP-initiated SSO, the relying party
configured in ADFS and should be set to RPID=ExampleServiceProvider.
The RPID syntax is specific to ADFS. If not specified then ADFS will convert the IdPinitiated SSO into SP-initiated SSO.
<add key="TargetUrl" value="RPID=ExampleServiceProvider"/>
10.3.7
If not enabled, ADFS will convert IdP-initiated SSO into SP-initiated SSO.
89
In the ADFS terminology, the identity provider is a claims provider. Using the ADFS
management console, add a claims provider trust for the identity provider.
Note that strings in ADFS, including URLs, are case sensitive.
Confirm that the /adfs/ls endpoint for SAML v2.0 exists. If it doesnt, refer to the ADFS
documentation.
Confirm that the service communications, token decrypting and token encrypting
certificates exist. If they dont, refer to the ADFS documentation.
Add a claims provider trust and select the option to enter the claims provider information
manually.
90
Specify a display name. The display name does not have to match with any other
configuration.
91
92
Enable support for SAML v2.0 and specify the identity providers SSO service URL.
ADFS sends the authn request to this URL. For example:
https://cs.test/ExampleIdentityProvider/SAML/SSOService.aspx
93
Specify the claims provider trust identifier. This identifier must match the issuer field in
the authn request sent by the service provider. The IdentityProvider name attribute in the
saml.config configuration file is used as the issuer and so this name and the claims
provider trust identifier must match.
For example, if the saml.config includes:
<IdentityProvider Name="urn:componentspace:ExampleIdentityProvider"/>
Then the claims provider trust identifier must be:
urn:componentspace:ExampleIdentityProvider.
94
Browse to idp.cer to specify it as the token signing certificate. Ignore any warnings about
the key length.
ADFS uses the token signing certificate to verify the SAML assertion signature.
95
96
The identity provider should be included in the list of claims provider trusts.
Although the SAML v2.0 component supports SHA-256 signatures, for this example
SHA-1 is used. To specify this, open the claims provider trusts properties and, under the
Advanced tab, select SHA-1.
97
Edit the claim rules and add a rule. Use the pass through template.
98
Add a rule to pass through the Name ID. Ignore any warning.
99
10.3.8
In this example, the user logs in at the identity provider and initiates SSO to ADFS.
ADFS forwards this to the specified service provider. The asserted identity, passed to the
service provider in a SAML assertion, is used to perform an automatic login at the service
provider.
1. Browse to https://cs.test/ExampleIdentityProvider, ignoring any browser
certificate warnings.
100
3. You should then be presented with the service providers default page.
101
10.3.9
Configuration errors will result in a cryptic message displayed in the browser by ADFS.
To troubleshoot configuration and other problems, refer to the ADFS event log.
10.4.1
The saml.config file includes the following entry for the Office 365 partner service
provider.
102
The web.configs PartnerSP setting specifies the partner service provider for IdPinitiated SSO and should be set to urn:federation:MicrosoftOnline.
<add key="PartnerSP" value="urn:federation:MicrosoftOnline"/>
The web.configs SubjectName setting specifies the subjects name identifier. This must
match with the users immutable identifier configured in Office 365. In this example, a
fixed immutable identifier is used. Refer to section 10.4.3.1.
<add key="SubjectName" value="12345678"/>
The web.config specifies the SAML attributes. The IDPEmail attribute must match with
the users principal name configured in Office 365. In this example, a fixed principal
name is used.
<add key="Attribute_IDPEmail" value="[email protected]"/>
To keep the example identity provider simple, fixed values are used for the users
immutable identifier and principal name. In a production application, these values would
be retrieved from the user store (e.g. Active Directory or a user database).
10.4.2
103
10.4.2.1
Add a Domain
104
105
106
107
Unless DNS entries are to be updated, uncheck the Exchange Online and Lync Online
check boxes.
108
109
10.4.2.2
10.4.2.3
Single sign on cannot be configured using the Office 365 administration center. Instead,
the Windows Azure Active Directory Module for Windows PowerShell cmdlets are used
to configure Office 365 for single sign on.
Download and install the cmdlets from:
http://technet.microsoft.com/en-us/library/jj151815.aspx
More information about these cmdlets and using them to configure single sign on may be
found at:
http://technet.microsoft.com/en-us/library/jj151815.aspx
and
http://technet.microsoft.com/en-us/library/hh967628.aspx
110
10.4.2.4
111
The $domain is the domain name previously configured in Office 365 for single sign on.
The $issuer is the identity provider name. This name must match with the
IdentityProvider name configured in the identity providers saml.config. For example, if
the identity provider name is urn:componentspace:ExampleIdentityProvider then the
$issuer must be set to the same value.
The $ssoUrl is the identity providers SSO service URL. In browser-based SP-initiated
SSO, Office 365 will send an authentication request to this endpoint.
The $ecpUrl is the identity providers Enhanced Client or Proxy URL. In non-browserbased SP-initiated SSO, Office 365 will send an authentication request to this endpoint.
The $logoffUrl is the identity providers SLO service URL.
The $cert is the identity providers certificate. Office 365 will use this certificate to verify
signed SAML assertions from the identity provider.
The Set-MsolDomainAuthentication cmdlet configures authentication for the domain.
The -Authentication federated parameter specifies to use single sign on. The PreferredAuthenticationProtocol SAMLP parameter specifies to use the SAML protocol
rather than WS-Federation.
10.4.2.5
10.4.3
Adding a User
Run the New-MsolUser cmdlet to add a user to the domain. For example:
New-MsolUser -UserPrincipalName [email protected] -ImmutableId
12345678 -FirstName Test -LastName User -DisplayName "Test User" LicenseAssignment "componentspaceau:ENTERPRISEPACK" -usageLocation US
112
10.4.3.1
10.4.4
Deleting a User
During testing, it may be necessary to delete and reconfigure users in Office 365.
Users may be deleted using the Office 365 administration center or by using the
PowerShell Remove-MsolUser cmdlet. For example:
Remove-MsolUser -UserPrincipalName [email protected]
Deleting the user moves the user to the Office 365 recycle bin. To create a user with the
same name, the user first must be removed from the recycle bin. This requires the object
identifier associated with the user.
The Get-MsolUser cmdlet is used to retrieve the object identifier. For example:
Get-MsolUser -ReturnDeletedUsers -SearchString [email protected]
| select UserPrincipalName, ObjectId
The Remove-MsolUser cmdlet is used to delete the user from the recycle bin. For
example:
Remove-MsolUser -RemoveFromRecycleBin ObjectId [objectID value]
10.4.5
In this example, the user is attempting to login at Office 365 and, rather than performing
a local login at Office 365, SSO is initiated with a local login occurring at the example
identity provider and the asserted identity, passed to the service provider in a SAML
assertion, is used to perform an automatic login at the Office 365.
1. Browse to https://portal.microsoftonline.com/.
113
114
115
10.4.6
In this example, the user is logged in at the identity provider and clicks a link to SSO to
Office 365.
1. Browse to the example identity provider.
For example: https://test.componentspace.com/ExampleIdentityProvider.
2. Login at the example identity provider.
116
10.4.7
Office 365 supports users of email clients, such as Microsoft Outlook, logging in through
an identity provider.
The users name and password are sent by the email client to Office 365 which delegates
user authentication to the identity provider.
The SAML Enhanced Client or Proxy (ECP) profile is used for the exchange of SAML
messages between Office 365 and the identity provider.
Along with the SAML authentication request sent to the identity provider, Office 365
includes the users name and password in the HTTP authorization header.
117
The identity provider uses these credentials to authenticate the user. If authenticated, the
identity provider returns a SAML response to Office 365.
10.4.8
Login as the Office 365 administrator and click the Outlook link at the top of the page.
This applies regardless of whether Outlook or some other email client is used.
Click the settings cog at the top right and select Options.
118
Click Settings for POP or IMAP access and take note of these settings.
119
120
121
122
123
124
125
10.4.9
Running the email client will cause user authentication to occur at the identity provider.
126
10.4.10
Refer to the Office 365 documentation pages. The following article lists error codes and
recommended actions.
http://support.microsoft.com/kb/2615736
Office 365 SAML metadata may be retrieved from:
https://nexus.microsoftonline-p.com/federationmetadata/saml20/federationmetadata.xml
10.5.1
The saml.config file includes the following entry for the Google Apps partner service
provider.
<PartnerServiceProvider Name="google.com"
WantAuthnRequestSigned="false"
SignSAMLResponse="true"
SignAssertion="false"
EncryptAssertion="false"/>
The name matches with the issuer name Google Apps uses in the authn request.
127
The assertion consumer service URL specified in the authn request is used rather than
configuring this URL. Alternatively, the assertion consumer service URL may be
configured (e.g. https://www.google.com/a/<domain-name>/acs).
10.5.2
Specify the sign-in page URL. This is the identity providers single sign-on service where
the authn request is sent.
For example:
https://test.componentspace.com/ExampleIdentityProvider/SAML/SSOService.aspx
Specify the sign-out page URL. When the user signs out of Google Apps they are
redirected to the sign-out page. Google Apps does not send a SAML logout request.
128
Specify the change password URL. The user is redirected to this page when they wish to
change their password. This does not involve SAML.
Upload the identity provider's certificate.
For example: idp.cer.
10.5.3
In this example, the user is attempting to access a protected resource on the service
provider and, rather than performing a local login at the service provider, SSO is initiated
with a local login occurring at the identity provider and the asserted identity, passed to
the service provider in a SAML assertion, is used to perform an automatic login at the
service provider.
1. Browse to:
https://mail.google.com/a/<domain-name>
For example:
https://mail.google.com/a/componentspace
2. You should then be presented with the identity provider login prompt.
3. Login using the user name and password of a user known to the identity provider.
The user account should also exist in Google Apps.
129
4. You should then be presented with the Google Mail default page.
This means youve successfully completed a SAML v2.0 SSO and are logged in
at Google Apps with your identity provider user name.
10.5.4
Refer to the Troubleshooting Single Sign-On (SSO) article in the Google Apps
documentation.
10.6.1
The saml.config file includes the following entry for the Salesforce partner service
provider.
<PartnerServiceProvider Name="https://saml.salesforce.com"
WantAuthnRequestSigned="false"
SignSAMLResponse="true"
SignAssertion="false"
EncryptAssertion="false"
AssertionConsumerServiceURL=
"https://login.salesforce.com"/>
The web.config file identifies the partner service provider. This must specify the
Saleforce service provider.
<add key="PartnerSP" value="https://saml.salesforce.com"/>
10.6.2
130
http://test.componentspace.com/ExampleIdentityProvider/SAML/SSOService.aspx as the
login URL.
10.6.3
1. Browse to:
http://localhost/ExampleIdentityProvider
You should then be presented with the identity provider login prompt.
2. Login using the user name and password of a user known to the identity provider.
The user account must also exist in Salesforce.
You may have to update the credentials section of the example identity providers
web.config to include the user name.
3. Click the link to SSO to Salesforce.
The Saleforce main page should be displayed.
This means youve successfully completed a SAML v2.0 SSO and are logged in
at Salesforce with your identity provider user name.
131
10.6.4
The saml.config file includes the following entry for the Salesforce partner identity
provider.
<PartnerIdentityProvider
Name="https://componentspace-dev-ed.my.salesforce.com"
SignAuthnRequest="false"
WantSAMLResponseSigned="true"
WantAssertionSigned="false"
WantAssertionEncrypted="false"
UseEmbeddedCertificate="true"
SingleSignOnServiceUrl=
"https://componentspace-deved.my.salesforce.com/idp/endpoint/HttpRedirect"/>
The partner identity provider name must match with the issuer name generated by
Salesforce. See section 10.6.5.
The web.config file identifies the partner identity provider. This must specify the
Saleforce identity provider.
<add key="PartnerIdP"
value=" https://componentspace-dev-ed.my.salesforce.com "/>
10.6.5
132
10.6.6
1. Browse to the IdP-Initiated login URL specified under the login information for
the service provider in the Salesforce configuration. For example:
133
https://ap1.salesforce.com/idp/login?app=0sp90000000Kyvb
You should then be presented with the Salesforce login prompt.
2. Login using the user name and password of a user known to Salesforce.
10.6.7
134
10.6.8
Use Setup > Security Controls > Single Sign-On Settings > SAML Assertion Validator to
debug problems with the SAML response.
View the Login History under Setup > Manage Users > Login History.
135
10.7.1
The saml.config file identifies the local identity provider. This must match with the entity
ID specified in the metadata uploaded to Shibboleth.
<IdentityProvider Name="https://test.componentspace.com"/>
The saml.config file includes the following entry for the Shibboleth partner service
provider.
<PartnerServiceProvider Name="https://sp.testshib.org/shibboleth-sp"
WantAuthnRequestSigned="false"
SignSAMLResponse="true"
SignAssertion="false"
EncryptAssertion="false"
AssertionConsumerServiceURL=
"https://sp.testshib.org/Shibboleth.sso/SAML2/POST"/>
10.7.2
The saml.config file identifies the local service provider. This must match with the entity
ID specified in the metadata uploaded to Shibboleth.
<ServiceProvider Name="https://test.componentspace.com"/>
The saml.config file includes the following entry for the Shibboleth partner service
provider.
<PartnerIdentityProvider Name="https://idp.testshib.org/idp/shibboleth"
SignAuthnRequest="true"
WantResponseSigned="true"
WantAssertionSigned="false"
WantAssertionEncrypted="false"
UseEmbeddedCertificate="true"
SingleSignOnServiceUrl=
"https://idp.testshib.org/idp/profile/SAML2/Redirect/SSO"/>
The web.config file identifies the partner identity provider. This must specify the
Shibboleth identity provider.
<add key="PartnerIdP" value="https://idp.testshib.org/idp/shibboleth"/>
136
10.7.3
Configuring Shibboleth
137
10.7.4
1. Browse to:
https://sp.testshib.org/
Specify the entity ID you defined in your metadata. This entity ID is used as a key
by Shibboleth to retrieve the correct metadata.
138
2. You should then be presented with the identity provider login prompt.
3. Login and you should be returned to Shibboleth.
https://sp.testshib.org/testing/sample.jsp
This means youve successfully completed a SAML v2.0 SSO and are logged in
at Shibboleth with your identity provider user name.
139
10.7.5
140
141
10.7.6
142
The example applications in sections 11.8 and 11.9 demonstrate interoperability with the
Shibboleth open source SSO software package. These applications are written in C#.
The example application in section 11.10 demonstrates creating and manipulating SAML
assertions. This application is written in VB.NET.
The example applications in section 11.11 demonstrate creating and manipulating SAML
metadata. These applications are written in C#.
The example applications in section 11.12 demonstrate generating and verifying XML
signatures. These applications are written in C#.
Section 11.13 includes various utility applications.
11.1.1
11.1.2
11.1.3
As this is SP initiated SSO, you need to run the service provider application rather than
the identity provider to initiate SSO.
143
In this example SSO is not being used. Instead, you should simply perform a local login
at the identity provider to ensure it is functioning correctly.
1. Browse to http://localhost/SAML2IdentityProvider.
2. Login using the user name idp-user and a password of password (see Figure 24).
3. Verify that youve been redirected to the identity providers default page (see
Figure 25).
11.1.4
You may run the identity provider in Visual Studio. The one additional step is to note the
port number being used by Visual Studio to run the application. You then need to update
the service providers configuration as described in section 11.2.2 to account for the
different port number being used by Visual Studio.
144
11.2.1
11.2.2
11.2.3
In this example SSO is not being used. Instead, you should simply perform a local login
at the service provider to ensure it is functioning correctly.
1. Browse to http://localhost/SAML2ServiceProvider.
2. You should be presented with the form shown in Figure 28.
3. Select the service provider as the location where login will occur.
4. Login using the user name sp-user and a password of password (see Figure 26).
5. Verify that youve been redirected to the service providers default page (see
Figure 27).
145
11.2.4
In this example, the user is attempting to access a protected resource on the service
provider and, rather than performing a local login at the service provider, SSO is initiated
with a local login occurring at the identity provider and the asserted identity, passed to
the service provider in a SAML assertion, is used to perform an automatic login at the
service provider.
7. Browse to http://localhost/SAML2ServiceProvider.
8. You should be presented with the form shown in Figure 28.
9. Select the identity provider as the location where login will occur.
Selecting the identity provider will initiate a SAML v2.0 SSO. Selecting the
service provider will initiate a local login at the service provider.
10. Select the binding to use when communicating between the service provider and
identity provider.
The user experience should be the same regardless of the binding selected. The
146
only time when this isnt the case is if the HTTP POST binding is selected and
Javascript is disabled in which case the user will be presented with an
intermediate form and a button they need to click.
11. Select the binding to use when communicating between the identity provider and
service provider.
The user experience should be the same regardless of the binding selected. The
only time when this isnt the case is if the HTTP POST binding is selected and
Javascript is disabled in which case the user will be presented with an
intermediate form and a button they need to click.
12. Click the Continue button.
13. You should then be presented with the identity provider login page (see Figure
24) as you will be logging in at the identity provider, not the service provider.
If you are not then you must already have logged in at the identity provider. To
force a login, close the browser and start again.
14. Login using the user name idp-user and a password of password.
15. You should then be presented with the service providers default page (see Figure
29).
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
147
The service provider is coded so as not to force authentication at the identity provider. To
demonstrate this login at the identity provider and, using the same browser session,
browse to the service provider and select the login location as the identity provider. No
login at the identity provider will be required as you have already logged in.
1. Login at the identity provider by following the steps described in section 11.1.3.
148
2. Using the same browser session, follow the steps described in section 11.2.4.
You should not have to login again at the identity provider.
11.2.5
You may run the service provider in Visual Studio. The one additional step is to note the
port number being used by Visual Studio to run the application. You then need to update
the identity providers configuration as described in section 11.1.2 to account for the
different port number being used by Visual Studio.
11.2.6
Figure 30 illustrates the execution flow between the example service provider and
identity provider.
Browser
Service Provider
Identity Provider
2. SPs LoginChoice.aspx
4. IdPs Login.aspx
5. <Response> message sent by IdPs SSOService.aspx to SPs AssertionConsumerService.aspx
6. SPs Default.aspx
149
11.3.1
11.3.2
11.3.3
As this is IdP initiated SSO, you need to run the identity provider application rather than
the service provider to initiate SSO.
In this example SSO is not being used. Instead, you should simply perform a local login
at the service provider to ensure it is functioning correctly.
1. Browse to http://localhost/SAML2SP.
2. Login using the user name sp-user and a password of password.
3. Verify that youve been redirected to the service providers default page.
150
11.3.4
You may run the identity provider in Visual Studio. No configuration changes are
required.
11.4.1
11.4.2
11.4.3
In this example, the user is attempting to access a protected resource on the service
provider and, rather than performing a local login at the service provider, SSO is initiated
with a local login occurring at the identity provider and the asserted identity, passed to
the service provider in a SAML assertion, is used to perform an automatic login at the
service provider.
1. Browse to http://localhost/SAML2IdP.
2. You should be presented with the identity provider login page as you will be
logging in at the identity provider, not the service provider.
If you are not then you must already have logged in at the identity provider. To
force a login, close the browser and start again.
3. Login using the user name idp-user and a password of password.
151
4. You should then be presented with the identity providers default page.
5. Click the link to access the service provider.
6. You should then be presented with the service providers default page.
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
11.4.4
You may run the service provider in Visual Studio. The one additional step is to note the
port number being used by Visual Studio to run the application. You then need to update
the identity providers configuration as described in section 11.4.2 to account for the
different port number being used by Visual Studio.
11.5.1
11.5.2
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect
152
11.5.3
Miscellaneous Configuration
For the purposes of this example, the host name of the service provider is www.sp.com
and the host name of the ADFS identity provider is www.idp.com.
Update the Windows\System32\drivers\etc\hosts file on the identity provider and server
provider to include entries for www.idp.com and www.sp.com. For example:
192.168.1.20
192.168.1.21
11.5.4
www.idp.com
www.sp.com
Configuring ADFS
In the ADFS terminology, the service provider is a relying party. Using the ADFS
management console, add a relying party trust for the service provider.
Select the option to enter the relying party information manually.
153
154
If you wish to have the SAML assertion returned by ADFS encrypted, browse to sp.cer to
specify it as the token encryption certificate.
155
Enable support for SAML v2.0 and specify the service providers assertion consumer
service URL.
156
157
158
Review the configuration and click Finish. The service provider should be included in the
list of relying party trusts.
The authn request sent by the service provider is signed. To specify the certificate to use
to verify the signature, bring up the reply party trusts properties and under the Signature
tab add the service provider certificate.
159
Although the SAML v2.0 component supports SHA-256 signatures, for this example
SHA-1 is used. To specify this, under the Advanced tab select SHA-1.
160
Map the Active Directory user principal name to the outgoing Name ID.
161
162
ADFS should now be ready to communicate with the example service provider.
To review the metadata published by ADFS browse to:
https://www.idp.com/FederationMetadata/2007-06/FederationMetadata.xml
11.5.5
In this example SSO is not being used. Instead, you should simply perform a local login
at the service provider to ensure it is functioning correctly.
1. Browse to https://www.sp.com/ADFSSP, ignoring any browser certificate
warnings.
2. Select the service provider as the location where login will occur.
3. Login using the user name sp-user and a password of password.
4. Verify that youve been redirected to the service providers default page.
163
11.5.6
In this example, the user is attempting to access a protected resource on the service
provider and, rather than performing a local login at the service provider, SSO is initiated
with a local login occurring at the ADFS identity provider and the asserted identity,
passed to the service provider in a SAML assertion, is used to perform an automatic login
at the service provider.
1. Browse to http://www.sp.com/ADFSSP, ignoring any browser certificate
warnings.
2. Select the identity provider as the location where login will occur.
Selecting the identity provider will initiate a SAML v2.0 SSO to ADFS. Selecting
the service provider will initiate a local login at the service provider.
3. You should then be presented with the identity provider login prompt as you will
be logging in at the identity provider, not the service provider.
4. Login using the user name and password of a user defined in Active Directory.
164
5. You should then be presented with the service providers default page.
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
11.6.1
11.6.2
The only identity provider configuration you may need to change is the list of user
credentials specified in web.config. The user name that you log into at the identity
provider must match with an account name in Google Apps.
Modifying web.config does not require an application restart.
11.6.3
Refer to the Google Apps documentation for instructions on enabling and configuring
single sign-on.
When using the GoogleIdP application, the following URLs should be specified. Replace
the example host name with the appropriate host name or IP address.
The sign-in page is: http://www.yourdomain.com/GoogleIdP/SAML/SSOService.aspx.
165
11.6.4
11.7.1
11.7.2
The only identity provider configuration you may need to change is specified in
web.config. The Issuer setting must match with the issuer specified in the Salesforce SSO
configuration. The SalesforceLoginID is the Salesforce user name used to single sign-on
to Salesforce.
Modifying web.config does not require an application restart.
11.7.3
Configuring Salesforce
Refer to the Salesforce documentation for instructions on enabling and configuring single
sign-on.
166
The SAML version is 2.0. The issuer is www.idp.com. This must match the Issuer setting
specified in web.config. Upload the certificate contained in the idp.cer file in the projects
directory.
The user ID type should be set to specify that the assertion contains the users Salesforce
user name and the user ID is in the subjects name identifier. The Salesforce user name is
configured with the SalesforceLoginID setting in web.config.
The Salesforce Login History under Manage Users provides a useful log for debugging
single sign-on problems.
11.7.4
Running Salesforce
11.7.5
The Salesforce SAML Assertion Validator may be used to track down SAML assertion
validation errors.
1. Capture and copy the SAML response XML making sure not to modify it in any
way. For example, turn on trace within web.config and copy the SAML response
XML from the generated log file.
2. Paste the SAML response XML into the Salesforce SAML Assertion Validator
screen and click Validate.
3. Review the validation check list.
11.8.1
167
5. Ensure the web application has been successfully installed and configured by
browsing to http://localhost/ShibbolethIdP.
11.8.2
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact.
11.8.3
As this is SP initiated SSO, you need to run the service provider application rather than
the identity provider to initiate SSO.
In this example SSO is not being used. Instead, you should simply perform a local login
at the identity provider to ensure it is functioning correctly.
1. Browse to http://localhost/ShibbolethIdP.
2. Login using the user name idp-user and a password of password.
3. Verify that youve been redirected to the identity providers default page.
11.8.4
You may run the identity provider in Visual Studio. The one additional step is to note the
port number being used by Visual Studio to run the application. You then need to update
the service providers configuration as described in section 11.8.2 to account for the
different port number being used by Visual Studio.
168
11.9.1
11.9.2
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact.
11.9.3
In this example SSO is not being used. Instead, you should simply perform a local login
at the service provider to ensure it is functioning correctly.
5. Browse to http://localhost/ShibbolethSP
6. Select the service provider as the location where login will occur.
7. Login using the user name sp-user and a password of password.
169
8. Verify that youve been redirected to the service providers default page.
11.9.4
In this example, the user is attempting to access a protected resource on the service
provider and, rather than performing a local login at the service provider, SSO is initiated
with a local login occurring at the identity provider and the asserted identity, passed to
the service provider in a SAML assertion, is used to perform an automatic login at the
service provider.
6. Browse to http://localhost/ShibbolethSP.
7. Select the identity provider as the location where login will occur.
Selecting the identity provider will initiate a SAML v2.0 SSO. Selecting the
service provider will initiate a local login at the service provider.
8. You should then be presented with the identity provider login page as you will be
logging in at the identity provider, not the service provider.
If you are not then you must already have logged in at the identity provider. To
force a login, close the browser and start again.
9. Login using the user name idp-user and a password of password.
10. You should then be presented with the service providers default page.
This means youve successfully completed a SAML v2.0 SSO and are logged in
at the service provider with your identity provider user name.
11.9.5
You may run the service provider in Visual Studio. The one additional step is to note the
port number being used by Visual Studio to run the application. You then need to update
the identity providers configuration as described in section 11.9.2 to account for the
different port number being used by Visual Studio.
11.10.1
170
11.11.1
The ImportMetadata application imports a SAML metadata file into the high-level API
SAML configuration (saml.config).
Usage:
ImportMetadata.exe <metadata-filename>
where the file contains the SAML entities descriptor or entity descriptor metadata to be
imported into saml.config.
For example, the following imports IdP metadata into saml.config:
ImportMetadata.exe idp-metadata.xml
The saml.config file, if any, is assumed to be in the current directory.
If it doesnt exist, a saml.config file is created. Otherwise, metadata is merged into the
existing saml.config.
A saml.config partner provider entry is created for each entity descriptor in the metadata.
The updated saml.config includes TODO instructions where additional information is
required or needs review.
11.11.2
171
A single metadata entity descriptor is created for the local provider configured in
saml.config.
The generated metadata includes TODO instructions where additional information is
required or needs review.
11.11.3
11.11.4
ReadMetadata
ReadMetadata reads SAML metadata. It is a useful utility for confirming the metadata
syntax is valid.
Usage:
ReadMetadata.exe <filename>
where the file contains the SAML entities descriptor or entity descriptor metadata.
For example, the following parses IdP metadata:
ReadMetadata.exe idp-metadata.xml
11.12.1
11.12.2
SignSAML
172
11.12.3
VerifySAML
11.13.1
ValidateConfig
ValidateConfig validates the SAML configuration file against its schema. See section 6
for a description of the SAML configuration schema.
ValidateConfig is a useful utility for debugging SAML configuration file errors.
Usage:
ValidateConfig.exe <filename >
where the file contains the SAML configuration.
For example, the following validates a SAML response:
ValidateConfig.exe saml.config
11.13.2
ValidateXML
173
11.13.3
EncryptSAML
11.13.4
DecryptSAML
11.13.5
ParseHttpRedirectUrl
ParseHttpRedirectUrl decodes the query string parameters in an HTTP redirect URL and
verifies their signature. It is a useful utility for debugging signature errors.
Usage:
ParseHttpRedirectUrl.exe c < certificateFileName> <filename>
where the certificateFileName is a CER file containing the certificate to use to verify the
signature, and the file contains the redirect URL including query string.
For example, the following parses a redirect URL:
ParseHttpRedirectUrl.exe c test.cer RedirectURL.txt
11.13.6
Java Utilities
A Java application may be found under the examples directory (e.g. C:\Program Files
(x86)\ComponentSpace\SAML2\Examples\Java).
This application may be used to independently generate and verify signatures.
Refer to the readme.txt in the Examples\Java directory for instructions on running this
application.
174
12.1 Considerations
The example applications described in section 5 are a good starting point for adding SSO
support to your application.
However, these are only example applications and have been kept as simple as possible
to assist you in understanding them.
For production applications you will need to consider a number of requirements not
covered by the example applications.
12.1.1
Error Handling
12.1.2
Configuration
Some of the example applications allow the user to select the SAML bindings.
The bindings to use should be negotiated between the identity provider and service
provider and not exposed to the user.
175
12.1.3
Key Management
SAML assertions and protocol message may be signed to ensure their integrity and
origin.
Also, SAML assertions may be encrypted to ensure the privacy of their data.
The example applications sign messages using private keys stored in PFX files and verify
signatures using public keys stored in CER files.
You may wish to store keys and certificates in one of the Windows certificate stores and
access them using the .NET frameworks X509Store class.
12.1.4
Security
13.1 Makecert
Use the makecert and pvk2pfx tools that ships with Visual Studio (e.g. C:\Program
Files\Microsoft Visual Studio 8\Common7\Tools\Bin\makecert.exe) to create certificate
files and private key files.
makecert -r -pe -sky exchange -n "cn=www.idp.com" -sv idp.pvk idp.cer
176
You then need to convert the PVK file to a PFX file so it can be loaded with the .NET
framework classes.
pvk2pfx -pvk idp.pvk -spc idp.cer -pfx idp.pfx -po password -f
Refer to the Microsoft help for additional options.
13.1.1
3. Using the Certification Authority MMC snap-in, view the pending requests and
issue a certificate.
4. Back at the certificate service click, view the status of the pending certificate
request and click the link to install the certificate.
5. Using the Certificates MMC snap-in, view the certificate to confirm that it has
been installed. If required you can export the certificate and private key to a PFX
file but make sure to check "Include all certificates in the certification path if
possible". You can also export the certificate only if required.
13.3 Keytool
Use the Java keytool that comes with the JDK to create certificate files and private key
files.
keytool -genkey -dname "cn=www.idp.com" -alias idp -keypass password -keyalg RSA
-validity 3650 -keystore idp.pfx -storepass password -storetype pkcs12
You then need to generate a certificate file.
keytool.exe -export -alias idp -keystore idp.pfx -storepass password -storetype pkcs12
-rfc -file idp.cer
14 SAML Metadata
The Metadata for the OASIS Security Assertion Markup Language (SAML) V2.0
specification defines a format for exchanging SAML configuration information. This
exchange occurs out-of-band (e.g. by downloading from web sites or by email) between
partner organizations as part of establishing a single sign-on environment.
The use of SAML metadata is entirely optional. Information, including endpoint URLs
etc, may be exchanged in any manner convenient to the partner organizations.
178
15 Troubleshooting
15.1 Tracing
To help resolve problems, tracing internal to the product may be enabled. If you are
experiencing a problem you may be asked to enable tracing.
15.1.1
Most of the example applications include a diagnostic tracing section in their web.config
files.
179
15.1.1.1
You must ensure the directory where the log file will be written exists. In this example,
the directory c:\temp must exist in order for the SAML2.log file to be created.
The user account running the web application must have write permission to this
directory. For example, give the IIS_USERS group write permission to the directory.
Alternatively, in a development environment you may give the Everyone group write
permission to the directory. This should not be done in a production environment.
180
15.1.2
Create a standard .NET configuration file for your application, if one doesn't already
exist. The configuration file name consists of your application file name and .config.
For example, if your application is called myapplication.exe then its configuration file
should be named myapplication.exe.config. The configuration file must be located in the
same directory as the application executable.
Include in the <system.diagnostics> section a switch and listeners as shown in the
example configuration below.
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="TextWriter"/>
</listeners>
</trace>
<sources>
<source name="ComponentSpace.SAML2" switchValue="Verbose">
<listeners>
<add name="TextWriter"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="TextWriter"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\temp\logs\idp.log"/>
181
15.2.1
VerifySAML
If you believe the correct certificate is being used you can run a supplied utility,
VerifySAML, to see whether the signature can be verified (see section 11.11.4).
For example, to verify the signature on a SAML protocol response you would capture the
response to file, ensuring the XML is not altered in any way, and run:
VerifySaml.exe [c <certificateFileName>] <filename>
The certificateFileName is a CER file containing the certificate to use to verify the
signature. Only specify this parameter if the certificate is being loaded from a certificate
file or store. If the certificate is included in the XML signature, then do not specify this
parameter.
The filename is the file containing the SAML protocol response as XML.
This utility may be used to verify signatures on SAML requests, responses and assertions.
15.2.2
182
This shows that the calculated hash of the canonicalized XML matches the hash or digest
value contained in the XML signature. This confirms that the XML has not been
modified.
It also shows that the calculated signature value matches the signature value in the XML
signature. This confirms that the XML was signed by the owner or subject of the
certificate.
If the XML has been modified after signing, the log will include entries like:
System.Security.Cryptography.Xml.SignedXml Verbose: 13 : [SignedMessage#00245fb7,
VerifyReference] Reference Reference#003917f2 hashed with
"http://www.w3.org/2000/09/xmldsig#sha1" (SHA1CryptoServiceProvider) has hash value
604bfa74922eb89c25d061a0e9eda3d3f1967d9c, expected hash value
a3503180ce819de2efc3a66f9b29b7d2687033ec.
System.Security.Cryptography.Xml.SignedXml Information: 12 : [SignedMessage#00245fb7,
VerificationFailure] Verification failed checking references.
This shows that the calculated hash of the canonicalized XML does not match the hash or
digest value contained in the XML signature. This means that the XML has been
modified.
If the wrong certificate is used to verify the signature, the log will include entries like:
System.Security.Cryptography.Xml.SignedXml Information: 12 : [SignedMessage#00245fb7,
VerificationFailure] Verification failed checking SignedInfo.
15.2.3
Java VerifyXMLSignature
15.2.4
The element name is Response; its prefixed with samlp; and its declared in the
urn:oasis:names:tc:SAML:2.0:protocol namespace.
183
What uniquely identifies this element is its name and namespace. The prefix is a
mechanism for linking an element with its namespace declaration.
By conventions samlp is used for the urn:oasis:names:tc:SAML:2.0:protocol namespace
although any other prefix would be equally valid.
Java and some other implementations often use the ds prefix for the XML signature
namespace. For example:
<ds:Signature xmlns="http://www.w3.org/2000/09/xmldsig#/">
The .NET framework treats the XML signature namespace as the default namespace and
consequently doesnt use a prefix. For example:
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
15.3.1
When loading a certificate from file, if an access denied exception occurs, this generally
indicates a file permissions error.
Firstly, make sure the process the application is running under has permission to read the
certificate file. For example, ensure the IIS_USERS group has read permission to the
idp.pfx file.
If the permissions are correct for the pfx file, then the issue lies with the private key.
184
Private keys are stored in containers on the file system. The location of the private key
container on Windows 7/Windows 8/Windows 2008 and Windows 2012 is:
C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
The FindPrivateKey.exe Windows SDK utility may be run to locate the private key
container.
http://msdn.microsoft.com/en-us/library/aa717039.aspx
The application process must have permission to create a file in the private key container
folder.
The following code dumps out a certificate:
X509Certificate2 x509Certificate = new X509Certificate2(idp.pfx, password,
X509KeyStorageFlags.MachineKeySet);
Trace.Write(x509Certificate.ToString(true));
Its output is:
[Version]
V1
[Subject]
CN=www.idp.com
Simple Name: www.idp.com
DNS Name: www.idp.com
[Issuer]
CN=www.idp.com
Simple Name: www.idp.com
DNS Name: www.idp.com
[Serial Number]
46D399D0
[Not Before]
8/28/2007 1:43:12 PM
[Not After]
8/25/2017 1:43:12 PM
[Thumbprint]
4E387A0C0B695DB05F5DFD70D2572BB0FEBB98BA
[Signature Algorithm]
185
md5RSA(1.2.840.113549.1.1.4)
[Public Key]
Algorithm: RSA
Length: 1024
Key Blob: 30 81 89 02 81 81 00 a3 7d 6a de 62 59 6b 25 df 66 42 c3 b8 b7 27 6a 77 3f 28 6f 91
0c 55 be 3a 56 03 3f e4 6e 6e f5 a7 b7 c5 f9 8e d8 94 4d ca 7c 21 0e 3a 4c d1 14 16 c9 26 b2 89
d4 6f 90 27 1b ec ce 09 c6 b0 6f 67 49 af c9 01 b4 23 61 7e 2f d3 b9 f6 46 05 03 63 b8 0c 4d 32
2d f8 c8 88 11 74 68 a7 6b 39 c7 81 c9 6b 00 82 19 4f 22 9e ad 0a 98 8c f2 f5 c5 10 ec 14 6a 73
a8 61 a2 ff 6a 29 cc df 27 57 99 02 03 01 00 01
Parameters: 05 00
[Private Key]
Key Store: Machine
Provider Name: Microsoft Base Cryptographic Provider v1.0
Provider type: 1
Key Spec: Exchange
Key Container Name: {7D7021F3-C4E9-44C2-BB68-ECD0517EF5FE}
Unique Key Container Name: 1cff1ca21ad134bb7e6e87ee27ff71d3_cddd8d16-473b-40eb-8c9f9cb4b8d44d33
Hardware Device: False
Removable: False
Protected: False
Note the unique key container name. This name is different each time the certificate is
loaded.
At the time the certificate is loaded, a file with the private key container name is created
in the private key container (e.g.
C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\7D7021F3-C4E9-44C2-BB68ECD0517EF5FE).
The application process must have permission to create files in this container.
186
15.3.2
When loading a certificate from the Windows Certificate Store, if an access denied
exception occurs, this generally indicates a permissions error.
Firstly, make sure the certificate is stored in the local computer store rather than the
current users store. This ensures the certificate may be accessed from within IIS.
Select the certificate, and click the menu Action > All Tasks > Manage Private Keys.
Make sure the application process (e.g the IIS_IUSRS group) has read access.
187
188
189
16.3.1
For .NET 4.5 and above, SHA-256 support is, for the most part, built into the .NET
framework. The only requirement is to register the cryptographic algorithm.
The RSAPKCS1SHA256SignatureDescription class in the
System.Deployment.Internal.CodeSigning namespace is contained in the
System.Deployment assembly.
To enable SHA-256 support:
1. Add a reference to the System.Deployment assembly.
2. In your application, add the following section of code to enable SHA-256 XML
signatures. A suitable location might be your applications Application_Start
method in Global.asax.
using System.Security.Cryptography;
using System.Deployment.Internal.CodeSigning;
protected void Application_Start(object sender, EventArgs e) {
// Enable SHA-256 XML signature support.
CryptoConfig.AddAlgorithm(
typeof(RSAPKCS1SHA256SignatureDescription),
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
}
16.3.2
For .NET 3.5 and above, SHA-256 support in XML signatures requires the use of the
CLR security update.
Download the CLR security update from:
http://clrsecurity.codeplex.com/
190
To generate SHA-256 signatures, use one of the overloaded signature Generate methods
that take as parameters the digest and signature methods.
The default digest method is http://www.w3.org/2000/09/xmldsig#sha1.
The default signature method is http://www.w3.org/2000/09/xmldsig#rsa-sha1.
191
192
18 Encrypted Assertions
For additional security, SAML assertions may be encrypted.
193
194
195
The following properties are for the licensed version of the DLL.
196
197
4. I keep receiving an error message saying the trial period has expired. What does
this mean?
You are using an evaluation version of the component and the trial period has
ended. If you need to extend the evaluation period, please contact us.
5. How do I tell if I'm using an evaluation version?
Navigate to the component DLL and right click it to bring up the file properties.
Under the Version tab, the description will specify whether or not it's an
evaluation version.
6. I'm not sure how to use the product. What can I do?
Whether you're evaluating the product or are an existing customer, please feel free
to contact us with any questions you might have.
7. The product is missing a feature I really need. What can I do?
Please contact us if there's additional functionality you would like to see. Your
feedback is most welcome and will be given careful consideration.
8. Does the product support SAML single sign-on?
Yes. The product includes the necessary functionality for enabling SAML single
sign-on at either the identity provider or service provider web site. You need to
integrate this functionality with your existing web applications.
9. Can I generate and verify XML digital signatures on SAML assertions and
protocol messages?
Yes. Refer to the Reference section and the Examples for more information.
10. Is the product compatible with Product X?
It should be but if you have any questions please contact us. A simple test is to
integrate the example identity provider or service provider application with the
product in question.
11. How do I create a SAML assertion?
Use the ComponentSpace.SAML2.Assertions.SAMLAssertion class to create a
SAML assertion.
The example applications demonstrate creating and manipulating SAML
assertions.
12. How do I convert a SAML assertion to and from XML?
The ComponentSpace.SAML2.Assertions.SAMLAssertion class includes a
198
constructor that creates a SAML assertion from an XML element. This class also
includes a ToXml method that converts the SAML assertion object to XML.
13. How do I sign a SAML assertion?
The ComponentSpace.SAML2.Assertions.SAMLAssertionSignature class has
methods for generating and verifying signatures on SAML assertions that are
serialized to XML.
Typically you create a SAML assertion using the
ComponentSpace.SAML2.Assertions.SAMLAssertion class. Once complete, you
convert it to XML using the ToXml method of this class. Then you pass this XML
to the Generate method of the SAMLAssertionSignature class.
14. How do I verify a signed SAML assertion?
The ComponentSpace.SAML2.Assertions.AssertionSignature class has methods
for generating and verifying signatures on SAML assertions that are serialized to
XML.
Typically you verify the signature by passing the XML to the Verify method of
the SAMLAssertionSignature class. Once verified, you create a SAML assertion
from the XML using the ComponentSpace.SAML2.Assertions.Assertion class.
15. How do I create a SAML protocol message?
Use the classes under the ComponentSpace.SAML2.Protocols namespace for
creating protocol messages. For example, to create an authentication request you
would use the AuthnRequest class.
16. How do I convert a SAML protocol message to and from XML?
The protocol message classes include a constructor that creates a SAML protocol
message from an XML element. These classes also include a ToXml method that
converts the SAML protocol message to XML.
17. How do I sign a SAML protocol message?
The ComponentSpace.SAML2.Protocols.SAMLMessageSignature class has
methods for generating and verifying signatures on SAML protocol messages that
are serialized to XML.
Typically you create a SAML message using the corresponding class in the
ComponentSpace.SAML2.Protocols namespace. Once complete, you convert it to
XML using the ToXml method of this class. Then you pass this XML to the
Generate method of the SAMLMessageSignature class.
18. How do I verify a signed SAML protocol message?
The ComponentSpace.SAML2.Protocols. SAMLMessageSignature class has
199
methods for generating and verifying signatures on SAML protocol messages that
are serialized to XML.
Typically you verify the signature by passing the XML to the Verify method of
the SAMLMessageSignature class. Once verified, you create a SAML protocol
message from the XML using the appropriate constructor for the protocol
messages corresponding class in the ComponentSpace.SAML2.Protocol
namespace.|
19. Whats the difference between CurrentUser and LocalMachine when referring to
certificate store locations?
Please refer to the Microsoft knowledge base article Q322371. If running in an
ASP.NET application then keys may need to be loaded from LocalMachine key
stores.
20. How do I use HTTPS to secure the connection between identity provider and the
service provider?
The MSDN has numerous articles on configuring HTTPS within an ASP.NET
environment. A good starting point is the article Building Secure ASP.NET
Applications: Authentication, Authorization, and Secure.
24 Support
For further information, visit us at www.componentspace.com or send email to
[email protected].
If you need assistance, have a bug to report, or a product enhancement request, send
email to [email protected].
200