List<SecurePart> encrParts,
boolean externalRef) throws SOAPException {
//Do encryption
if (recToken != null && recToken.getToken() != null) {
AbstractToken encrToken = recToken.getToken();
AlgorithmSuite algorithmSuite = sbinding.getAlgorithmSuite();
// Action
WSSSecurityProperties properties = getProperties();
WSSConstants.Action actionToPerform = WSSConstants.ENCRYPT;
if (recToken.getToken().getDerivedKeys() == DerivedKeys.RequireDerivedKeys) {
actionToPerform = WSSConstants.ENCRYPT_WITH_DERIVED_KEY;
if (MessageUtils.isRequestor(message) && recToken.getToken() instanceof X509Token) {
properties.setDerivedKeyTokenReference(
WSSConstants.DerivedKeyTokenReference.EncryptedKey);
} else {
properties.setDerivedKeyTokenReference(
WSSConstants.DerivedKeyTokenReference.DirectReference);
}
AlgorithmSuiteType algSuiteType = sbinding.getAlgorithmSuite().getAlgorithmSuiteType();
properties.setDerivedEncryptionKeyLength(
algSuiteType.getEncryptionDerivedKeyLength() / 8);
}
if (recToken.getVersion() == SPConstants.SPVersion.SP12) {
properties.setUse200512Namespace(true);
}
for (SecurePart encPart : encrParts) {
properties.addEncryptionPart(encPart);
}
properties.addAction(actionToPerform);
if (isRequestor()) {
properties.setEncryptionKeyIdentifier(getKeyIdentifierType(recToken, encrToken));
properties.setDerivedKeyKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_SecurityTokenDirectReference);
} else if (recToken.getToken() instanceof KerberosToken && !isRequestor()) {
properties.setEncryptionKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_KerberosSha1Identifier);
properties.setDerivedKeyKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_KerberosSha1Identifier);
if (recToken.getToken().getDerivedKeys() == DerivedKeys.RequireDerivedKeys) {
properties.setEncryptionKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_SecurityTokenDirectReference);
}
} else if ((recToken.getToken() instanceof IssuedToken
|| recToken.getToken() instanceof SecureConversationToken
|| recToken.getToken() instanceof SpnegoContextToken) && !isRequestor()) {
properties.setEncryptionKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_SecurityTokenDirectReference);
} else {
properties.setEncryptionKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_EncryptedKeySha1Identifier);
if (recToken.getToken().getDerivedKeys() == DerivedKeys.RequireDerivedKeys) {
properties.setDerivedKeyKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_EncryptedKeySha1Identifier);
properties.setEncryptionKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_SecurityTokenDirectReference);
properties.setEncryptSymmetricEncryptionKey(false);
}
}
properties.setEncryptionKeyTransportAlgorithm(
algorithmSuite.getAlgorithmSuiteType().getAsymmetricKeyWrap());
properties.setEncryptionSymAlgorithm(
algorithmSuite.getAlgorithmSuiteType().getEncryption());
String encUser = (String)message.getContextualProperty(SecurityConstants.ENCRYPT_USERNAME);
if (encUser == null) {
encUser = (String)message.getContextualProperty(SecurityConstants.USERNAME);
}