}
}
private void doSignBeforeEncrypt() {
TokenWrapper sigTokenWrapper = getSignatureToken();
Token sigToken = sigTokenWrapper.getToken();
String sigTokId = null;
Element sigTokElem = null;
try {
SecurityToken sigTok = null;
if (sigToken != null) {
if (sigToken instanceof SecureConversationToken) {
sigTok = getSecurityToken();
} else if (sigToken instanceof IssuedToken) {
sigTok = getSecurityToken();
} else if (sigToken instanceof X509Token) {
if (isRequestor()) {
sigTokId = setupEncryptedKey(sigTokenWrapper, sigToken);
} else {
sigTokId = getEncryptedKey();
}
}
} else {
policyNotAsserted(sbinding, "No signature token");
return;
}
if (sigTok == null && StringUtils.isEmpty(sigTokId)) {
policyNotAsserted(sigTokenWrapper, "No signature token id");
return;
} else {
policyAsserted(sigTokenWrapper);
}
if (sigTok == null) {
sigTok = tokenStore.getToken(sigTokId);
}
if (sigTok == null) {
//REVISIT - no token?
}
boolean tokIncluded = true;
if (SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS == sigToken.getInclusion()
|| SPConstants.IncludeTokenType.INCLUDE_TOKEN_ONCE == sigToken.getInclusion()
|| (isRequestor()
&& SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT
== sigToken.getInclusion())) {
Element el = sigTok.getToken();
sigTokElem = cloneElement(el);
this.addEncryptedKeyElement((Element)sigTokElem);
} else if (isRequestor() && sigToken instanceof X509Token) {
Element el = sigTok.getToken();
sigTokElem = (Element)secHeader.getSecurityHeader().getOwnerDocument()
.importNode(el, true);
this.addEncryptedKeyElement((Element)sigTokElem);
} else {
tokIncluded = false;
}
List<WSEncryptionPart> sigs = getSignedParts();
//Add timestamp
if (timestampEl != null) {
WSEncryptionPart timestampPart = convertToEncryptionPart(timestampEl.getElement());
sigs.add(timestampPart);
}
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);
}