Class SslFilter
java.lang.Object
- All Implemented Interfaces:
javax.servlet.Filter,org.apache.shiro.lang.util.Nameable,PathConfigProcessor
Filter which requires a request to be over SSL. Access is allowed if the request is received on the configured
server
property defaults
is
port and the
request.isSecure(). If either condition is false,
the filter chain will not continue.
The port property defaults to 443 and also additionally guarantees that the
request scheme is always 'https' (except for port 80, which retains the 'http' scheme).
In addition, the filter allows enabling HTTP Strict Transport Security (HSTS).
This feature is opt-in and disabled by default. If enabled HSTS
will prevent any communications from being sent over HTTP to the
specified domain and will instead send all communications over HTTPS.
The
invalid reference
maxAge
31536000, and
invalid reference
includeSubDomains
false.
Warning: Use this setting with care and only if you plan to enable
SSL on every path.
Example configs:
[urls] /secure/path/** = sslwith HSTS enabled
[main] ssl.hsts.enabled = true [urls] /** = ssl
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassHelper class for HTTP Strict Transport Security (HSTS) -
Field Summary
FieldsFields inherited from class org.apache.shiro.web.filter.authz.PortFilter
DEFAULT_HTTP_PORT, HTTP_SCHEMEFields inherited from class org.apache.shiro.web.filter.AccessControlFilter
DEFAULT_LOGIN_URL, GET_METHOD, POST_METHODFields inherited from class org.apache.shiro.web.filter.PathMatchingFilter
appliedPaths, pathMatcherFields inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.apache.shiro.web.servlet.AbstractFilter
filterConfig -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetHsts()protected Stringprotected booleanisAccessAllowed(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) Retains the parent method's port-matching behavior but additionally guarantees that theServletRequest.isSecure().protected voidpostHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) If HTTP Strict Transport Security (HSTS) is enabled the HTTP header will be written, otherwise this method does nothing.voidsetHsts(SslFilter.HSTS hsts) Methods inherited from class org.apache.shiro.web.filter.authz.PortFilter
getPort, onAccessDenied, setPort, toPortMethods inherited from class org.apache.shiro.web.filter.authz.AuthorizationFilter
getUnauthorizedUrl, onAccessDenied, setUnauthorizedUrlMethods inherited from class org.apache.shiro.web.filter.AccessControlFilter
getLoginUrl, getSubject, isLoginRequest, onPreHandle, redirectToLogin, saveRequest, saveRequestAndRedirectToLogin, setLoginUrlMethods inherited from class org.apache.shiro.web.filter.PathMatchingFilter
getPathWithinApplication, isEnabled, pathsMatch, pathsMatch, preHandle, processPathConfigMethods inherited from class org.apache.shiro.web.servlet.AdviceFilter
afterCompletion, cleanup, doFilterInternal, executeChainMethods inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isEnabled, isEnabled, isFilterOncePerRequest, setEnabled, setFilterOncePerRequest, shouldNotFilterMethods inherited from class org.apache.shiro.web.servlet.NameableFilter
getName, setName, toStringBuilderMethods inherited from class org.apache.shiro.web.servlet.AbstractFilter
destroy, getFilterConfig, getInitParam, init, onFilterConfigSet, setFilterConfigMethods inherited from class org.apache.shiro.web.servlet.ServletContextSupport
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString
-
Field Details
-
DEFAULT_HTTPS_PORT
- See Also:
-
HTTPS_SCHEME
- See Also:
-
-
Constructor Details
-
SslFilter
public SslFilter()
-
-
Method Details
-
getHsts
-
setHsts
-
getScheme
- Overrides:
getSchemein classPortFilter
-
isAccessAllowed
protected boolean isAccessAllowed(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) throws Exception Retains the parent method's port-matching behavior but additionally guarantees that theServletRequest.isSecure(). If the port does not match or the request is not secure, access is denied.- Overrides:
isAccessAllowedin classPortFilter- Parameters:
request- the incomingServletRequestresponse- the outgoingServletResponse- ignored in this implementationmappedValue- the filter-specific config value mapped to this filter in the URL rules mappings - ignored by this implementation.- Returns:
trueif the request is received on an expected SSL port and therequest.isSecure(),falseotherwise.- Throws:
Exception- if the call tosuper.isAccessAllowedthrows an exception.- Since:
- 1.2
-
postHandle
protected void postHandle(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) If HTTP Strict Transport Security (HSTS) is enabled the HTTP header will be written, otherwise this method does nothing.- Overrides:
postHandlein classAdviceFilter- Parameters:
request- the incomingServletRequestresponse- the outgoingServletResponse
-