Class HttpsRedirectFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.security.web.transport.HttpsRedirectFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.EnvironmentAware
,org.springframework.core.env.EnvironmentCapable
,org.springframework.web.context.ServletContextAware
public final class HttpsRedirectFilter
extends org.springframework.web.filter.OncePerRequestFilter
Redirects any non-HTTPS request to its HTTPS equivalent.
Can be configured to use a RequestMatcher
to narrow which requests get
redirected.
Can also be configured for custom ports using PortMapper
.
- Since:
- 6.5
-
Field Summary
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doFilterInternal
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) void
setPortMapper
(PortMapper portMapper) Use thisPortMapper
for mapping custom portsvoid
setRequestMatcher
(RequestMatcher requestMatcher) Use thisRequestMatcher
to narrow which requests are redirected to HTTPS.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
HttpsRedirectFilter
public HttpsRedirectFilter()
-
-
Method Details
-
doFilterInternal
protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws jakarta.servlet.ServletException, IOException - Specified by:
doFilterInternal
in classorg.springframework.web.filter.OncePerRequestFilter
- Throws:
jakarta.servlet.ServletException
IOException
-
setPortMapper
Use thisPortMapper
for mapping custom ports- Parameters:
portMapper
- thePortMapper
to use
-
setRequestMatcher
Use thisRequestMatcher
to narrow which requests are redirected to HTTPS. The filter already first checks for HTTPS in the uri scheme, so it is not necessary to include that check in this matcher.- Parameters:
requestMatcher
- theRequestMatcher
to use
-