STSTokenProvider tokenProvider = WSTrustFactory.getSTSTokenProvider();
tokenProvider.generateToken(context);
// Create RequestedSecurityToken
final RequestedSecurityToken reqSecTok = eleFac.createRequestedSecurityToken();
Token issuedToken = context.getSecurityToken();
// Encrypt the token if required and the service certificate is available
if (stsConfig.getEncryptIssuedToken()&& serCert != null){
String keyWrapAlgo = (String) context.getOtherProperties().get(IssuedTokenContext.KEY_WRAP_ALGORITHM);
Element encTokenEle = this.encryptToken((Element)issuedToken.getTokenValue(), serCert, appliesTo, encryptionAlgorithm, keyWrapAlgo);
issuedToken = new GenericToken(encTokenEle);
}
reqSecTok.setToken(issuedToken);
// Create RequestedAttachedReference and RequestedUnattachedReference