throw new TrustException(
"errorInBuildingTheEncryptedKeyForPrincipal",
new String[] { cert.getSubjectDN().getName()}, e);
}
SecurityContextToken sct = new SecurityContextToken(config.getDocument());
Util.resgisterContext(sct.getIdentifier(), config);
//Creation and expiration times
Date creationTime = new Date();
Date expirationTime = new Date();
expirationTime.setTime(creationTime.getTime() + 300000);
Token token = new Token(sct.getIdentifier(), (OMElement)sct.getElement(), creationTime, expirationTime);
token.setSecret(encrKeyBuilder.getEphemeralKey());
config.getTokenStore().add(token);
SOAPEnvelope env = config.getMsgCtx().getEnvelope();
SOAPHeader header = env.getHeader();
if(header == null) {
header = ((SOAPFactory)env.getOMFactory()).createSOAPHeader(env);
}
OMElement rstrElem = TrustUtil.createRequestSecurityTokenResponseElement(config.getWstVersion(), header);
OMElement rstElem = TrustUtil.createRequestedSecurityTokenElement(config.getWstVersion(), rstrElem);
// Use GMT time in milliseconds
DateFormat zulu = new XmlSchemaDateFormat();
// Add the Lifetime element
TrustUtil.createLifetimeElement(config.getWstVersion(), rstrElem, zulu
.format(creationTime), zulu.format(expirationTime));
rstElem.addChild((OMElement)sct.getElement());
TrustUtil.createRequestedAttachedRef(config.getWstVersion(), rstrElem,
"#" + sct.getID(), WSSHandlerConstants.TOK_TYPE_SCT);
TrustUtil
.createRequestedUnattachedRef(config.getWstVersion(), rstrElem,
sct.getIdentifier(), WSSHandlerConstants.TOK_TYPE_SCT);
Element encryptedKeyElem = encrKeyBuilder.getEncryptedKeyElement();
Element bstElem = encrKeyBuilder.getBinarySecurityTokenElement();
OMElement reqProofTok = TrustUtil.createRequestedProofTokenElement(