Package net.shibboleth.shared.servlet

# Class AbstractConditionalFilter

java.lang.Object
net.shibboleth.shared.servlet.AbstractConditionalFilter

All Implemented Interfaces:
  `Filter`

Direct Known Subclasses:
  `CookieBufferingFilter`, `DynamicResponseHeaderFilter`, `RequestResponseContextFilter`, `SameSiteCookieHeaderFilter`

public abstract class AbstractConditionalFilter extends Object implements Filter
Base class for HTTP servlet `Filter` that determines whether to run dynamically based on a supplied `Predicate` instead of based on mapping rules defined in web.xml.

Since:
  9.0.0

## Field Summary

Fields
Modifier and Type
Field
Description
`private Predicate<ServletRequest>`
`activationCondition`
Whether filter should run or not.

## Constructor Summary

Constructors
Constructor
Description
`AbstractConditionalFilter()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`destroy()`
`void`
`doFilter(ServletRequest request, ServletResponse response, FilterChain chain)`
`Predicate<ServletRequest>`
`getActivationCondition()`
Get the condition to control activation of this filter.
`void`
`init(FilterConfig filterConfig)`
`protected abstract void`
`runFilter(ServletRequest request, ServletResponse response, FilterChain chain)`
Subclasses should override this method to be called when the filter is directed to activate.
`void`
`setActivationCondition(Predicate<ServletRequest> condition)`
Set the condition to control activation of this filter.

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

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

## Field Details

### activationCondition

@Nonnull private Predicate<ServletRequest> activationCondition
Whether filter should run or not.

## Constructor Details

### AbstractConditionalFilter

public AbstractConditionalFilter()
Constructor.

## Method Details

### getActivationCondition

@Nonnull public Predicate<ServletRequest> getActivationCondition()
Get the condition to control activation of this filter.

Returns:
  condition

### setActivationCondition

public void setActivationCondition(@Nonnull Predicate<ServletRequest> condition)
Set the condition to control activation of this filter.

Parameters:
  `condition` - run condition

### init

public void init(FilterConfig filterConfig) throws ServletException

Specified by:
  `init` in interface `Filter`
Throws:
  `ServletException`

### destroy

public void destroy()

Specified by:
  `destroy` in interface `Filter`

### doFilter

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException

Specified by:
  `doFilter` in interface `Filter`
Throws:
  `IOException`
  `ServletException`

### runFilter

protected abstract void runFilter(@Nonnull ServletRequest request, @Nonnull ServletResponse response, @Nonnull FilterChain chain) throws IOException, ServletException
Subclasses should override this method to be called when the filter is directed to activate.

Parameters:
  `request` - servlet request
  `response` - servlet response
  `chain` - filter chain
Throws:
  `ServletException` - on error
  `IOException` - on error