Class AbstractMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>
- java.lang.Object
-
- se.litsec.opensaml.saml2.metadata.AbstractMetadataContainer<T>
-
- Type Parameters:
T- the contained type
- All Implemented Interfaces:
MetadataContainer<T>
- Direct Known Subclasses:
EntitiesDescriptorContainer,EntityDescriptorContainer
public abstract class AbstractMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject> extends Object implements MetadataContainer<T>
Abstract base class for theMetadataContainerinterface.- Author:
- Martin Lindström (martin.lindstrom@litsec.se)
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_DESCRIPTOR_ID_SIZEDefault size for the ID attribute string.static floatDEFAULT_UPDATE_FACTORThe default update factor for the metadata - 0,75 (75%), i.e.static DurationDEFAULT_VALIDITYThe default validity for metadata - one week.protected TdescriptorThe encapsulated descriptor element.protected intidSizeThe size of the ID attribute string.protected X509CredentialsignatureCredentialsThe signature credentials for signing the metadata entry.protected floatupdateFactorThe update factor.protected DurationvalidityThe validity time for created entries.
-
Constructor Summary
Constructors Constructor Description AbstractMetadataContainer(T descriptor, X509Credential signatureCredentials)Constructor assigning the encapsulated descriptor element.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidassignID(T descriptor, String id)Assigns the supplied id to the ID attribute of the descriptor.TcloneDescriptor()Returns a deep clone of the descriptor element that is encapsulated by this object.TgetDescriptor()Returns the metadata element that is encapsulated by this object.protected abstract StringgetID(T descriptor)Returns the ID attribute of the supplied descriptor.intgetIdSize()Returns the size of the ID attribute that is generated.protected abstract StringgetLogString(T descriptor)Returns a log string of the supplied descriptor.floatgetUpdateFactor()Returns the factor (between 0 and 1) that is used to compute whether it is time to update the contained descriptor.DurationgetValidity()Returns the duration of the validity that the encapsulated descriptor has.Elementmarshall()Marshals the encapsulated descriptor into its XML representation.voidsetIdSize(int idSize)Assigns the size of the ID attribute that is generated.voidsetUpdateFactor(float updateFactor)Assigns the factor (between 0 and 1) that is used to compute whether it is time to update the contained descriptor.voidsetValidity(Duration validity)Assigns the duration of the validity that the encapsulatedEntityDescriptorshould have.Tsign()Signs the encapsulated descriptor using the signature credentials configured for this object.Tupdate(boolean sign)Updates the encapsulated descriptor with a newly generated ID, a validity time according to this object's configuration, and then optionally signs the record.booleanupdateRequired(boolean signatureRequired)Predicate that returnstrueif the contained descriptor needs to be updated regarding its signature status and validity.
-
-
-
Field Detail
-
DEFAULT_VALIDITY
public static final Duration DEFAULT_VALIDITY
The default validity for metadata - one week.
-
DEFAULT_UPDATE_FACTOR
public static final float DEFAULT_UPDATE_FACTOR
The default update factor for the metadata - 0,75 (75%), i.e. "update the metadata when less than 75% of its original validity time remains".- See Also:
getUpdateFactor(), Constant Field Values
-
DEFAULT_DESCRIPTOR_ID_SIZE
public static final int DEFAULT_DESCRIPTOR_ID_SIZE
Default size for the ID attribute string.- See Also:
- Constant Field Values
-
descriptor
protected T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject descriptor
The encapsulated descriptor element.
-
validity
protected Duration validity
The validity time for created entries.
-
updateFactor
protected float updateFactor
The update factor.
-
idSize
protected int idSize
The size of the ID attribute string.
-
signatureCredentials
protected X509Credential signatureCredentials
The signature credentials for signing the metadata entry.
-
-
Constructor Detail
-
AbstractMetadataContainer
public AbstractMetadataContainer(T descriptor, X509Credential signatureCredentials)
Constructor assigning the encapsulated descriptor element.- Parameters:
descriptor- the descriptor objectsignatureCredentials- the signature credentials for signing the descriptor. May benull, but then no signing will be possible
-
-
Method Detail
-
getDescriptor
public T getDescriptor()
Returns the metadata element that is encapsulated by this object.- Specified by:
getDescriptorin interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Returns:
- a descriptor object
-
cloneDescriptor
public T cloneDescriptor() throws MarshallingException, UnmarshallingException
Returns a deep clone of the descriptor element that is encapsulated by this object.- Specified by:
cloneDescriptorin interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Returns:
- an copied descriptor object
- Throws:
MarshallingException- for marshalling errors of the objectUnmarshallingException- for unmarshalling errors of the object
-
updateRequired
public boolean updateRequired(boolean signatureRequired)
Predicate that returnstrueif the contained descriptor needs to be updated regarding its signature status and validity. The method will also take into account the update interval configured for this instance of the container.- Specified by:
updateRequiredin interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Parameters:
signatureRequired- should be set if signatures are required for a entry to be regarded valid- Returns:
- if the encapsulated descriptor needs to be updated
trueis returned, otherwisefalse
-
update
public T update(boolean sign) throws SignatureException, MarshallingException
Updates the encapsulated descriptor with a newly generated ID, a validity time according to this object's configuration, and then optionally signs the record.- Specified by:
updatein interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Parameters:
sign- flag that should be set if the metadata is to be signed- Returns:
- a reference to the resulting descriptor object
- Throws:
SignatureException- for signature errorsMarshallingException- for marshalling errors- See Also:
MetadataContainer.sign()
-
sign
public T sign() throws SignatureException, MarshallingException
Signs the encapsulated descriptor using the signature credentials configured for this object.- Specified by:
signin interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Returns:
- a reference to the resulting descriptor object
- Throws:
SignatureException- for signature errorsMarshallingException- for marshalling errors- See Also:
MetadataContainer.update(boolean)
-
marshall
public Element marshall() throws MarshallingException
Marshals the encapsulated descriptor into its XML representation.- Specified by:
marshallin interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Returns:
- an XML element
- Throws:
MarshallingException- for marshalling errors
-
getValidity
public Duration getValidity()
Returns the duration of the validity that the encapsulated descriptor has.- Specified by:
getValidityin interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Returns:
- the validity time for the metadata
-
setValidity
public void setValidity(Duration validity)
Assigns the duration of the validity that the encapsulatedEntityDescriptorshould have.The default value is
DEFAULT_VALIDITY.- Parameters:
validity- the validity
-
getUpdateFactor
public float getUpdateFactor()
Returns the factor (between 0 and 1) that is used to compute whether it is time to update the contained descriptor. The higher the factor, the more often the metadata is updated. The "is update required" computation is calculated as follows:
The easiest way to get the meaning of the update factor is perhaps using words. Suppose the update factor is 0,5, then the meaning is: "update the metadata when less than 50% of its original validity time remains".if (expireInstant > now) { return <update-required> } else { return (updateFactor * getValidity()) > (expireInstant - now) ? <update-required> : <no-update-required> }- Specified by:
getUpdateFactorin interfaceMetadataContainer<T extends TimeBoundSAMLObject & SignableSAMLObject & CacheableSAMLObject>- Returns:
- the update factor
-
setUpdateFactor
public void setUpdateFactor(float updateFactor)
Assigns the factor (between 0 and 1) that is used to compute whether it is time to update the contained descriptor.The default value is
DEFAULT_UPDATE_FACTOR.- Parameters:
updateFactor- the update factor- See Also:
getUpdateFactor()
-
getIdSize
public int getIdSize()
Returns the size of the ID attribute that is generated.- Returns:
- the size
-
setIdSize
public void setIdSize(int idSize)
Assigns the size of the ID attribute that is generated.The default value is
DEFAULT_DESCRIPTOR_ID_SIZE.- Parameters:
idSize- the size
-
getID
protected abstract String getID(T descriptor)
Returns the ID attribute of the supplied descriptor.- Parameters:
descriptor- the descriptor- Returns:
- the ID attribute
-
assignID
protected abstract void assignID(T descriptor, String id)
Assigns the supplied id to the ID attribute of the descriptor.- Parameters:
descriptor- the descriptorid- the ID attribute value
-
-