Class PortFilter

All Implemented Interfaces:
javax.servlet.Filter, org.apache.shiro.lang.util.Nameable, PathConfigProcessor
Direct Known Subclasses:
SslFilter

public class PortFilter extends AuthorizationFilter
A Filter that requires the request to be on a specific port, and if not, redirects to the same URL on that port.

Example config:

 [filters]
 port.port = 80
 

[urls] /some/path/** = port # override for just this path: /another/path/** = port[8080]

Since:
1.0
  • Field Details

  • Constructor Details

    • PortFilter

      public PortFilter()
  • Method Details

    • getPort

      public int getPort()
    • setPort

      public void setPort(int port)
    • toPort

      protected int toPort(Object mappedValue)
    • isAccessAllowed

      protected boolean isAccessAllowed(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) throws Exception
      Description copied from class: AccessControlFilter
      Returns true if the request is allowed to proceed through the filter normally, or false if the request should be handled by the onAccessDenied(request,response,mappedValue) method instead.
      Specified by:
      isAccessAllowed in class AccessControlFilter
      Parameters:
      request - the incoming ServletRequest
      response - the outgoing ServletResponse
      mappedValue - the filter-specific config value mapped to this filter in the URL rules mappings.
      Returns:
      true if the request should proceed through the filter normally, false if the request should be processed by this filter's AccessControlFilter.onAccessDenied(ServletRequest,ServletResponse,Object) method instead.
      Throws:
      Exception - if an error occurs during processing.
    • getScheme

      protected String getScheme(String requestScheme, int port)
    • onAccessDenied

      protected boolean onAccessDenied(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue) throws IOException
      Redirects the request to the same exact incoming URL, but with the port listed in the filter's configuration.
      Overrides:
      onAccessDenied in class AccessControlFilter
      Parameters:
      request - the incoming ServletRequest
      response - the outgoing ServletResponse
      mappedValue - the config specified for the filter in the matching request's filter chain.
      Returns:
      false always to force a redirect.
      Throws:
      IOException