org.tynamo.security.shiro.authz
Class PortFilter

java.lang.Object
  extended by org.apache.shiro.web.servlet.ServletContextSupport
      extended by org.apache.shiro.web.servlet.AbstractFilter
          extended by org.apache.shiro.web.servlet.NameableFilter
              extended by org.apache.shiro.web.servlet.OncePerRequestFilter
                  extended by org.apache.shiro.web.servlet.AdviceFilter
                      extended by org.tynamo.security.shiro.AccessControlFilter
                          extended by org.tynamo.security.shiro.authz.AuthorizationFilter
                              extended by org.tynamo.security.shiro.authz.PortFilter
All Implemented Interfaces:
javax.servlet.Filter, org.apache.shiro.util.Nameable
Direct Known Subclasses:
SslFilter

public class PortFilter
extends AuthorizationFilter

A copy of Shiro's 1.2.0 PortFilter that works with tapestry-security 0.4.x A Filter that requires the request to be on a specific port, and if not, redirects to the same URL on that port.

Since:
0.4.1

Field Summary
static int DEFAULT_HTTP_PORT
           
static String HTTP_SCHEME
           
 
Fields inherited from class org.tynamo.security.shiro.AccessControlFilter
GET_METHOD, LOGIN_URL, pathMatcher, POST_METHOD, REDIRECT_TO_SAVED_URL, SUCCESS_URL, UNAUTHORIZED_URL
 
Fields inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
 
Fields inherited from class org.apache.shiro.web.servlet.AbstractFilter
filterConfig
 
Constructor Summary
PortFilter(LoginContextService loginContextService)
           
 
Method Summary
 int getPort()
           
protected  String getScheme(String requestScheme, int port)
           
protected  boolean isAccessAllowed(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue)
          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.
protected  boolean onAccessDenied(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Object mappedValue)
          Redirects the request to the same exact incoming URL, but with the port listed in the filter's configuration.
 void setPort(int port)
           
protected  int toPort(Object mappedValue)
           
 
Methods inherited from class org.tynamo.security.shiro.authz.AuthorizationFilter
getUnauthorizedUrl, onAccessDenied, setUnauthorizedUrl
 
Methods inherited from class org.tynamo.security.shiro.AccessControlFilter
addConfig, getLoginContextService, getLoginUrl, getSubject, getSuccessUrl, isLoginRequest, isRedirectToSavedUrl, onPreHandle, preHandle, redirectToLogin, saveRequest, saveRequestAndRedirectToLogin, setConfig, setLoginUrl, setRedirectToSavedUrl, setSuccessUrl
 
Methods inherited from class org.apache.shiro.web.servlet.AdviceFilter
afterCompletion, cleanup, doFilterInternal, executeChain, postHandle
 
Methods inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isEnabled, isEnabled, setEnabled, shouldNotFilter
 
Methods inherited from class org.apache.shiro.web.servlet.NameableFilter
getName, setName, toStringBuilder
 
Methods inherited from class org.apache.shiro.web.servlet.AbstractFilter
destroy, getFilterConfig, getInitParam, init, onFilterConfigSet, setFilterConfig
 
Methods inherited from class org.apache.shiro.web.servlet.ServletContextSupport
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_HTTP_PORT

public static final int DEFAULT_HTTP_PORT
See Also:
Constant Field Values

HTTP_SCHEME

public static final String HTTP_SCHEME
See Also:
Constant Field Values
Constructor Detail

PortFilter

public PortFilter(LoginContextService loginContextService)
Method Detail

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


Copyright © 2004-2013. All Rights Reserved.