Top Description Inners Fields Constructors Methods
org.apache.catalina.filters

public Class HttpHeaderSecurityFilter

extends FilterBase
Class Inheritance
Imports
java.io.IOException, java.net.URI, .URISyntaxException, jakarta.servlet.FilterChain, .FilterConfig, .ServletException, .ServletRequest, .ServletResponse, jakarta.servlet.http.HttpServletResponse, org.apache.juli.logging.Log, .LogFactory

Provides a single configuration point for security measures that required the addition of one or more HTTP headers to the response.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private static final String
private boolean
private String
private HttpHeaderSecurityFilter.XFrameOption
private URI
private static final String
private static final String
private boolean
private static final String
private boolean
private String
private boolean
private int
private boolean
private final Log
private static final String
private static final String
private boolean
Inherited from org.apache.catalina.filters.FilterBase:
sm

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
doFilter(ServletRequest
The request to process
request
,
ServletResponse
The response associated with the request
response
,
FilterChain
Provides access to the next filter in the chain for this filter to pass the request and response to for further processing
chain
)

Implements jakarta.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.

public String
public String
public int
protected Log
public void
init(FilterConfig
The configuration information associated with the filter instance being initialised
filterConfig
)

Overrides org.apache.catalina.filters.FilterBase.init.

Overrides default jakarta.servlet.Filter.init.

Iterates over the configuration parameters and either logs a warning, or throws an exception for any parameter that does not have a matching setter in this filter.

public boolean
public boolean
protected boolean
isConfigProblemFatal()

Overrides org.apache.catalina.filters.FilterBase.isConfigProblemFatal.

Determines if an exception when calling a setter or an unknown configuration attribute triggers the failure of the this filter which in turn will prevent the web application from starting.

public boolean
public boolean
public boolean
public boolean
public void
setAntiClickJackingEnabled(boolean antiClickJackingEnabled)

public void
setAntiClickJackingOption(String antiClickJackingOption)

public void
setAntiClickJackingUri(String antiClickJackingUri)

public void
setBlockContentTypeSniffingEnabled(boolean blockContentTypeSniffingEnabled)

public void
setHstsEnabled(boolean hstsEnabled)

public void
setHstsIncludeSubDomains(boolean hstsIncludeSubDomains)

public void
setHstsMaxAgeSeconds(int hstsMaxAgeSeconds)

public void
setHstsPreload(boolean hstsPreload)

public void
setXssProtectionEnabled(boolean xssProtectionEnabled)
Deprecated

Field Detail

ANTI_CLICK_JACKING_HEADER_NAMEback to summary
private static final String ANTI_CLICK_JACKING_HEADER_NAME
antiClickJackingEnabledback to summary
private boolean antiClickJackingEnabled
antiClickJackingHeaderValueback to summary
private String antiClickJackingHeaderValue
antiClickJackingOptionback to summary
private HttpHeaderSecurityFilter.XFrameOption antiClickJackingOption
antiClickJackingUriback to summary
private URI antiClickJackingUri
BLOCK_CONTENT_TYPE_SNIFFING_HEADER_NAMEback to summary
private static final String BLOCK_CONTENT_TYPE_SNIFFING_HEADER_NAME
BLOCK_CONTENT_TYPE_SNIFFING_HEADER_VALUEback to summary
private static final String BLOCK_CONTENT_TYPE_SNIFFING_HEADER_VALUE
blockContentTypeSniffingEnabledback to summary
private boolean blockContentTypeSniffingEnabled
HSTS_HEADER_NAMEback to summary
private static final String HSTS_HEADER_NAME
hstsEnabledback to summary
private boolean hstsEnabled
hstsHeaderValueback to summary
private String hstsHeaderValue
hstsIncludeSubDomainsback to summary
private boolean hstsIncludeSubDomains
hstsMaxAgeSecondsback to summary
private int hstsMaxAgeSeconds
hstsPreloadback to summary
private boolean hstsPreload
logback to summary
private final Log log
XSS_PROTECTION_HEADER_NAMEback to summary
private static final String XSS_PROTECTION_HEADER_NAME

Deprecated

Annotations
@Deprecated
XSS_PROTECTION_HEADER_VALUEback to summary
private static final String XSS_PROTECTION_HEADER_VALUE

Deprecated

Annotations
@Deprecated
xssProtectionEnabledback to summary
private boolean xssProtectionEnabled

Deprecated

Annotations
@Deprecated

Constructor Detail

HttpHeaderSecurityFilterback to summary
public HttpHeaderSecurityFilter()

Method Detail

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

Implements jakarta.servlet.Filter.doFilter.

Doc from jakarta.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

A typical implementation of this method would follow the following pattern:-
1. Examine the request
2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering
3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering
4. a) Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
4. b) or not pass on the request/response pair to the next entity in the filter chain to block the request processing
5. Directly set headers on the response after invocation of the next entity in the filter chain.

