List<SecurePart> encrParts,
boolean externalRef) throws SOAPException {
//Do encryption
if (recToken != null && recToken.getToken() != null) {
AbstractToken encrToken = recToken.getToken();
AlgorithmSuite algorithmSuite = sbinding.getAlgorithmSuite();
// Action
Map<String, Object> config = getProperties();
String actionToPerform = ConfigurationConstants.ENCRYPT;
if (recToken.getToken().getDerivedKeys() == DerivedKeys.RequireDerivedKeys) {
actionToPerform = ConfigurationConstants.ENCRYPT_DERIVED;
if (MessageUtils.isRequestor(message) && recToken.getToken() instanceof X509Token) {
config.put(ConfigurationConstants.DERIVED_TOKEN_REFERENCE, "EncryptedKey");
} else {
config.put(ConfigurationConstants.DERIVED_TOKEN_REFERENCE, "DirectReference");
}
AlgorithmSuiteType algSuiteType = sbinding.getAlgorithmSuite().getAlgorithmSuiteType();
config.put(ConfigurationConstants.DERIVED_ENCRYPTION_KEY_LENGTH,
"" + algSuiteType.getEncryptionDerivedKeyLength() / 8);
}
if (recToken.getVersion() == SPConstants.SPVersion.SP12) {
config.put(ConfigurationConstants.USE_2005_12_NAMESPACE, "true");
}
if (config.containsKey(ConfigurationConstants.ACTION)) {
String action = (String)config.get(ConfigurationConstants.ACTION);
config.put(ConfigurationConstants.ACTION, action + " " + actionToPerform);
} else {
config.put(ConfigurationConstants.ACTION, actionToPerform);
}
String parts = "";
if (config.containsKey(ConfigurationConstants.ENCRYPTION_PARTS)) {
parts = (String)config.get(ConfigurationConstants.ENCRYPTION_PARTS);
if (!parts.endsWith(";")) {
parts += ";";
}
}
if (encrParts != null) {
for (SecurePart part : encrParts) {
QName name = part.getName();
parts += "{" + part.getModifier() + "}{"
+ name.getNamespaceURI() + "}" + name.getLocalPart() + ";";
}
}
config.put(ConfigurationConstants.ENCRYPTION_PARTS, parts);
if (isRequestor()) {
config.put(ConfigurationConstants.ENC_KEY_ID,
getKeyIdentifierType(recToken, encrToken));
config.put(ConfigurationConstants.DERIVED_TOKEN_KEY_ID, "DirectReference");
} else if (recToken.getToken() instanceof KerberosToken && !isRequestor()) {
config.put(ConfigurationConstants.ENC_KEY_ID, "KerberosSHA1");
config.put(ConfigurationConstants.DERIVED_TOKEN_KEY_ID, "KerberosSHA1");
if (recToken.getToken().getDerivedKeys() == DerivedKeys.RequireDerivedKeys) {
config.put(ConfigurationConstants.ENC_KEY_ID, "DirectReference");
}
} else if ((recToken.getToken() instanceof IssuedToken
|| recToken.getToken() instanceof SecureConversationToken
|| recToken.getToken() instanceof SpnegoContextToken) && !isRequestor()) {
config.put(ConfigurationConstants.ENC_KEY_ID, "DirectReference");
} else {
config.put(ConfigurationConstants.ENC_KEY_ID, "EncryptedKeySHA1");
if (recToken.getToken().getDerivedKeys() == DerivedKeys.RequireDerivedKeys) {
config.put(ConfigurationConstants.DERIVED_TOKEN_KEY_ID, "EncryptedKeySHA1");
config.put(ConfigurationConstants.ENC_KEY_ID, "DirectReference");
config.put(ConfigurationConstants.ENC_SYM_ENC_KEY, "false");
}
}
config.put(ConfigurationConstants.ENC_KEY_TRANSPORT,
algorithmSuite.getAlgorithmSuiteType().getAsymmetricKeyWrap());
config.put(ConfigurationConstants.ENC_SYM_ALGO,
algorithmSuite.getAlgorithmSuiteType().getEncryption());
String encUser = (String)message.getContextualProperty(SecurityConstants.ENCRYPT_USERNAME);
if (encUser != null) {
config.put(ConfigurationConstants.ENCRYPTION_USER, encUser);
}