Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Chapter 9. The Security Token Service
Abstract
9.1. STS Architecture Copy linkLink copied to clipboard!
9.1.1. Overview of the STS Copy linkLink copied to clipboard!
Architecture Copy linkLink copied to clipboard!
Figure 9.1. STS Architecture
STS WSDL Copy linkLink copied to clipboard!
- Logical part of the WSDL—consists of WSDL type definitions and the STS WSDL port type. In other words, this part of the WSDL provides an abstract definition of the STS interface.The logical part is defined exactly in the WSDL appendix of the WS-Trust specification.
- Physical part of the WSDL—consists of the WSDL binding and WSDL service definitions. In other words, this part of the WSDL specifies the details of the message encoding and the transport protocol used to access the STS.In contrast to the logical part, the physical part of the WSDL can be customized, enabling you to choose what kind of protocol to use when accessing the STS. The most common choice is SOAP/HTTP, but in principle you could use other SOAP-compatible transports supported by Apache CXF—for example, SOAP/JMS.
STS operations Copy linkLink copied to clipboard!
- Issue binding—the specification defines this binding as follows: Based on the credential provided/proven in the request, a new token is issued, possibly with new proof information.
- Validate binding—the specification defines this binding as follows: The validity of the specified security token is evaluated and a result is returned. The result may be a status, a new token, or both.
- Renew binding—the specification defines this binding as follows: A previously issued token with expiration is presented (and possibly proven) and the same token is returned with new expiration semantics.
- Cancel binding—the specification defines this binding as follows: When a previously issued token is no longer needed, the Cancel binding can be used to cancel the token, terminating its use.
- Key Exchange Token binding (not supported)—in the context of the WS-Trust negotiation and challenge extensions, this binding is used for requesting a new Key Exchange Token.
- RequestCollection binding (not supported)—similar to the Issue binding, except that it allows you to request multiple tokens in a single operation (the request message is a
wst:RequestSecurityTokenCollectionelement, which consists of a list ofwst:RequestSecurityTokenelements).
STS policies Copy linkLink copied to clipboard!
Abstract STS provider framework Copy linkLink copied to clipboard!
SecurityTokenServiceProvider class from the org.apache.cxf.ws.security.sts.provider package, which provides the Java implementation of the STS WSDL interface.
IssueOperationIssueSingleOperationValidateOperationRenewOperationCancelOperation
SecurityTokenServiceProvider instance, you can customize the implementation of each STS operation.
TokenIssueOperation class Copy linkLink copied to clipboard!
TokenIssueOperation class from the org.apache.cxf.ws.security.sts.operation package is the default implementation of the Issue operation.
TokenIssueOperation instance, you would normally just provide it with a reference to a SAMLTokenProvider instance (which enables it to issue SAML tokens). For details, see Section 9.1.3, “Customizing the Issue Operation”.
TokenValidateOperation class Copy linkLink copied to clipboard!
TokenValidateOperation class from the org.apache.cxf.ws.security.sts.operation package is the default implementation of the Validate operation.
TokenValidateOperation instance, you need to provide it with a list of token validators. For details, see Section 9.1.4, “Customizing the Validate Operation”.
TokenCancelOperation class Copy linkLink copied to clipboard!
TokenCancelOperation class from the org.apache.cxf.ws.security.sts.operation package is the default implementation of the Cancel operation.
TokenCancelOperation instance, you need to provide it with a list of cancellers. At the moment, only the SCTCanceller canceller is available, which is used for cancelling Security Context Tokens in the context of secure conversations (WS-SecureConversation specification). For details, see Section 9.1.4, “Customizing the Validate Operation”.
9.1.2. Customizing the STS WSDL Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
- Address of the STS WSDL port—the host, IP port, and context path of the STS Web service endpoint can be customized by editing the address attribute of the WSDL port.NoteMoreover, it is possible to define multiple Web service ports for a single STS, where each port can specify a different address and different WS policies.
- WS security policies—you can customize the WS security policies that apply to the STS WSDL binding. For example, you can choose between a symmetric, asymmetric, or transport binding and you can choose how clients authenticate themselves to the STS.
WSDL types and portType Copy linkLink copied to clipboard!
- Request message types—are either:
RequestSecurityToken(RST) type, for theIssue,Renew,Validate,Cancel, andKeyExchangeTokenoperations; orRequestSecurityTokenCollectiontype, for theRequestCollectionoperation.
- Response message types—are either:
RequestSecurityTokenResponse(RSTR) type, for theRenew,Validate,Cancel, andKeyExchangeTokenoperations; orRequestSecurityTokenResponseCollectiontype, for theIssueandRequestCollectionoperations.
CXFInstallDir/samples/sts/wsdl/ws-trust-1.4-service.wsdl
CXFInstallDir/samples/sts/wsdl/ws-trust-1.4-service.wsdl
Choosing a WSDL binding Copy linkLink copied to clipboard!
- SOAP/HTTP (either SOAP 1.1 or SOAP 1.2)
- SOAP/JMS
SOAP/HTTP binding Copy linkLink copied to clipboard!
wsdl:binding element) and a HTTP port (defined by the wsdl:service element):
soap:binding element is used to specify that this is a SOAP binding and the transport attribute identifies the transport type as HTTP. Inside the wsdl:port element, the location attribute of the soap:address element specifies the URL that is used to access the STS.
Choosing policies Copy linkLink copied to clipboard!
- Transport binding—security is provided by the HTTPS transport (that is, in the SSL/TLS layer). In this case, an initiator (for example, a WS client) authenticates itself by providing either of the following credentials:
- X.509 certificate (sent through the SSL/TLS layer, during the TLS security handshake), or
- WSS UsernameToken (sent through the SOAP layer, in a SOAP security header)
- Symmetric binding—security is provided at the SOAP layer. An initiator must authenticate itself by providing WSS UsernameToken credentials.
- Asymmetric binding—security is provided at the SOAP layer. An initiator must authenticate itself by providing an X.509 certificate.
Inserting policy references Copy linkLink copied to clipboard!
wsp:PolicyReference element, which references the relevant WS policy (see Policies and policy references). The following extract from the STS WSDL shows how to apply policies to the SOAP/HTTP binding:
wsp:PolicyReference element applies the UT_Policy policy (in the sample/sts demonstration, this is a symmetric binding policy) to the SOAP binding. This implies that the policy applies to all endpoints that use this SOAP binding.
wsp:PolicyReference element applies the Input_policy policy to the Issue operation's request message, and the third wsp:PolicyReference element applies the Output_policy policy to the Issue operation's response message. The Input_policy policy and the Output_policy policy are used to specify which parts of the SOAP messages to protect (see Specifying Parts of Message to Encrypt and Sign).
Example of SymmetricBinding and UsernameToken policy Copy linkLink copied to clipboard!
9.1.3. Customizing the Issue Operation Copy linkLink copied to clipboard!
TokenIssueOperation Copy linkLink copied to clipboard!
TokenIssueOperation class provides the overall coordination of the token issuing process. There are some important aspects of a TokenIssueOperation instance that can be customized. In particular, because the TokenIssueOperation instance delegates token generation to token providers—where each token provider is capable of generating a particular kind of token—the token provider beans play a particularly important role in issuing tokens.
Figure 9.2. Configuring TokenIssueOperation
Plug-in framework Copy linkLink copied to clipboard!
TokenIssueOperation has a modular structure. You can inject various plug-ins into the TokenIssueOperation instance in order to customize the behavior of the Issue operation. The following properties can be set on the TokenIssueOperation class:
tokenProviders- Specifies a list of token providers, where each token provider is capable of generating tokens of a specific type. Whenever an STS client asks the Issue operation to issue a token of a specific type, the
TokenIssueOperationclass iterates over all of the token providers specified by this property, asking each of them whether they can handle the required token type (by invoking thecanHandle()method on each token provider).The available token providers are described in the section called “Token providers”. stsProperties- References a bean that encapsulates generic configuration properties for the STS (normally an instance of
StaticSTSProperties). This configuration data mainly consists of the details needed to access a signing certificate and an encrypting certificate. services- Specifies a list of known services and their corresponding token requirements. This property must be set, if you want to support the
AppliesTopolicy in a token request. For details, see Section 9.4, “Enabling AppliesTo in the STS”. encryptIssuedToken- Specifies whether or not to encrypt an issued token. Default is
false.If you enable this option, you must also associate an encryption key with theTokenIssueOperation, through the properties defined on theStaticSTSPropertiesinstance—see the section called “Encrypting key”
Token providers Copy linkLink copied to clipboard!
SAMLTokenProvider Copy linkLink copied to clipboard!
SAMLTokenProvider token provider is used to generate SAML tokens. This is the most commonly used token provider.
SAMLTokenProvider instance is triggered to issue a token, if the token type specified by the requesting STS client is one of the following:
| Token Type URIs handled by the SAMLTokenProvider |
|---|
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1 |
urn:oasis:names:tc:SAML:1.0:assertion |
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0 |
urn:oasis:names:tc:SAML:2.0:assertion |
SAMLTokenProvider class comes pre-configured with sensible default behaviors, so it is normally acceptable to instantiate it without setting any of its properties. If you want to customize its behavior, however, you can set some or all of the following properties:
attributeStatementProviders- You can optionally use this property to add attribute statement providers, if you want to define your own custom attribute statements in the generated SAML token. If this property is not set, the
DefaultAttributeStatementProviderclass is automatically invoked, which generates the following attribute statements:- An attribute statement that confirms the SAML token has been authenticated.
- An attribute statements containing a username, if an
OnBehalfOfelement or anActAselement containing aUsernameTokenwas present in the Issue request. - An attribute statements containing a subject name, if an
OnBehalfOfelement or anActAselement containing a SAML token was present in the Issue request.
authenticationStatementProviders- You can optionally add authentication statement providers, if you want to define your own custom authentication statements in the generated SAML token. No authentication statements are added by default.
authDecisionStatementProviders- You can optionally add authorization decision statement providers, if you want to define your own custom authorization decision statements in the generated SAML token. No authorization decision statements are added by default.
subjectProvider- You can optionally set this property to define a custom SAML subject provider.If this property is not set, the
DefaultSubjectProviderclass is automatically invoked. The default implementation automatically populates the SAML subject with all of the fields needed to support the standard scenarios: Holder-of-Key withSymmetricKey; Holder-of-Key withPublicKeyalgorithm; andBearer. conditionsProvider- You can optionally set this property to define a custom conditions provider.If this property is not set, the
DefaultConditionsProviderclass is automatically invoked. The default implementation applies a default lifetime of five minutes to the token and sets the audience restriction URI to the value of the receivedAppliesToaddress (if any). signToken- Specifies whether or not to sign the SAML token. Default is
true. realmMap- Specifies a map that associates realm names with
SAMLRealmobjects. Only required, if you want to enable support for realms. For details, see Section 9.5, “Enabling Realms in the STS”.
SCTProvider Copy linkLink copied to clipboard!
SCTProvider token provider is used to generate security context tokens, which you only need if you are using the WS-SecureConversation protocol.
SCTProvider instance is triggered to issue a token, if the token type specified by the requesting STS client is one of the following:
| Token Type URIs handled by the SCTProvider |
|---|
http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512/sct |
http://schemas.xmlsoap.org/ws/2005/02/sc/sct |
SCTProvider instance:
lifetime- Specifies the lifetime of the generated security context token. Default is five minutes.
returnEntropy- Specifies whether to return entropy to the STS client. Default is
true.
Sample configuration of SAMLTokenProvider Copy linkLink copied to clipboard!
TokenIssueOperation class is configured to use a SAMLTokenProvider token provider.
Example 9.1. Configuring the STS Issue Operation
9.1.4. Customizing the Validate Operation Copy linkLink copied to clipboard!
TokenValidateOperation Copy linkLink copied to clipboard!
TokenValidateOperation class provides the overall coordination of the token validation process. The TokenValidateOperation instance delegates token validation to token validators—where each token validator is capable of validating a particular kind of token.
TokenValidateOperation class can also support token transformation and this capability is discussed in detail in the context of realms, Section 9.5.3, “Token Transformation across Realms”.
Figure 9.3. Configuring TokenValidateOperation
Plug-in framework Copy linkLink copied to clipboard!
TokenValidateOperation instance in order to customize the behavior of the Validate operation. The following properties can be set on the TokenValidateOperation class:
tokenValidators- Specifies a list of token validators, where each token validator is capable of validating tokens of a specific type. Whenever an STS client asks the Validate operation to validate a token of a specific type, the
TokenValidateOperationclass iterates over all of the token validators specified by this property, asking each of them whether they can handle the required token type (by invoking thecanHandle()method on each token validator).The available token validators are described in the section called “Token validators”. stsProperties- References a bean that encapsulates generic configuration properties for the STS (normally an instance of
StaticSTSProperties). This configuration data mainly consists of the details needed to access a signing certificate and an encrypting certificate. services- (Only relevant, if token transformation is requested) Specifies a list of known services and their corresponding token requirements. This property must be set, if you want to support the
AppliesTopolicy in a token request. For details, see Section 9.4, “Enabling AppliesTo in the STS”. tokenProviders- (Only relevant, if token transformation is requested) Specifies a list of token providers, where each token provider is capable of generating tokens of a specific type.For details of token transformation, see Section 9.5.3, “Token Transformation across Realms”.
Token validators Copy linkLink copied to clipboard!
SAMLTokenValidator Copy linkLink copied to clipboard!
SAMLTokenValidator instance is triggered to validate a token, if the received token is a SAML assertion and its token type is one of the following:
| Token Type URIs handled by the SAMLTokenValidator |
|---|
urn:oasis:names:tc:SAML:1.0:assertion |
urn:oasis:names:tc:SAML:2.0:assertion |
SAMLTokenValidator class uses the following algorithm to validate the received SAML token:
- The SAML assertion is first checked, to ensure that it is well-formed.
- If the assertion is not signed, it is rejected.
- The signature is checked, using the X.509 certificate embedded in the assertion's signature. If the signature is verified, this proves that whoever signed the SAML token is in possession of the private key corresponding to the embedded X.509 certificate.
- The embedded X.509 certificate is checked to make sure that it is trusted. The validator looks up the trusted certificates stored in the STS properties signature trust store (as configured by the
signaturePropertiesFileproperty or thesignatureCryptoproperty on theStaticSTSPropertiesobject—see Section 9.1.6, “Configuring STS Properties”) and checks that the certificate is either present in the trust store or is signed by a private key corresponding to one of the certificates in the trust store (certificate chaining). - If the
subjectConstraintsproperty is set on theSAMLTokenValidatorinstance, the validator checks that the Subject DN string from the embedded X.509 certificate matches one of the specified regular expressions. If there is no match, the SAML assertion is rejected.This optional feature gives you more fine-grained control over which signing certificates to trust.
SAMLTokenValidator is made indirectly, by specifying the signature trust store for the parent TokenValidateOperation instance. The signature trust store is usually configured by setting the signaturePropertiesFile property on the StaticSTSProperties bean, and then injecting the StaticSTSProperties bean into the TokenValidateOperation instance. For example, see Example 9.2, “Configuring the STS Validate Operation”.
SAMLTokenValidator class, you can set some or all of the following properties:
subjectConstraints- Specifies a list of regular expression strings. If this property is set, the subject DN extracted from the X.509 embedded in the SAML assertion must match one of the specified regular expressions. If this property is not set, no test is applied to the subject DN.
validator- You can optionally set this property to customize the step that checks whether or not the embedded X.509 certificate is trusted or not. By default, the WSS4J
SignatureTrustValidatorclass is used. samlRealmCodec- If you want to use realms with SAML tokens, you must implement the
SAMLRealmCodecinterface and inject an instance into this property. The purpose of the SAML realm codec is to assign a realm to the SAML token, based on the contents of the SAML assertion. No SAML realm codec is set by default.For more details about using realms with the STS, see Section 9.5, “Enabling Realms in the STS”.
UsernameTokenValidator Copy linkLink copied to clipboard!
UsernameTokenValidator instance is triggered to validate a token, if the received token can be parsed as a UsernameToken.
UsernameTokenValidator- (Default) This WSS4J validator implementation uses a
CallbackHandlerobject to look up passwords, where the callback handler, is specified by setting thecallbackHandlerproperty on theStaticSTSPropertiesobject—see Section 9.1.6, “Configuring STS Properties”.To use this validator, you must provide your ownCallbackHandlerimplementation. For example, see the section called “STS callback handler ” JAASUsernameTokenValidator- This WSS4J validator implementation integrates password lookup with JAAS, so that the UsernameToken credentials are checked using a JAAS login module. In particular, by configuring an appropriate JAAS login module, you could integrate the UsernameToken validator with an LDAP database.To use this token validator, create an instance of
JAASUsernameTokenValidatorand inject it into thevalidatorproperty of theUsernameTokenValidatorbean.
UsernameTokenRealmCodec interface and registering it with the UsernameTokenValidator bean—for details, see Section 9.5, “Enabling Realms in the STS”.
X509TokenValidator Copy linkLink copied to clipboard!
X509TokenValidator instance is triggered to validate a token, if the received token can be parsed as a BinarySecurityToken type.
BinarySecurityToken in Base-64 encoding) consists of checking that the received certificate is trusted.
X509TokenValidator class is the WSS4J SignatureTrustValidator, which checks that the X.509 certificate is either present in the trust store or is signed by a private key corresponding to one of the certificates in the trust store (certificate chaining). The trust store that is used for this purpose is the signature trust store on the StaticSTSProperties object—see Section 9.1.6, “Configuring STS Properties”.
SCTValidator Copy linkLink copied to clipboard!
SCTValidator instance is triggered to validate a token, if the received token can be parsed as a SecurityContextToken type and belongs to one of the following namespaces:
| Namespaces handled by SCTValidator |
|---|
http://schemas.xmlsoap.org/ws/2005/02/sc |
http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512 |
SCTValidator is used to validate security context tokens in the context of WS-SecureConversation sessions, which is currently not covered by this documentation.
Sample configuration Copy linkLink copied to clipboard!
TokenValidateOperation class is configured to use a SAMLTokenValidator token validator.
Example 9.2. Configuring the STS Validate Operation
9.1.5. Customizing the Cancel Operation Copy linkLink copied to clipboard!
TokenCancelOperation Copy linkLink copied to clipboard!
Figure 9.4. Configuring TokenCancelOperation
Plug-in framework Copy linkLink copied to clipboard!
TokenCancelOperation class:
tokencancellers- Specifies a list of token cancellers, where each token canceller is capable of canceling tokens of a particular type. Currently, the only token canceller implementation provided is the
SCTCanceller, for canceling WS-SecureConversation tokens.
SCTCanceller Copy linkLink copied to clipboard!
SCTCanceller token canceller is used in the context of WS-SecureConversation to cancel security context tokens.
SCTCanceller instance is triggered to cancel a token, if the token namespace specified by the requesting STS client is one of the following:
| Namespaces handled by the SCTCanceller |
|---|
http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512 |
http://schemas.xmlsoap.org/ws/2005/02/sc |
SCTCanceller instance:
verifyProofOfPossession- When the
verifyProofOfPossessionflag is enabled, only the owner of the security context token is allowed to cancel the token. To prove possession of the token, the client must demonstrate that it knows the secret key associated with the security context token. The client demonstrates knowledge of the key by signing some part of the SOAP message using the secret key.Default istrue.
Sample configuration of SCTCanceller Copy linkLink copied to clipboard!
TokenCancelOperation class is configured to use an SCTCanceller token canceller.
Example 9.3. Configuring the STS Cancel Operation
9.1.6. Configuring STS Properties Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
StaticSTSProperties instance (which implements the STSPropertiesMBean interface) and can be injected into the various operation implementations (TokenIssueOperation, TokenValidateOperation, and so on).
What you can configure with STS properties Copy linkLink copied to clipboard!
Issuer Copy linkLink copied to clipboard!
Callback handler Copy linkLink copied to clipboard!
javax.security.auth.callback.CallbackHandler interface. The purpose of the callback handler is to provide any passwords required by the STS. In particular, the callback handler is normally used to provide the password to access the STS signing key.
Signing key Copy linkLink copied to clipboard!
signatureCrypto- Specifies the signing key directly as an
org.apache.ws.security.components.crypto.Cryptoinstance. This is the most flexible way of configuring the signing key, but also the most complicated. ThesignaturePropertiesFileproperty offers an easier alternative for specifying the signing key. signaturePropertiesFile- Specifies the location of a file containing WSS4J keystore properties, that provide access to the signing key in a Java keystore file. For details of the WSS4J keystore properties that you can set in this file, see Table 6.2.
signatureUsername- Specifies the alias of the signing key in the specified Java keystore.
signatureProperties- (Optional) By injecting an
org.apache.cxf.sts.SignaturePropertiesinstance into this property, you can fine-tune the signing algorithm used by the STS.
signaturePropertiesFile property, where the private key with the alias, mystskey, is selected from the specified Java keystore.
stsKeystore.properties file typically contains WSS4J keystore properties like the following:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin org.apache.ws.security.crypto.merlin.keystore.type=jks org.apache.ws.security.crypto.merlin.keystore.password=stsspass org.apache.ws.security.crypto.merlin.keystore.file=keys/stsstore.jks
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=stsspass
org.apache.ws.security.crypto.merlin.keystore.file=keys/stsstore.jks
stsstore.jks Java keystore file and the stsspass password unlocks the keystore file.
Encrypting key Copy linkLink copied to clipboard!
encryptIssuedToken option is set to true on the TokenIssueOperation instance—see Section 9.1.3, “Customizing the Issue Operation”.
encryptionCrypto- Specifies the encryption key directly as an
org.apache.ws.security.components.crypto.Cryptoinstance. This is the most flexible way of configuring the encryption key, but also the most complicated. TheencryptionPropertiesFileproperty offers an easier alternative for specifying the encryption key. encryptionPropertiesFile- Specifies the location of a file containing WSS4J keystore properties, that provide access to the encryption key in a Java keystore file. For details of the WSS4J keystore properties that you can set in this file, see Table 6.2.
encryptionUsername- Specifies the alias of the encryption key in the specified Java keystore.
encryptionProperties- (Optional) By injecting an
org.apache.cxf.sts.service.EncryptionPropertiesinstance into this property, you can fine-tune the encryption algorithm used by the STS.
Realm settings Copy linkLink copied to clipboard!
realmParser- (Optional) In the context of enabling realms in the STS, you would inject an
org.apache.cxf.sts.RealmParserinstance into this property, to give STS the ability to decide which realm the current token should be issued in. For more details, see Section 9.5.1, “Issuing Tokens in Multiple Realms”. identityMapper- (Optional) In the context of token transformation in the STS, you would inject an
org.apache.cxf.sts.IdentityMapperinstance into this property, which has the capability to map a principal in the context of one realm to the corresponding principal in the context of another realm. For more details, see Section 9.5.3, “Token Transformation across Realms”.