Parameters
request:ServletRequest

The request to process

response:ServletResponse

The response associated with the request

chain:FilterChain

Provides access to the next filter in the chain for this filter to pass the request and response to for further processing

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs during this filter's processing of the request
ServletException:
if the processing fails for any other reason
getAntiClickJackingOptionback to summary
public String getAntiClickJackingOption()
getAntiClickJackingUriback to summary
public String getAntiClickJackingUri()
getHstsMaxAgeSecondsback to summary
public int getHstsMaxAgeSeconds()
getLoggerback to summary
protected Log getLogger()

Implements abstract org.apache.catalina.filters.FilterBase.getLogger.

Annotations
@Override
initback to summary
public void init(FilterConfig filterConfig) throws ServletException

Overrides org.apache.catalina.filters.FilterBase.init.

Overrides default jakarta.servlet.Filter.init.

Doc from org.apache.catalina.filters.FilterBase.init.

Iterates over the configuration parameters and either logs a warning, or throws an exception for any parameter that does not have a matching setter in this filter.

Parameters
filterConfig:FilterConfig

The configuration information associated with the filter instance being initialised

Annotations
@Override
Exceptions
ServletException:
if isConfigProblemFatal() returns true and a configured parameter does not have a matching setter
isAntiClickJackingEnabledback to summary
public boolean isAntiClickJackingEnabled()
isBlockContentTypeSniffingEnabledback to summary
public boolean isBlockContentTypeSniffingEnabled()
isConfigProblemFatalback to summary
protected boolean isConfigProblemFatal()

Overrides org.apache.catalina.filters.FilterBase.isConfigProblemFatal.

Doc from org.apache.catalina.filters.FilterBase.isConfigProblemFatal.

Determines if an exception when calling a setter or an unknown configuration attribute triggers the failure of the this filter which in turn will prevent the web application from starting.

Returns:boolean

true if a problem should trigger the failure of this filter, else false

Annotations
@Override
isHstsEnabledback to summary
public boolean isHstsEnabled()
isHstsIncludeSubDomainsback to summary
public boolean isHstsIncludeSubDomains()
isHstsPreloadback to summary
public boolean isHstsPreload()
isXssProtectionEnabledback to summary
public boolean isXssProtectionEnabled()

Deprecated

Annotations
@Deprecated
setAntiClickJackingEnabledback to summary
public void setAntiClickJackingEnabled(boolean antiClickJackingEnabled)
setAntiClickJackingOptionback to summary
public void setAntiClickJackingOption(String antiClickJackingOption)
setAntiClickJackingUriback to summary
public void setAntiClickJackingUri(String antiClickJackingUri)
setBlockContentTypeSniffingEnabledback to summary
public void setBlockContentTypeSniffingEnabled(boolean blockContentTypeSniffingEnabled)
setHstsEnabledback to summary
public void setHstsEnabled(boolean hstsEnabled)
setHstsIncludeSubDomainsback to summary
public void setHstsIncludeSubDomains(boolean hstsIncludeSubDomains)
setHstsMaxAgeSecondsback to summary
public void setHstsMaxAgeSeconds(int hstsMaxAgeSeconds)
setHstsPreloadback to summary
public void setHstsPreload(boolean hstsPreload)
setXssProtectionEnabledback to summary
public void setXssProtectionEnabled(boolean xssProtectionEnabled)

Deprecated

Annotations
@Deprecated
org.apache.catalina.filters back to summary

private final Enum HttpHeaderSecurityFilter.XFrameOption

extends Enum<HttpHeaderSecurityFilter.XFrameOption>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final HttpHeaderSecurityFilter.XFrameOption
public static final HttpHeaderSecurityFilter.XFrameOption
private final String
public static final HttpHeaderSecurityFilter.XFrameOption

Constructor Summary

AccessConstructor and Description
private
XFrameOption(String headerValue)

Method Summary

Modifier and TypeMethod and Description
public String
public static HttpHeaderSecurityFilter.XFrameOption
public static HttpHeaderSecurityFilter.XFrameOption[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALLOW_FROMback to summary
public static final HttpHeaderSecurityFilter.XFrameOption ALLOW_FROM
DENYback to summary
public static final HttpHeaderSecurityFilter.XFrameOption DENY
headerValueback to summary
private final String headerValue
SAME_ORIGINback to summary
public static final HttpHeaderSecurityFilter.XFrameOption SAME_ORIGIN

Constructor Detail

XFrameOptionback to summary
private XFrameOption(String headerValue)

Method Detail

getHeaderValueback to summary
public String getHeaderValue()
valueOfback to summary
public static HttpHeaderSecurityFilter.XFrameOption valueOf(String name)
valuesback to summary
public static HttpHeaderSecurityFilter.XFrameOption[] values()