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_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) voidsetPortMapper(PortMapper portMapper) Use thisPortMapperfor mapping custom portsvoidsetRequestMatcher(RequestMatcher requestMatcher) Use thisRequestMatcherto narrow which requests are redirected to HTTPS.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods 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:
doFilterInternalin classorg.springframework.web.filter.OncePerRequestFilter- Throws:
jakarta.servlet.ServletExceptionIOException
-
setPortMapper
Use thisPortMapperfor mapping custom ports- Parameters:
portMapper- thePortMapperto use
-
setRequestMatcher
Use thisRequestMatcherto 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- theRequestMatcherto use
-