Vector<WSEncryptionPart> sigs = getSignedParts();
//Add timestamp
if (timestampEl != null) {
Element el = timestampEl.getElement();
sigs.add(new WSEncryptionPart(addWsuIdToElement(el)));
}
if (isRequestor()) {
addSupportingTokens(sigs);
if (!sigs.isEmpty()) {
signatures.add(doSignature(sigs, sigTokenWrapper, sigToken, sigTok, tokIncluded));
}
doEndorse();
} else {
//confirm sig
assertSupportingTokens(sigs);
addSignatureConfirmation(sigs);
if (!sigs.isEmpty()) {
doSignature(sigs, sigTokenWrapper, sigToken, sigTok, tokIncluded);
}
}
//Encryption
TokenWrapper encrTokenWrapper = getEncryptionToken();
Token encrToken = encrTokenWrapper.getToken();
SecurityToken encrTok = null;
if (sigToken.equals(encrToken)) {
//Use the same token
encrTok = sigTok;
} else {
String encrTokId = null;
//REVISIT - issued token from trust?
encrTok = tokenStore.getToken(encrTokId);
if (SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS == encrToken.getInclusion()
|| SPConstants.IncludeTokenType.INCLUDE_TOKEN_ONCE == encrToken.getInclusion()
|| (isRequestor()
&& SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT
== encrToken.getInclusion())) {
Element encrTokElem = (Element)encrTok.getToken();
//Add the encrToken element before the sigToken element
secHeader.getSecurityHeader().insertBefore(encrTokElem, sigTokElem);
}
}
Vector<WSEncryptionPart> enc = getEncryptedParts();
//Check for signature protection
if (sbinding.isSignatureProtection() && mainSigId != null) {
enc.add(new WSEncryptionPart(mainSigId, "Element"));
}
if (isRequestor()) {
for (String id : encryptedTokensIdList) {
enc.add(new WSEncryptionPart(id, "Element"));
}
}
doEncryption(encrTokenWrapper,
encrTok,
tokIncluded,