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.Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
9.5. Enabling Realms in the STS
9.5.1. Issuing Tokens in Multiple Realms Link kopierenLink in die Zwischenablage kopiert!
Overview Link kopierenLink in die Zwischenablage kopiert!
Figure 9.11. Realm-Aware SAML Token Issuer
Realm aware token issuing steps Link kopierenLink in die Zwischenablage kopiert!
- When a realm-aware STS receives an issue token request, it tries to find out what realm to issue the token in, by calling out to the realm parser instance.WS-Trust does not define a standard way to associate a token with a realm. Hence, you must work out your own approach for indicating the realm and codify this approach by providing a custom implementation of the
RealmParserinterface. The realm parser'sparseRealmmethod returns a string, which is the name of the realm to issue the token in.For example, you could identify the realm, by inspecting the URL of the STS Web service endpoint that was invoked. The pathname of the URL could include a segment that identifies the realm. - The
TokenIssueOperationinstance then calls thecanHandleTokenmethod on each of the registered token providers. In this example, only theSAMLTokenProvidertoken provider is registered. ThecanHandleTokenmethod parameters include the token type and the realm name. - Assuming that the token type matches (for example, the client is requesting a SAML token), the
SAMLTokenProviderlooks up the realm name in its realm map to make sure that it can handle this realm. If theSAMLTokenProviderfinds the realm name in its map, it returnstruefrom thecanHandleTokenmethod. - The
TokenIssueOperationinstance now calls thecreateTokenmethod on theSAMLTokenProviderinstance, in order to issue the token in the specified realm. - The
SAMLTokenProviderlooks up the specified realm in the realm map and retrieves the correspondingSAMLRealminstance. TheSAMLRealminstance encapsulates the data that is specific to this realm.For example, if the specified realm isA, theSAMLRealminstance records that the corresponding issuer name isA-Issuerand the alias of the signing key to use for this realm isStsKeyA. - The
SAMLTokenProvidernow uses the realm-specific data in combination with the generic data from the STS properties instance to issue the SAML token in the specified realm.For example, if the specified realm isA, theSAMLTokenProviderembeds theA-Issuerstring in the SAML token's issuer element and the SAML token is signed using theStsKeyAprivate key from thestsstore.jksJava keystore file.
Configuring the realm parser Link kopierenLink in die Zwischenablage kopiert!
RealmParser interface and then register your custom realm parser by injecting it into the realmParser property of the STS properties bean.
URLRealmParser instance with the StaticSTSProperties bean as follows:
Sample URL realm parser Link kopierenLink in die Zwischenablage kopiert!
RealmParser interface:
public String parseRealm(WebServiceContext context) throws STSException;
public String parseRealm(WebServiceContext context) throws STSException;
parseRealm passes an instance of javax.xml.ws.WebServiceContext, which provides access to message context and security information about the current request message (issue token request). You can use this message context information to identify the current realm.
URLRealmParser used in the previous example works by examining the URL of the invoked STS Web service endpoint and checking whether any known realm names are embedded in the URL. The realm name embedded in the URL is then taken to be the realm to issue the token in and the realm is then returned from the parseRealm method.
null return value indicates that the STS should use the default realm (as defined by the issuer and signatureUsername properties of the STS properties bean).
Configuring the realm map Link kopierenLink in die Zwischenablage kopiert!
SAMLTokenProvider token provider must be initialized with a realm map, which provides the requisite data about each realm. For example, the scenario shown in Figure 9.11, “Realm-Aware SAML Token Issuer” uses a realm map like the following:
9.5.2. Validating Tokens in Multiple Realms Link kopierenLink in die Zwischenablage kopiert!
Overview Link kopierenLink in die Zwischenablage kopiert!
Figure 9.12. Realm-Aware SAML Token Validation
Realm aware token validating steps Link kopierenLink in die Zwischenablage kopiert!
- When a realm-aware STS receives a validate token request, it tries to find out what realm to issue the token in, by calling out to the realm parser instance.NoteThe realm identified by the realm parser in this step is not necessarily the same realm that the token was originally issued in. See the section called “Validating tokens across realms”.
- The
TokenValidateOperationinstance then calls thecanHandleTokenmethod on each of the registered token validators. In this example, only theSAMLTokenValidatortoken validator is registered. ThecanHandleTokenmethod parameters include the token type and the realm name.NoteThe defaultSAMLTokenValidatorclass ignores the realm parameter in thecanHandleTokenmethod, so it will attempt to validate the token in any realm. If you need to implement realm-specific validation steps, however, you have the option of implementing a custom SAML token validator that pays attention to the realm parameter. - The
TokenValidateOperationinstance then calls thevalidateTokenmethod on theSAMLTokenValidator, in order to validate the token in the specified realm. - The
SAMLTokenValidatorattempts to validate the received SAML token by checking whether it has been signed by a trusted key. The public part of the signing key pair must match one of the trusted certificates stored in the signature trust store (as configured by thesignaturePropertiesFileproperty in the STS properties instance).Hence, for each of the supported realms, the public part of the realm's signing key must be present in the signature trust store (or at least one of the certificate's in that realm's trust chain). Otherwise, theSAMLTokenValidatorwill not be able to validate tokens that were issued in that realm.For example, if you want to be able to validate tokens in the realms,A,B, andC, you must store the corresponding certificates (public part of the signature keys),StsKeyA,StsKeyB, andStsKeyC, in thestsstore.jksJava keystore file. - In case the client needs the information, the
SAMLTokenValidatoralso embeds the name of the realm where the token was originally issued into the Validate response message. This is not necessarily the same realm as the realm that the token has just been validated in.To find the original realm that the token was issued in, theSAMLTokenValidatorcalls out to the customSAMLRealmCodecinstance. TheSAMLRealmCodecinstance tries to figure out the issuing realm by examining the token contents. If the issuing realm can be established, this information is included in the Validate response message.
Configuring the realm parser Link kopierenLink in die Zwischenablage kopiert!
Validating tokens across realms Link kopierenLink in die Zwischenablage kopiert!
Response from Validate operation Link kopierenLink in die Zwischenablage kopiert!
SAMLTokenValidator can be configured to discover the token's issuing realm and embed this information in the Validate operation's response. To give the SAMLTokenValidator the ability to discover the token's issuing realm, you must implement and register a SAMLRealmCodec instance.
Configuring the SAMLRealmCodec Link kopierenLink in die Zwischenablage kopiert!
IssuerSAMLRealmCodec instance, which implements the SAMLRealmCodec interface:
Sample implementation of SAMLRealmCodec Link kopierenLink in die Zwischenablage kopiert!
public String getRealmFromToken(AssertionWrapper assertion)
public String getRealmFromToken(AssertionWrapper assertion)
assertion parameter holds the contents of the SAML token. The assumption made here is that the realm name is either embedded in the SAML token somehow or the identity of the realm can somehow be inferred from the SAML token contents. For example, the SAML issuer name can typically be identified with a security realm.
IssuerSAMLRealmCodec, which infers the realm name from the value of the issuer string:
9.5.3. Token Transformation across Realms Link kopierenLink in die Zwischenablage kopiert!
Overview Link kopierenLink in die Zwischenablage kopiert!
Triggering token transformation Link kopierenLink in die Zwischenablage kopiert!
jaxws:endpoint element are of key importance in configuring token transformation:
ws-security.saml2.validator- By initializing this property with an instance of the
STSTokenValidatorclass, you are instructing the JAX-WS endpoint to validate incoming tokens by contacting the STS and invoking the Validate operation. ws-security.sts.client- When validation is enabled on the JAX-WS endpoint, you must also configure an
STSClientinstance, which encapsulates all of the settings required to connect to the STS. The properties you can set on theSTSClientinstance are discussed in detail in Creating an STSClient Instance. tokenType- In order to enable a token transformation request (as distinct from a simple validation request), you must also set the
tokenTypeproperty on theSTSClientinstance. This is the key setting that triggers token transformation. When this setting is present, the Validate operation will perform token transformation and return a newly issued token of the specified type in the Validate response message.For the list of possible token type URIs you can specify here, see Table 8.2.
Relying party as a gateway service Link kopierenLink in die Zwischenablage kopiert!
Transformation algorithm Link kopierenLink in die Zwischenablage kopiert!
- When the STS receives the Validate request message, it performs all of the usual tests to validate the received token (see Section 9.1.4, “Customizing the Validate Operation”).
- After validating the token successfully, the STS checks whether the
TokenTypehas been explicitly set in the Validate request message (that is, whether the token type has some value other than the default dummy value). - If the token type was explicitly set, the STS proceeds to transform the token, which means that it issues a new token to replace the validated token.
- The STS now checks whether the current realm (as determined by the realm parser—see the section called “Configuring the realm parser”) is the same as the realm that issued the received token (as determined by the configured
SAMLRealmCodec—see the section called “Configuring the SAMLRealmCodec”). If the realms are different, the STS checks whether anIdentityMapperinstance is configured on the STS properties object. - If an
IdentityMapperis configured, the STS transforms the validated token's principal by calling themapPrincipalmethod on theIdentityMapper. The mapped identity will now be used as the transformed token's principal.NoteIn the context of SAML tokens, the principal corresponds to the value of theSubject/NameIDelement in the SAML token. - The STS now proceeds to issue a new token in the current realm using the (possibly transformed) principal, based on the data in the validated token. The STS iterates over all of the registered token providers, until it finds a token provider that can handle the requested token type in the current realm.
- The STS then issues a new token by calling out to the token provider and returns the newly issued token in the Validate response message.
Configuring the TokenValidateOperation Link kopierenLink in die Zwischenablage kopiert!
TokenValidateOperation instance is configured in an STS that supports token transformation:
tokenValidators property (as is usual for the Valdate operation—for example, see Section 9.1.4, “Customizing the Validate Operation”). What you might not expect, however, is that you are also required to provide a list of token providers to the tokenProviders property: this is because the Validate operation is also responsible for issuing new tokens, in the token transformation scenario.
Implementing an IdentityMapper Link kopierenLink in die Zwischenablage kopiert!
IdentityMapper interface and implement the mapPrincipal method, as shown in the following example:
CustomTokenPrincipal class is just a simple implementation of the java.security.Principal interface, which holds the string value of the returned principal.
Configuring the IdentityMapper Link kopierenLink in die Zwischenablage kopiert!
IdentityMapper instance is configured by setting the identityMapper property on the STS properties instance, as follows:
9.5.4. Realms Demonstration Link kopierenLink in die Zwischenablage kopiert!
Overview Link kopierenLink in die Zwischenablage kopiert!
Demonstration location Link kopierenLink in die Zwischenablage kopiert!
CXFInstallDir/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/realms
CXFInstallDir/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/realms
CXFInstallDir/services/sts/systests/advanced/src/test/resources/org/apache/cxf/systest/sts/realms
CXFInstallDir/services/sts/systests/advanced/src/test/resources/org/apache/cxf/systest/sts/realms
First STS server for A and C realms Link kopierenLink in die Zwischenablage kopiert!
Figure 9.13. STS Server for A and C realms
STS for realms A and C Link kopierenLink in die Zwischenablage kopiert!
STS endpoint configuration for realms A and C Link kopierenLink in die Zwischenablage kopiert!
A, for realm C, and for the default realm. The endpoint URL that the client connects to, determines the realm in which the token is issued (see Example 9.5, “Demonstration RealmParser Implementation”).
Issue configuration for realms A and C Link kopierenLink in die Zwischenablage kopiert!
TokenIssueOperation instance is configured as follows:
TokenIssueOperation is configured with a SAML token provider, but this SAML token provider is also configured with a realm map (through the realmMap property). The SAML token provider uses the realm map to retrieve the extra data that it needs to generate and sign a SAML token in each of the supported realms (see Section 9.5.1, “Issuing Tokens in Multiple Realms”).
Validate configuration for realms A and C Link kopierenLink in die Zwischenablage kopiert!
TokenValidateOperation instance is configured as follows:
TokenValidateOperation instance. The token provider list is needed in case the STS is asked to issue a new token, in the context of token transformation (see Section 9.5.3, “Token Transformation across Realms”).
STS properties for realms A and C Link kopierenLink in die Zwischenablage kopiert!
realmParser property is initialized with an instance of the URLRealmParser class, whose implementation is shown in Example 9.5, “Demonstration RealmParser Implementation”. The realm parser figures out the current realm by examining the message context.
Second STS server for B realm Link kopierenLink in die Zwischenablage kopiert!
Figure 9.14. STS Server for B realm
STS for realm B Link kopierenLink in die Zwischenablage kopiert!
STS configuration for realm B Link kopierenLink in die Zwischenablage kopiert!
realmB, in the WS endpoint address URL. The endpoint URL that the client connects to, determines the realm in which the token is issued (see Example 9.5, “Demonstration RealmParser Implementation”).
Issue configuration for realm B Link kopierenLink in die Zwischenablage kopiert!
TokenIssueOperation instance is configured as follows:
TokenIssueOperation is configured with a SAML token provider, but this SAML token provider is also configured with a realm map (through the realmMap property). The SAML token provider uses the realm map to retrieve the extra data that it needs to generate and sign a SAML token in each of the supported realms (see Section 9.5.1, “Issuing Tokens in Multiple Realms”).
Validate configuration for realm B Link kopierenLink in die Zwischenablage kopiert!
TokenValidateOperation instance is configured as follows:
samlRealmCodec property with a reference to the SAML realm codec implementation, IssuerSAMLRealmCodec. The SAML realm codec parses the received token in order to discover what realm it was originally issued in. See Example 9.6, “Demonstration SAMLRealmCodec Implementation”.
STS properties for realm B Link kopierenLink in die Zwischenablage kopiert!
Realm parser implementation Link kopierenLink in die Zwischenablage kopiert!
parseRealm method returns null, to select the default realm (that is, the realm configured by default, by the STS properties instance).
Example 9.5. Demonstration RealmParser Implementation
SAMLRealmCodec implementation Link kopierenLink in die Zwischenablage kopiert!
SAMLRealmCodec. The purpose of the codec is to determine the realm that originally issued the received token, by inspecting the contents of the token. In this implementation, it is assumed the SAML assertion's Issuer string uniquely identifies the issuing realm.
Example 9.6. Demonstration SAMLRealmCodec Implementation
IdentityMapper implementation Link kopierenLink in die Zwischenablage kopiert!
Example 9.7. Demonstration IdentityMapper Implementation