Class Encrypter
java.lang.Object
org.opensaml.xmlsec.encryption.support.Encrypter
org.opensaml.saml.saml2.encryption.Encrypter
Encrypter for SAML 2 SAMLObjects which has specific options for generating instances of subtypes of
EncryptedElementType.
Overloaded methods are provided for encrypting various SAML 2 elements to their corresponding encrypted element
variant of EncryptedElementType.
Support is also provided for differing placement options for any associated EncryptedKeys that may be generated. The options are:
INLINE: EncryptedKeys will placed inside the KeyInfo element of the EncryptedData elementPEER: EncryptedKeys will be placed as peer elements of the EncryptedData inside the EncryptedElementType element
The default placement is PEER.
The EncryptedKey forward and back referencing behavior associated with these key placement options is intended to be consistent with the guidelines detailed in SAML 2 Errata E43. See that document for further information.
For information on other parameters and options, and general XML Encryption issues, see
Encrypter.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumOptions for where to place the resulting EncryptedKey elements with respect to the associated EncryptedData element. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate XMLObjectBuilderFactoryFactory for building XMLObject instances.private XMLEncryptionBuilder<CarriedKeyName>Builder for CarriedKeyName objects.private XMLEncryptionBuilder<DataReference>Builder for DataReference objects.private DataEncryptionParametersThe parameters to use for encrypting the data.private IdentifierGenerationStrategyGenerator for XML ID attribute values.private List<KeyEncryptionParameters>The parameters to use for encrypting (wrapping) the data encryption key.private XMLSignatureBuilder<KeyInfo>Builder for KeyInfo objects.private XMLSignatureBuilder<KeyName>Builder for KeyName objects.private Encrypter.KeyPlacementThe option for where to place the generated EncryptedKey elements.private final org.slf4j.LoggerClass logger.private XMLEncryptionBuilder<ReferenceList>Builder for ReferenceList objects.private XMLSignatureBuilder<RetrievalMethod>Builder for RetrievalMethod objects. -
Constructor Summary
ConstructorsConstructorDescriptionEncrypter(DataEncryptionParameters dataEncParams) Constructor.Encrypter(DataEncryptionParameters dataEncParams, List<KeyEncryptionParameters> keyEncParams) Constructor.Encrypter(DataEncryptionParameters dataEncParams, KeyEncryptionParameters keyEncParam) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate EncryptedElementTypeEncrypt the specified XMLObject, and return it as an instance of the specified QName, which should be one of the types derived fromEncryptedElementType.Encrypt the specified Assertion.Encrypt the specified Attribute.Encrypt the specified BaseID.Encrypt the specified NameID.Encrypt the specified NewID.encryptAsID(Assertion assertion) Encrypt the specified Assertion, treating as an identifier and returning an EncryptedID.Get the current key placement option.private voidinit()Helper method for constructors.protected voidlinkMultiplePeerKeys(EncryptedData encData, List<EncryptedKey> encKeys) Link multiple "multicast" EncryptedKeys to the EncryptedData according to guidelines in SAML Errata E43.protected voidlinkSinglePeerKey(EncryptedData encData, EncryptedKey encKey) Link a single EncryptedKey to the EncryptedData according to guidelines in SAML Errata E43.private voidlogPreEncryption(XMLObject xmlObject, String objectType) Log the target object prior to encryption.protected EncryptedElementTypeplaceKeysAsPeers(EncryptedElementType encElement, EncryptedData encData, List<EncryptedKey> encKeys) Store the specified EncryptedData and EncryptedKey(s) in the specified instance of EncryptedElementType as peer elements, following SAML 2 Errata E43 guidelines for forward and back referencing between the EncryptedData and EncryptedKey(s).protected EncryptedElementTypeplaceKeysInline(EncryptedElementType encElement, EncryptedData encData, List<EncryptedKey> encKeys) Place the EncryptedKey elements inside the KeyInfo element within the EncryptedData element.protected EncryptedElementTypeprocessElements(EncryptedElementType encElement, EncryptedData encData, List<EncryptedKey> encKeys) Handle post-processing of generated EncryptedData and EncryptedKey(s) and storage in the appropriate EncryptedElementType instance.voidsetIDGenerator(IdentifierGenerationStrategy newIDGenerator) Set the generator to use when creating XML ID attribute values.voidsetKeyPlacement(Encrypter.KeyPlacement newKeyPlacement) Set the key placement option.Methods inherited from class org.opensaml.xmlsec.encryption.support.Encrypter
buildXMLCipher, checkAndMarshall, checkParams, checkParams, checkParams, checkParams, decodeOAEPParams, encryptElement, encryptElement, encryptElement, encryptElement, encryptElementContent, encryptElementContent, encryptElementContent, encryptKey, encryptKey, encryptKey, generateEncryptionKey, getEffectiveMGF, getJCAProviderName, postProcessApacheEncryptedKey, setJCAProviderName
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
builderFactory
Factory for building XMLObject instances. -
keyInfoBuilder
Builder for KeyInfo objects. -
dataReferenceBuilder
Builder for DataReference objects. -
referenceListBuilder
Builder for ReferenceList objects. -
retrievalMethodBuilder
Builder for RetrievalMethod objects. -
keyNameBuilder
Builder for KeyName objects. -
carriedKeyNameBuilder
Builder for CarriedKeyName objects. -
idGenerator
Generator for XML ID attribute values. -
encParams
The parameters to use for encrypting the data. -
kekParamsList
The parameters to use for encrypting (wrapping) the data encryption key. -
keyPlacement
The option for where to place the generated EncryptedKey elements.
-
-
Constructor Details
-
Encrypter
public Encrypter(DataEncryptionParameters dataEncParams, List<KeyEncryptionParameters> keyEncParams) Constructor.- Parameters:
dataEncParams- the data encryption parameterskeyEncParams- the key encryption parameters
-
Encrypter
Constructor.- Parameters:
dataEncParams- the data encryption parameterskeyEncParam- the key encryption parameter
-
Encrypter
Constructor.- Parameters:
dataEncParams- the data encryption parameters
-
-
Method Details
-
init
private void init()Helper method for constructors. -
getKeyPlacement
Get the current key placement option.- Returns:
- returns the key placement option.
-
setKeyPlacement
Set the key placement option.- Parameters:
newKeyPlacement- The new key placement option to set
-
encrypt
Encrypt the specified Assertion.- Parameters:
assertion- the Assertion to encrypt- Returns:
- an EncryptedAssertion
- Throws:
EncryptionException- thrown when encryption generates an error
-
encryptAsID
Encrypt the specified Assertion, treating as an identifier and returning an EncryptedID.- Parameters:
assertion- the Assertion to encrypt- Returns:
- an EncryptedID
- Throws:
EncryptionException- thrown when encryption generates an error
-
encrypt
Encrypt the specified Attribute.- Parameters:
attribute- the Attribute to encrypt- Returns:
- an EncryptedAttribute
- Throws:
EncryptionException- thrown when encryption generates an error
-
encrypt
Encrypt the specified NameID.- Parameters:
nameID- the NameID to encrypt- Returns:
- an EncryptedID
- Throws:
EncryptionException- thrown when encryption generates an error
-
encrypt
Encrypt the specified BaseID.- Parameters:
baseID- the BaseID to encrypt- Returns:
- an EncryptedID
- Throws:
EncryptionException- thrown when encryption generates an error
-
encrypt
Encrypt the specified NewID.- Parameters:
newID- the NewID to encrypt- Returns:
- a NewEncryptedID
- Throws:
EncryptionException- thrown when encryption generates an error
-
logPreEncryption
Log the target object prior to encryption.- Parameters:
xmlObject- the XMLObject to encryptobjectType- String description of the type of object to encrypt
-
encrypt
@Nonnull private EncryptedElementType encrypt(@Nonnull XMLObject xmlObject, @Nonnull QName encElementName) throws EncryptionException Encrypt the specified XMLObject, and return it as an instance of the specified QName, which should be one of the types derived fromEncryptedElementType.- Parameters:
xmlObject- the XMLObject to encryptencElementName- the QName of the specialization of EncryptedElementType to return- Returns:
- a specialization of
EncryptedElementType - Throws:
EncryptionException- thrown when encryption generates an error
-
processElements
@Nonnull protected EncryptedElementType processElements(@Nonnull EncryptedElementType encElement, @Nonnull EncryptedData encData, @Nonnull List<EncryptedKey> encKeys) throws EncryptionException Handle post-processing of generated EncryptedData and EncryptedKey(s) and storage in the appropriate EncryptedElementType instance.- Parameters:
encElement- the EncryptedElementType instance which will hold the encrypted data and keysencData- the EncryptedData objectencKeys- the list of EncryptedKey objects- Returns:
- the processed EncryptedElementType instance
- Throws:
EncryptionException- thrown when processing encounters an error
-
placeKeysInline
@Nonnull protected EncryptedElementType placeKeysInline(@Nonnull EncryptedElementType encElement, @Nonnull EncryptedData encData, @Nonnull List<EncryptedKey> encKeys) Place the EncryptedKey elements inside the KeyInfo element within the EncryptedData element. Although operationally trivial, this method is provided so that subclasses may override or augment as desired.- Parameters:
encElement- the EncryptedElementType instance which will hold the encrypted data and keysencData- the EncryptedData objectencKeys- the list of EncryptedKey objects- Returns:
- the processed EncryptedElementType instance
-
placeKeysAsPeers
@Nonnull protected EncryptedElementType placeKeysAsPeers(@Nonnull EncryptedElementType encElement, @Nonnull EncryptedData encData, @Nonnull List<EncryptedKey> encKeys) Store the specified EncryptedData and EncryptedKey(s) in the specified instance of EncryptedElementType as peer elements, following SAML 2 Errata E43 guidelines for forward and back referencing between the EncryptedData and EncryptedKey(s).- Parameters:
encElement- a specialization of EncryptedElementType to store the encrypted data and keysencData- the EncryptedData to storeencKeys- the EncryptedKey(s) to store- Returns:
- the resulting specialization of EncryptedElementType
-
linkSinglePeerKey
Link a single EncryptedKey to the EncryptedData according to guidelines in SAML Errata E43.- Parameters:
encData- the EncryptedDataencKey- the EncryptedKey
-
linkMultiplePeerKeys
protected void linkMultiplePeerKeys(@Nonnull EncryptedData encData, @Nonnull List<EncryptedKey> encKeys) Link multiple "multicast" EncryptedKeys to the EncryptedData according to guidelines in SAML Errata E43.- Parameters:
encData- the EncryptedDataencKeys- the list of EncryptedKeys
-