// or a <SecurityTokenReference> element to a security token found elsewhere
requestedToken = new SecurityTokenOrReference(userToken);
}
// Create our response object, giving it an XML document object to use for element creation, along with our requestedToken object
RequestSecurityTokenResponse tokenResponse = new RequestSecurityTokenResponse(doc, requestedToken);
// Set the Context of the response, according to WS-Trust, this must be the same as the Context of the request
tokenResponse.setContext(tokenRequest.getContext());
// Set the TokenType of the response. To make clients happy we'll return a token of the type they requested
tokenResponse.setTokenType(tokenRequest.getTokenType());
// Add a Lifetime element to indicate to clients the lifetime of the token we're sending
// In this case, we're giving the client the lifetime they asked for
Lifetime lifetime = tokenRequest.getLifetime();
tokenResponse.setLifetime(lifetime);
// Check if the request included a custom element named <TestElement>
// Note that a list of custom elements can be obtained by calling getCustomElements();
if (tokenRequest.getCustomElement("http://testElementNs.testElementNs", "TestElement") != null) {
// If it did we'll add our own custom element to the response
tokenResponse.addCustomElementNS("http://testElementNs.testElementNs", "te:TestElementResponse");
}
// Return the response object. If our Axis Serializers are configured correctly, this should automatically get converted to XML
return tokenResponse;
}