Package net.shibboleth.shared.spring.servlet.impl

# Class DynamicResponseHeaderFilter

java.lang.Object
net.shibboleth.shared.servlet.AbstractConditionalFilter
net.shibboleth.shared.spring.servlet.impl.DynamicResponseHeaderFilter

All Implemented Interfaces:
  `Filter`, `ChainableFilter`, `Ordered`

public class DynamicResponseHeaderFilter extends AbstractConditionalFilter implements ChainableFilter
Implementation of an HTTP servlet `Filter` which supports configurable response header injection, including via injected functions that can conditionally attach headers.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`private class`
`DynamicResponseHeaderFilter.ResponseProxy`
An implementation of `HttpServletResponse` which adds the response headers supplied by the outer class.

## Nested classes/interfaces inherited from interface net.shibboleth.shared.spring.servlet.ChainableFilter

`ChainableFilter.FilterOrder`

## Field Summary

Fields
Modifier and Type
Field
Description
`private Collection<Function<Pair<HttpServletRequest,HttpServletResponse>,Boolean>>`
`callbacks`
Callbacks to add headers dynamically.
`private Map<String,String>`
`headers`
Statically defined headers to return.

### Fields inherited from interface org.springframework.core.Ordered

`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

## Constructor Summary

Constructors
Constructor
Description
`DynamicResponseHeaderFilter()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`destroy()`
`int`
`getOrder()`
`void`
`init(FilterConfig filterConfig)`
`protected void`
`runFilter(ServletRequest request, ServletResponse response, FilterChain chain)`
Subclasses should override this method to be called when the filter is directed to activate.
`void`
`setCallbacks(Collection<Function<Pair<HttpServletRequest,HttpServletResponse>,Boolean>> theCallbacks)`
Set the callbacks to invoke to dynamically attach headers.
`void`
`setHeaders(Map<String,String> map)`
Set the headers to statically attach to all responses.

### Methods inherited from class net.shibboleth.shared.servlet.AbstractConditionalFilter

`doFilter, getActivationCondition, setActivationCondition`

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

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

### Methods inherited from interface jakarta.servlet.Filter

`doFilter`

## Field Details

### headers

@Nonnull private Map<String,String> headers
Statically defined headers to return.

### callbacks

@Nonnull private Collection<Function<Pair<HttpServletRequest,HttpServletResponse>,Boolean>> callbacks
Callbacks to add headers dynamically.

## Constructor Details

### DynamicResponseHeaderFilter

public DynamicResponseHeaderFilter()
Constructor.

## Method Details

### setHeaders

public void setHeaders(@Nullable Map<String,String> map)
Set the headers to statically attach to all responses.

Parameters:
  `map` - header map

### setCallbacks

public void setCallbacks(@Nullable Collection<Function<Pair<HttpServletRequest,HttpServletResponse>,Boolean>> theCallbacks)
Set the callbacks to invoke to dynamically attach headers.

Parameters:
  `theCallbacks` - callback collection

### init

public void init(FilterConfig filterConfig) throws ServletException

Specified by:
  `init` in interface `Filter`
Overrides:
  `init` in class `AbstractConditionalFilter`
Throws:
  `ServletException`

### destroy

public void destroy()

Specified by:
  `destroy` in interface `Filter`
Overrides:
  `destroy` in class `AbstractConditionalFilter`

### getOrder

public int getOrder()

Specified by:
  `getOrder` in interface `ChainableFilter`
Specified by:
  `getOrder` in interface `Ordered`

### runFilter

protected 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.

Specified by:
  `runFilter` in class `AbstractConditionalFilter`
Parameters:
  `request` - servlet request
  `response` - servlet response
  `chain` - filter chain
Throws:
  `IOException` - on error
  `ServletException` - on error