Package net.shibboleth.idp.attribute.filter.impl

# Class AttributeFilterImpl

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.idp.attribute.filter.impl.AttributeFilterImpl

All Implemented Interfaces:
  `AttributeFilter`, `Component`, `DestructableComponent`, `IdentifiableComponent`, `IdentifiedComponent`, `InitializableComponent`

@ThreadSafe public class AttributeFilterImpl extends AbstractIdentifiableInitializableComponent implements AttributeFilter
Service that filters out attributes and values based upon loaded policies.

## Field Summary

Fields
Modifier and Type
Field
Description
`private final List<AttributeFilterPolicy>`
`filterPolicies`
Filter policies used by this engine.
`private final org.slf4j.Logger`
`log`
Class logger.
`private String`
`logPrefix`
Log prefix.
`private Function<AttributeFilterContext,MetricContext>`
`metricContextLookupStrategy`
Strategy to get the `MetricContext` for timing.

## Constructor Summary

Constructors
Constructor
Description
`AttributeFilterImpl(String engineId, Collection<AttributeFilterPolicy> policies)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`doInitialize()`
`void`
`filterAttributes(AttributeFilterContext filterContext)`
Filters attributes and values.
`protected Collection<IdPAttributeValue>`
`getFilteredValues(String attributeId, AttributeFilterContext filterContext)`
Gets the permitted values for the given attribute from the `AttributeFilterWorkContext.getPermittedIdPAttributeValues()` and removes all denied values given in the `AttributeFilterWorkContext.getDeniedAttributeValues()`.
`List<AttributeFilterPolicy>`
`getFilterPolicies()`
Gets the immutable collection of filter policies.
`protected String`
`getLogPrefix()`
Get the prefix for logging.
`private void`
`logContext(AttributeFilterContext filterContext)`
Before we start log all we know about the resolver and context (at `Logger.debug(String)`).
`private String`
`notProvidedOr(String input)`
Code to replace (null) with <Not Supplied> in the log.
`private String`
`present(Object input)`
Return whether an object is null.
`private boolean`
`startTimer(AttributeFilterContext filterContext)`
Conditionally start a timer at the beginning of the filtering process.
`private void`
`stopTimer(AttributeFilterContext filterContext)`
Conditionally stop a timer at the end of the filtering process.

### Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent

`setId`

### Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent

`ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException`

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.shibboleth.shared.component.IdentifiedComponent

`getId`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### filterPolicies

@Nonnull private final List<AttributeFilterPolicy> filterPolicies
Filter policies used by this engine.

### logPrefix

@Nullable private String logPrefix
Log prefix.

### metricContextLookupStrategy

@Nonnull private Function<AttributeFilterContext,MetricContext> metricContextLookupStrategy
Strategy to get the `MetricContext` for timing.

## Constructor Details

### AttributeFilterImpl

public AttributeFilterImpl(@Nonnull @NotEmpty String engineId, @Nullable Collection<AttributeFilterPolicy> policies)
Constructor.

Parameters:
  `engineId` - ID of this engine
  `policies` - filter policies used by this engine

## Method Details

### getFilterPolicies

@Nonnull @Unmodifiable @NotLive public List<AttributeFilterPolicy> getFilterPolicies()
Gets the immutable collection of filter policies.

Specified by:
  `getFilterPolicies` in interface `AttributeFilter`
Returns:
  immutable collection of filter policies

### filterAttributes

public void filterAttributes(@Nonnull AttributeFilterContext filterContext) throws AttributeFilterException
Filters attributes and values. This filtering process may remove attributes and values but must never add them.

Specified by:
  `filterAttributes` in interface `AttributeFilter`
Parameters:
  `filterContext` - context containing the attributes to be filtered and collecting the results of the filtering process
Throws:
  `AttributeFilterException` - thrown if there is a problem retrieving or applying the attribute filter policy

### notProvidedOr

@Nonnull private String notProvidedOr(@Nullable String input)
Code to replace (null) with <Not Supplied> in the log.

Parameters:
  `input` - an input String
Returns:
  the input or a fixed string

### present

@Nonnull private String present(@Nullable Object input)
Return whether an object is null.

Parameters:
  `input` - an input String
Returns:
  "present" or "not present"

### logContext

private void logContext(@Nonnull AttributeFilterContext filterContext)
Before we start log all we know about the resolver and context (at `Logger.debug(String)`).

Parameters:
  `filterContext` - the context

### getFilteredValues

@Nullable protected Collection<IdPAttributeValue> getFilteredValues(@Nonnull @NotEmpty String attributeId, @Nonnull AttributeFilterContext filterContext)
Gets the permitted values for the given attribute from the `AttributeFilterWorkContext.getPermittedIdPAttributeValues()` and removes all denied values given in the `AttributeFilterWorkContext.getDeniedAttributeValues()`.

Parameters:
  `attributeId` - ID of the attribute whose values are to be retrieved
  `filterContext` - current attribute filter context
Returns:
  null if no values were permitted to be released, an empty collection if values were permitted but then all were removed by deny policies, a collection containing permitted values

### doInitialize

protected void doInitialize() throws ComponentInitializationException

Overrides:
  `doInitialize` in class `AbstractIdentifiedInitializableComponent`
Throws:
  `ComponentInitializationException`

### getLogPrefix

@Nonnull protected String getLogPrefix()
Get the prefix for logging.

Returns:
  Returns the logPrefix.

### startTimer

private boolean startTimer(@Nonnull AttributeFilterContext filterContext)
Conditionally start a timer at the beginning of the filtering process.

Parameters:
  `filterContext` - attribute filtering context
Returns:
  true iff the `stopTimer(AttributeFilterContext)` method needs to be called

### stopTimer

private void stopTimer(@Nonnull AttributeFilterContext filterContext)
Conditionally stop a timer at the end of the filtering process.

Parameters:
  `filterContext` - attribute filtering context