Token token = null;
final CallbackHandler callbackHandler = stsConfig.getCallbackHandler();
try{
NamespaceContextEx nsContext = null;
if(soapVersion == soapVersion.SOAP_11){
nsContext = new NamespaceContextEx();
}else{
nsContext = new NamespaceContextEx(true);
}
nsContext.addEncryptionNS();
nsContext.addExc14NS();
nsContext.addSAMLNS();
nsContext.addSignatureNS();
nsContext.addWSSNS();
// Get the service certificate
final X509Certificate serCert = getServiceCertificate(callbackHandler, stsConfig.getTrustSPMetadata(appliesTo), appliesTo);
// Create the KeyInfo for SubjectConfirmation
final KeyInfo keyInfo = createKeyInfo(keyType, serCert, context);