public void execute(WSHandler handler, SecurityActionToken actionToken,
Document doc, RequestData reqData)
throws WSSecurityException {
WSSecEncrypt wsEncrypt = new WSSecEncrypt(reqData.getWssConfig());
EncryptionActionToken encryptionToken = null;
if (actionToken instanceof EncryptionActionToken) {
encryptionToken = (EncryptionActionToken)actionToken;
}
if (encryptionToken == null) {
encryptionToken = reqData.getEncryptionToken();
}
if (encryptionToken.getKeyIdentifierId() != 0) {
wsEncrypt.setKeyIdentifierType(encryptionToken.getKeyIdentifierId());
}
if (encryptionToken.getSymmetricAlgorithm() != null) {
wsEncrypt.setSymmetricEncAlgorithm(encryptionToken.getSymmetricAlgorithm());
}
if (encryptionToken.getKeyTransportAlgorithm() != null) {
wsEncrypt.setKeyEnc(encryptionToken.getKeyTransportAlgorithm());
}
if (encryptionToken.getDigestAlgorithm() != null) {
wsEncrypt.setDigestAlgorithm(encryptionToken.getDigestAlgorithm());
}
if (encryptionToken.getMgfAlgorithm() != null) {
wsEncrypt.setMGFAlgorithm(encryptionToken.getMgfAlgorithm());
}
wsEncrypt.setUserInfo(encryptionToken.getUser());
wsEncrypt.setUseThisCert(encryptionToken.getCertificate());
Crypto crypto = encryptionToken.getCrypto();
boolean enableRevocation = Boolean.valueOf(handler.getStringOption(WSHandlerConstants.ENABLE_REVOCATION));
if (enableRevocation && crypto != null) {
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias(encryptionToken.getUser());
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
if (certs != null && certs.length > 0) {
crypto.verifyTrust(certs, enableRevocation);
}
}
if (encryptionToken.getParts().size() > 0) {
wsEncrypt.setParts(encryptionToken.getParts());
}
wsEncrypt.setEncryptSymmKey(encryptionToken.isEncSymmetricEncryptionKey());
byte[] ephemeralKey = encryptionToken.getKey();
if (!encryptionToken.isEncSymmetricEncryptionKey() && ephemeralKey == null) {
CallbackHandler callbackHandler =
handler.getPasswordCallbackHandler(reqData);
if (ephemeralKey == null) {
WSPasswordCallback passwordCallback =
handler.getPasswordCB(encryptionToken.getUser(), WSConstants.ENCR, callbackHandler, reqData);
ephemeralKey = passwordCallback.getKey();
}
}
wsEncrypt.setEphemeralKey(ephemeralKey);
if (encryptionToken.getTokenId() != null) {
wsEncrypt.setEncKeyId(encryptionToken.getTokenId());
}
if (encryptionToken.getTokenType() != null) {
wsEncrypt.setCustomReferenceValue(encryptionToken.getTokenType());
}
wsEncrypt.setAttachmentCallbackHandler(reqData.getAttachmentCallbackHandler());
try {
wsEncrypt.build(doc, encryptionToken.getCrypto(), reqData.getSecHeader());
} catch (WSSecurityException e) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty", e, "Error during encryption: ");
}
}