Class TemplateAttributeDefinition
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
-
- net.shibboleth.idp.attribute.resolver.AbstractResolverPlugin<IdPAttribute>
-
- net.shibboleth.idp.attribute.resolver.AbstractAttributeDefinition
-
- net.shibboleth.idp.attribute.resolver.ad.impl.TemplateAttributeDefinition
-
- All Implemented Interfaces:
AttributeDefinition,ResolverPlugin<IdPAttribute>,Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,UnmodifiableComponent,DisposableBean
@ThreadSafeAfterInit public class TemplateAttributeDefinition extends AbstractAttributeDefinition
An attribute definition that constructs its values based on the values of its dependencies using the Velocity Template Language. Dependencies may have multiple values, however multiple dependencies must have the same number of values. In the case of multi-valued dependencies, the template will be evaluated multiples times, iterating over each dependency.The template is inserted into the engine with a unique name derived from this class and from the id supplied for this attribute.
-
-
Constructor Summary
Constructors Constructor Description TemplateAttributeDefinition()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intaddAttributeValues(String attributeName, List<IdPAttributeValue> attributeValues, Map<String,Iterator<IdPAttributeValue>> sourceValues, int curValueCount)Add values for a given attribute to the source Map.protected IdPAttributedoAttributeDefinitionResolve(AttributeResolutionContext resolutionContext, AttributeResolverWorkContext workContext)protected voiddoInitialize()TemplategetTemplate()Get the template text to be evaluated.StringgetTemplateText()Get the template text to be evaluated.org.apache.velocity.app.VelocityEnginegetVelocityEngine()Get theVelocityEngineto be used.voidsetTemplateText(String velocityTemplate)Set the literal text of the template to be evaluated.private intsetupSourceValues(AttributeResolverWorkContext workContext, Map<String,Iterator<IdPAttributeValue>> sourceValues)Set up a map which can be used to populate the template.voidsetVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine)Set theVelocityEngineto be used.-
Methods inherited from class net.shibboleth.idp.attribute.resolver.AbstractAttributeDefinition
doResolve, getLogPrefix, isDependencyOnly, isPreRequested, setDependencyOnly, setPreRequested
-
Methods inherited from class net.shibboleth.idp.attribute.resolver.AbstractResolverPlugin
addDisplayInformation, doDestroy, equals, getActivationCondition, getAttributeDependencies, getDataConnectorDependencies, getProfileContextStrategy, hashCode, isPropagateResolutionExceptions, isSuppressDisplayInformation, resolve, setActivationCondition, setAttributeDependencies, setDataConnectorDependencies, setProfileContextStrategy, setPropagateResolutionExceptions, setSuppressDisplayInformation
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
setId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
getId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, initialize, isDestroyed, isInitialized
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.shibboleth.utilities.java.support.component.DestructableComponent
destroy, isDestroyed
-
Methods inherited from interface org.springframework.beans.factory.DisposableBean
destroy
-
Methods inherited from interface net.shibboleth.utilities.java.support.component.IdentifiedComponent
getId
-
Methods inherited from interface net.shibboleth.utilities.java.support.component.InitializableComponent
initialize, isInitialized
-
Methods inherited from interface net.shibboleth.idp.attribute.resolver.ResolverPlugin
getActivationCondition, getAttributeDependencies, getDataConnectorDependencies, isPropagateResolutionExceptions, resolve
-
-
-
-
Field Detail
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
template
@NonnullAfterInit private Template template
Template to be evaluated.
-
templateText
@NonnullAfterInit private String templateText
Template (as Text) to be evaluated.
-
engine
@NonnullAfterInit private org.apache.velocity.app.VelocityEngine engine
VelocityEngine.
-
-
Method Detail
-
getTemplate
@NonnullAfterInit public Template getTemplate()
Get the template text to be evaluated.- Returns:
- the template
-
getTemplateText
@NonnullAfterInit public String getTemplateText()
Get the template text to be evaluated.- Returns:
- the template
-
setTemplateText
public void setTemplateText(@Nullable String velocityTemplate)Set the literal text of the template to be evaluated.- Parameters:
velocityTemplate- template to be evaluated
-
getVelocityEngine
@NonnullAfterInit public org.apache.velocity.app.VelocityEngine getVelocityEngine()
Get theVelocityEngineto be used.- Returns:
- the template
-
setVelocityEngine
public void setVelocityEngine(@Nonnull org.apache.velocity.app.VelocityEngine velocityEngine)Set theVelocityEngineto be used.- Parameters:
velocityEngine- engine to be used
-
doInitialize
protected void doInitialize() throws ComponentInitializationException- Overrides:
doInitializein classAbstractAttributeDefinition- Throws:
ComponentInitializationException
-
doAttributeDefinitionResolve
@Nonnull protected IdPAttribute doAttributeDefinitionResolve(@Nonnull AttributeResolutionContext resolutionContext, @Nonnull AttributeResolverWorkContext workContext) throws ResolutionException
- Specified by:
doAttributeDefinitionResolvein classAbstractAttributeDefinition- Throws:
ResolutionException
-
addAttributeValues
private int addAttributeValues(@Nonnull String attributeName, @Nullable List<IdPAttributeValue> attributeValues, @Nonnull @NonnullElements Map<String,Iterator<IdPAttributeValue>> sourceValues, int curValueCount) throws ResolutionExceptionAdd values for a given attribute to the source Map. Helper function forsetupSourceValues(AttributeResolverWorkContext, Map)- Parameters:
attributeName- the attribute name under considerationattributeValues- The values to add.sourceValues- the Map to add tocurValueCount- how many values to expect. 0 means never set- Returns:
- the number of values to expect, 0 means still not set.
- Throws:
ResolutionException- if there is a mismatched count of attributes
-
setupSourceValues
private int setupSourceValues(@Nonnull AttributeResolverWorkContext workContext, @Nonnull @NonnullElements Map<String,Iterator<IdPAttributeValue>> sourceValues) throws ResolutionExceptionSet up a map which can be used to populate the template. The key is the attribute name and the value is the iterator to give all the names. We also return how deep the iteration will be and throw an exception if there is a mismatch in number of elements in any attribute.- Parameters:
workContext- source for dependenciessourceValues- to populate with the attribute iterators- Returns:
- how many values in the attributes
- Throws:
ResolutionException- if there is a mismatched count of attributes
-
-