Spring Security Saml Reference
Spring Security Saml Reference
Reference Documentation
1.0.0.RC3-SNAPSHOT
Vladimr Schfer
Table of Contents
I. Getting Started ....................................................................................................................... 1
1. Introduction .................................................................................................................... 2
1.1. What this manual covers ..................................................................................... 2
1.2. When to use Spring Security SAML Extension ...................................................... 2
1.3. Features and supported profiles ........................................................................... 2
1.4. Requirements ...................................................................................................... 3
1.5. Source code ........................................................................................................ 3
1.6. Builds ................................................................................................................. 3
1.7. License ............................................................................................................... 3
1.8. Support ............................................................................................................... 3
2. Glossary ........................................................................................................................ 4
3. Quick start guide ............................................................................................................ 6
3.1. Pre-requisites ...................................................................................................... 6
3.2. Installation steps ................................................................................................. 6
Compilation of the module .................................................................................. 6
Configuration of IDP metadata ............................................................................ 6
Generation of SP metadata ................................................................................ 7
Deployment ........................................................................................................ 7
Uploading of SP metadata to the IDP .................................................................. 7
3.3. Testing single sign-on and single logout ............................................................... 8
II. Configuring SSO with SAML ................................................................................................... 9
4. Configuration and integration ........................................................................................ 10
4.1. Overview ........................................................................................................... 10
4.2. Integration to applications .................................................................................. 10
Maven dependency .......................................................................................... 10
Bean definitions ................................................................................................ 11
Spring Security integration ................................................................................ 11
4.3. Metadata configuration ....................................................................................... 11
Service provider metadata ................................................................................ 11
Automatic metadata generation ................................................................. 11
Pre-configured metadata ........................................................................... 14
Downloading metadata ............................................................................. 15
Identity provider metadata ................................................................................. 16
File-based metadata provider .................................................................... 16
HTTP-based metadata provider ................................................................. 16
Signature verification ................................................................................ 17
Extended metadata .......................................................................................... 17
4.4. Entity alias ........................................................................................................ 17
4.5. Key management .............................................................................................. 17
Sample keystore .............................................................................................. 18
Generating and importing private keys ............................................................... 18
Importing public keys ........................................................................................ 19
Loading SSL/TLS certificates ............................................................................ 19
4.6. Security profiles ................................................................................................. 19
Metadata interoperability profile (MetaIOP) ........................................................ 19
PKIX profile ...................................................................................................... 20
Custom profile .................................................................................................. 20
1.0.0.RC3-SNAPSHOT
ii
1.0.0.RC3-SNAPSHOT
20
21
22
22
22
24
24
25
25
26
27
27
27
27
28
29
29
29
31
31
32
iii
1. Introduction
1.1 What this manual covers
This manual describes Spring Security SAML Extension component, it's uses, installation, configuration,
design and tested environments.
1.0.0.RC3-SNAPSHOT
1.4 Requirements
Spring Security SAML Extension requires as minimum Java 1.6.
TODO Apache Tomcat, Jetty, Oracle Weblogic, ....
1.6 Builds
Snapshot builds of the project are available in the SpringSource repository
1.7 License
Source code of the module is licensed under the Apache License, Version 2.0. You may obtain copy of
the license at http://www.apache.org/licenses/LICENSE-2.0.
1.8 Support
Issue tracking for the module can be found at Spring Security Extensions Jira. Feel free to submit bugs,
patches and feature requests.
For community support please use Spring Security forum. For additional support you can reach me at
vladimir.schafer at gmail.com.
1.0.0.RC3-SNAPSHOT
2. Glossary
Table 2.1. Definitions of terms used within this manual.
Term
Definition
Assertion
Artifact
Binding
Discovery
Metadata
Profile
Protocol
1.0.0.RC3-SNAPSHOT
Term
Definition
1.0.0.RC3-SNAPSHOT
3.1 Pre-requisites
Please make sure the following items are available before starting the installation:
Supported application server or container
Spring Security SAML Extension
Java 1.6+ SDK
SAML Extension relies on XML processing capabilities of JAXP. Some older versions of JRE might
require updating of the embedded JAXP libraries. In case you encounter XML processing exceptions
please create folder jdk/jre/lib/endorsed in your JDK installation and include files in lib/endorsed from
the latest OpenSAML archive available at http://shibboleth.net/downloads/java-opensaml/. The location
of the endorsed folder may differ based on your application server or container.
Due to US export limitations Java JDK comes with a limited set of cryptography capabilities. Usage of
the SAML Extension might require installation of the Unlimited Strength Jurisdiction Policy Files which
removes these limitations.
1.0.0.RC3-SNAPSHOT
<bean id="metadata"
class="org.springframework.security.saml.metadata.CachingMetadataManager">
<constructor-arg>
<list>
<bean class="org.opensaml.saml2.metadata.provider.HTTPMetadataProvider">
<constructor-arg>
<value type="java.lang.String">http://idp.ssocircle.com/idp-meta.xml</value>
</constructor-arg>
<constructor-arg>
<value type="int">5000</value>
</constructor-arg>
<property name="parserPool" ref="parserPool"/>
</bean>
</list>
</constructor-arg>
</bean>
The settings tell system to download IDP metadata from the given URL with timeout of 5 seconds. In
production system metadata should be either stored as a local file or be downloaded from a source
using SSL/TLS with configured trust or which provides digitally signed metadata.
Generation of SP metadata
Modify file WEB-INF/classes/security/securityContext.xml inside the war archive and replace
metadataGeneratorFilter bean as follows and make sure to replace the entityId value with a string which
is unique within the SSO Circle service (e.g. urn:test:yourname:yourcity):
<bean id="metadataGeneratorFilter"
class="org.springframework.security.saml.metadata.MetadataGeneratorFilter">
<constructor-arg>
<bean class="org.springframework.security.saml.metadata.MetadataGenerator">
<property name="entityId" value="replaceWithUniqueIdentifier"/>
<property name="signMetadata" value="false"/>
</bean>
</constructor-arg>
</bean>
Deployment
Deploy the updated war archive to your application server or container. After deployment the SP module
will be available at e.g. http://localhost:8080/spring-security-saml2-sample
1.0.0.RC3-SNAPSHOT
1.0.0.RC3-SNAPSHOT
4.1 Overview
Spring Security SAML 2.0 library comprises three modules:
saml2-core contains implementation of the WebSSO profiles of the SAML 2.0 protocol and is required
for integration to target systems.
saml2-sample contains example of Spring configuration used for integration to target systems. It also
contains user interface for generation and management of metadata.
saml2-doc contains this documentation.
Configuration of library is done using Spring context XML. An example of configuration can be found
undersaml2-sample/src/main/resources/security/securityContext.xml. Setting up of the library typically
involves these steps:
integration to application using Spring XML configuration
import, generation and customization of SP and IDP metadata
configuration of signature, encryption and trust keys
configuration of security profiles
configuration of reverse proxy or load balancer
configuration of IDP selection or discovery
configuration of single sign-on process
configuration of logout process
configuration of authentication object
configuration of authentiction log
Additional steps such as customization of SAML 2.0 bindings, configuration of artifact resolution or
configuration of time skews might be needed.
Maven dependency
In order to include the library and all it's dependencies add the following dependency to your pom.xml file:
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>${version}</version>
</dependency>
The current version of SAML Extension has been tested to work with Spring 3.1.2, Spring Security 3.1.2
and OpenSAML 2.5.3. Later versions of these libraries are likely to be compatible without modifications.
1.0.0.RC3-SNAPSHOT
10
Bean definitions
Configuration of the SAML library requires beans definitions included in the saml2-sample/src/main/
resources/security/securityContext.xml configuration file. Include copy of the file in your own Spring
application, either directly or with an inclusion. Configuration steps in the following chapters will be
customizing beans included in the default context.
Beans of the SAML library are using auto-wiring and annotation-based configuration by default. Make
sure that your Spring configuration contains e.g. the following settings in order to enable support for
these features:
<context:annotation-config/>
<context:component-scan base-package="org.springframework.security.saml"/>
1.0.0.RC3-SNAPSHOT
11
Filter is automatically invoked as part of the first request to a URL processed by Spring Security. In
case there is no service provider metadata already specified (meaning property hostedSPName of the
metadata bean is empty) filter will generate a new one.
By default metadata will be generated with the following values which can be customized by setting
properties of the metadataGenerator bean:
Table 4.1. Metadata generator settings
Property
Description
Default value
entityBaseURL
entityAlias
defaultAlias
entityId
<entityBaseUrl>/saml/ metadata/
alias/<entityAlias>
requestSigned
Key to include with usage "signing" Default private key from the
in the metadata. Value will be
KeyManager
set in ExtendedMetadata as
signingKey.
encryptionKey
tlsKey
signMetadata
bindingsSSO
1.0.0.RC3-SNAPSHOT
12
Property
Description
Default value
Artifact, POST
bindingsSLO
POST, Redirect
assertionConsumerIndex
Index of assertion consumer point
to be marked as default.
includeDiscovery
customDiscoveryURL
customDiscoveryResponseURL
When
includeDiscoveryExtension
is true value overrides default
discovery response URL.
includeDiscoveryExtension
When true generated metadata will false
contain extension indicating that
it's able to consume response from
an IDP Discovery service.
nameID
1.0.0.RC3-SNAPSHOT
EMAIL, TRANSIENT,
PERSISTENT, UNSPECIFIED,
X509_SUBJECT
13
Property
Description
Default value
Property entityBaseUrl is automatically generated based on values in the first HTTP request,
unless explictly specified in the MetadataGenerator. Generated value can be normalized to exclude
standard 80/443 ports for http/https schemes by setting property normalizeBaseUrl of the
MetadataGeneratorFilter to true.
Providing an empty collection or null value to properties bindingsSSO, bindingsHoKSSO and
bindingsSLO will disable and remove the given profile. For example the following setting removes the
holder-of-key profile from the generated metadata, forces artifact binding for single sign-on and redirect
binding for single logout:
<bean class="org.springframework.security.saml.metadata.MetadataGenerator">
<property name="bindingsSSO"><list><value>artifact</value></list></property>
<property name="bindingsSLO"><list><value>redirect</value></list></property>
<property name="bindingsHoKSSO"><list/></property>
</bean>
By default generated metadata will be digitally signed using the default credential specified in
KeyManager (see Section 4.5, Key management for details). Digital signature can be disabled using
property signMetadata of the metadataGeneratorFilter bean.
In case application is deployed behind a reverse-proxy or other mechanism which makes the URL at
the application server different from the URL seen by client at least property entityBaseURL should
be set to a value e.g. https://www.server.com:8080 For details about load balancing see Section 4.7,
Reverse proxies and load balancers.
Pre-configured metadata
In some situations it is beneficial to provide static version of the metadata document instead of the
automatic generation. Need for manual changes in the metadata or fixing of production settings are
some of those. Custom metadata document describing local SP application can be added by updating
the metadata bean with correct ExtendedMetadata. Please follow these steps in order to do so:
Generate and download metadata, e.g. using the Metadata information -> Generate new service
provider metadata option in the sample application's administration UI or using instructions in the
section called Automatic metadata generation.
Store the metadata file as part of your project classpath, e.g. in WEB-INF/classes/security/
localhost_sp.xml.
Disable the automatic metadata generator by removing the following custom filter from the
securityContext.xml:
1.0.0.RC3-SNAPSHOT
14
Include the SP metadata in the metadata bean and mark the entity as local in the extended metadata.
Make sure to specify the alias property in case it was used during metadata generation.
It is recommended to use the administration UI which also generates all the Spring declarations ready
for inclusion in your securityContext.xml.
<bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate">
<constructor-arg>
<bean class="org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider">
<constructor-arg>
<value type="java.io.File">classpath:security/localhost_sp.xml</value>
</constructor-arg>
<property name="parserPool" ref="parserPool"/>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
<property name="local" value="true"/>
<property name="alias" value="default"/>
<property name="securityProfile" value="metaiop"/>
<property name="sslSecurityProfile" value="pkix"/>
<property name="signingKey" value="apollo"/>
<property name="encryptionKey" value="apollo"/>
<property name="requireArtifactResolveSigned" value="false"/>
<property name="requireLogoutRequestSigned" value="false"/>
<property name="requireLogoutResponseSigned" value="false"/>
<property name="idpDiscoveryEnabled" value="true"/>
<property name="idpDiscoveryURL"
value="https://www.server.com:8080/context/saml/discovery/alias/default"/>
<property name="idpDiscoveryResponseURL"
value="https://www.server.com:8080/context/saml/login/alias/default?disco=true"/>
</bean>
</constructor-arg>
</bean>
Same instance of your application can include multiple statically declared local service providers each
differentiated with it's own unique alias and entity ID. Each service provider can e.g. process a different
domain or have different security key settings. This feature makes it possible to create multi-tenant
applications with individual SAML settings for each of the tenants. In case multiple local SPs are
declared, property hostedSPName of the metadata bean should be set to the entity ID of the default one.
For details about available settings of the ExtendedMetadata see Section A.1, Extended metadata.
Downloading metadata
Metadata describing the default local application can be downloaded from URL:
https://www.server.com:8080/context/saml/metadata
In case application is configured to contain multiple service providers metadata for each can be loaded
by adding the alias:
https://www.server.com:8080/context/saml/login/alias/defaultAlias
1.0.0.RC3-SNAPSHOT
15
URL for metadata download can be disabled by removing filter metadataDisplayFilter from the
securityContext.xml.
Metadata is also available in the sample application's administration UI under Metadata information > selected SP.
1.0.0.RC3-SNAPSHOT
16
Extended metadata
Additional processing instructions related to SAML exchanges with the IDP can be defined in
ExtendedMetadata bean. In case your metadata document contains multiple identity providers (in
multiple EntityDescriptor elements) extended metadata can be set separately for each of them using a
map with entity ids as keys, e.g.:
<bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate">
<constructor-arg>
metadata provider bean
</constructor-arg>
<constructor-arg>
<!-- Default extended metadata for entities not specified in the map -->
<bean class="org.springframework.security.saml.metadata.ExtendedMetadata"/>
</constructor-arg>
<constructor-arg>
<!-- Extended metadata for specific IDPs -->
<map>
<entry key="http://idp.ssocircle.com">
<bean class="org.springframework.security.saml.metadata.ExtendedMetadata"/>
</entry>
</map>
</constructor-arg>
</bean>
For details about available settings of the ExtendedMetadata see Section A.1, Extended metadata.
1.0.0.RC3-SNAPSHOT
17
Default implementation relies on a single JKS key store which contains all private and public keys.
KeyManager must contain at least one private key which should be marked as default by using the alias
of the private key as part of the KeyManager constructor.
Make sure that your configuration of SAML module contains bean keyManager with your custom key
store and passwords.
Sample keystore
Sample application contains a default key store with a sample private certificate usable for test purposes.
The key store is defined as:
<bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager">
<constructor-arg value="classpath:security/samlKeystore.jks"/>
<constructor-arg type="java.lang.String" value="nalle123"/>
<constructor-arg>
<map>
<entry key="apollo" value="nalle123"/>
</map>
</constructor-arg>
<constructor-arg type="java.lang.String" value="apollo"/>
</bean>
The first argument points to the used key store file, second contains password for the keystore, third
then map with passwords for private keys with alias-password value pairs. Alias of the default certificate
is the last parameter.
The keystore will now contain additional PrivateKeyEntry with alias mykey which can be imported to the
keyManager in your securityContext.xml.
Keys signed by certification authorities are typically provided in .p12/.pfx format (or can be converted to
such using OpenSSL) and imported to Java keystore with, e.g.:
keytool -importkeystore -srckeystore key.p12 -srcstoretype PKCS12 -srcstorepass password \
-alias some-alias -destkeystore samlKeystore.jks -destalias some-alias -destkeypass
changeit
The following command can be used to determine available alias in the p12 file:
keytool -list -keystore key.p12 -storetype pkcs12
1.0.0.RC3-SNAPSHOT
18
The certificates are stored as .cer files and can be imported to the keystore as a usual public key. For
details about configuring of trust for SSL/TLS connections see Section 4.6, Security profiles.
1.0.0.RC3-SNAPSHOT
19
PKIX profile
With PKIX profile trust of signature certificates is verified based on a certificate path between trusted
CA certificates and the certificate in question. Certificate is trusted when it's possible to construct path
from a trusted certificate to the validated one. With this profile certificate expiration and revocation can
be checked.
Trusted keys (anchors) for PKIX verification of signatures are combined from the following places:
Key with usage of signing or unspecified in entity metadata of a remote entity
Signing key specified in property signingKey of extended metadata of a remote entity
All keys specified in trustedKeys set of extended metadata of a remote entity
Custom profile
Engine used to verify trust of signatures for given combination of SP/IDP
is created in methods populateTrustEngine and populateSSLTrustEngine of interface
org.springframework.security.saml.context.SAMLContextProvider and can be overriden with custom
implementation. See Section 4.13, Context provider for details on context customization.
This setting enables extension to correctly form all generated URLs and verify endpoints of the
incoming SAML messages.
1.0.0.RC3-SNAPSHOT
20
In case you use automatically generated metadata make sure to configure entityBaseUrl matching
the front-end URL in your metadataGeneratorFilter bean:
<bean id="metadataGeneratorFilter"
class="org.springframework.security.saml.metadata.MetadataGeneratorFilter">
<constructor-arg>
<bean class="org.springframework.security.saml.metadata.MetadataGenerator">
<property name="entityBaseURL" value="https://www.myserver.com/spring-security-saml2sample"/>
</bean>
</constructor-arg>
</bean>
1.0.0.RC3-SNAPSHOT
21
1.0.0.RC3-SNAPSHOT
22
Value
Principal
Principal
Principal
Credentials
SAML authentication object including entity ID of local and remote entity, name ID,
assertion and relay state (org.springframework.security.saml.SAMLCredential)
Authorities
Expiration
org.opensaml.saml2.core.Attribute;
org.opensaml.xml.XMLObject;
org.springframework.security.core.userdetails.UsernameNotFoundException;
org.springframework.security.saml.SAMLCredential;
org.springframework.security.saml.userdetails.SAMLUserDetailsService;
Population of the authentication object can be further customized by overriding of the getUserDetails,
getPrincipal, getEntitlements and getExpirationDate methods in the SAMLAuthenticationProvider.
1.0.0.RC3-SNAPSHOT
23
1.0.0.RC3-SNAPSHOT
24
Load parameter idp of the HttpRequest object and try to locate peer IDP by the entityId. When
there's no idp parameter provided system will either start IDP discovery process (when enabled in
the ExtendedMetadata of the local SP) or use the default IDP specified in the metadata bean.
1.0.0.RC3-SNAPSHOT
25
1.0.0.RC3-SNAPSHOT
26
Initialize SP metadata
Deploy SAML 2 Extension war archive from saml2-sample/target/spring-security-saml2-sample.war
Open browser at e.g. https://server:port/spring-security-saml2-sample, make sure to use HTTPS
protocol, system will automatically generate metadata document
Click Metadata information, select item with your server name in the Service providers list
Store content of the Metadata field to a document metadata.xml and upload it to the AD FS server
In AD FS 2.0 Management Console select "Add Relying Party Trust"
Select "Import data about the relying party from a file" and select file created earlier, select Next
1.0.0.RC3-SNAPSHOT
27
System may complain that some content of metadata is not supported, you can safely ignore this
warning
Continue with the wizard, on the "Ready to Add Trust" make sure that tab endpoints contains multiple
endpoing values, if not verify that your metadata was generated with https protocol in their URLs
Leave "Open the Edit Claim Rules dialog" checkbox checked and finish the wizard
Select "Add Rule", choose "Send LDAP Attributes as Claims" and press Next
Add NameID as "Claim rule name", choose "Active Directory" as Attribute store, choose "SAMAccount-Name" as LDAP Attribute and "Name ID" as "Outgoing claim type", finish the wizard and
confirm the claim rules window
Open the provider by double-clicking it, select tab Advanced and change "Secure hash algorithm"
to SHA-1
Test SSO
Open SAML Extension at https://localhost:8443/spring-security-saml2-sample, select your AD FS
server and press login. In case Artifact binding is used and SSL/TLS certificate of your AD FS is not
already trusted you have to import it to your samlKeystore.jks by following instructions in the error report.
1.0.0.RC3-SNAPSHOT
28
7. Troubleshooting
7.1 Logging
SAML Extension uses SLF4J framework for logging. The same applies to the underlaying OpenSAML
library. The sample application by default uses log4j version 1.2 binding for SLF4J.
You can enable debug logging by modifying file saml2-sample/src/main/resources/log4j.properties and
adding:
log4j.logger.org.springframework.security.saml=DEBUG
log4j.logger.org.opensaml=DEBUG
log4j.logger.PROTOCOL_MESSAGE=DEBUG
For details about using other logging frameworks please consult the SLF4J manual.
1.0.0.RC3-SNAPSHOT
29
1.0.0.RC3-SNAPSHOT
30
Default
Entities
Description
local
false
local
and
remote
alias
defaultAlias
local
only
idpDiscoveryEnabled
false
local
only
idpDiscoveryURL
internal local
discovery only
URL
idpDiscoveryResponseURL
internal local
discovery only
URL
ecpEnabled
false
local
only
securityProfile
metaiop
local
only
sslSecurityProfile
pkix
local
only
signingKey
local
and
remote
1.0.0.RC3-SNAPSHOT
31
Property
Default
Entities
Description
identity providers defines an additional public
key used to verify signatures.
encryptionKey
local
and
remote
tlsKey
local
and
remote
trustedKeys
remote
requireLogoutRequestSigned true
local
and
remote
requireLogoutResponseSigned false
local
and
remote
requireArtifactResolveSigned true
remote
only
Description
binding
providerName
Default: empty. Human readable name of the local SP sent with the
authentication request.
1.0.0.RC3-SNAPSHOT
32
Property
Description
assertionConsumerIndex
nameID
allowCreate
passive
Default: false. Sets whether the IdP should refrain from interacting with
the user during the authentication process.
forceAuthn
includeScoping
allowedIDPs
proxyCount
authnContexts
authnContextComparison
Default: AuthnContextComparisonTypeEnumeration.EXACT.
Mechanism used by IDP to determine authentication method to use.
See the specification for details.
relayState
1.0.0.RC3-SNAPSHOT
33