* @param config
* @throws Exception
*/
private void createRSTR(ConversationConfiguration config) throws Exception {
WSSecEncryptedKey encrKeyBuilder = new WSSecEncryptedKey();
Crypto crypto = org.apache.rampart.conversation.Util.getCryptoInstace(config);
String encryptionUser = config.getEncryptionUser();
if(encryptionUser == null) {
throw new RampartException("missingEncryptionUser");
}
X509Certificate cert = crypto.getCertificates(encryptionUser)[0];
encrKeyBuilder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
try {
encrKeyBuilder.setUseThisCert(cert);
encrKeyBuilder.prepare(config.getDocument(), crypto);
} catch (WSSecurityException e) {
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(
config.getWstVersion(), rstrElem);
if(bstElem != null) {