javawebparts.filter
Class SessionLimiterFilter

java.lang.Object
  |
  +--javawebparts.filter.SessionLimiterFilter
All Implemented Interfaces:
javax.servlet.Filter

public class SessionLimiterFilter
extends java.lang.Object
implements javax.servlet.Filter

This filter can be used to limit the number of concurrent sessions allowed by a webapp at any given time.

You have to specify the number of allowed sessions and a page where you want to forward requests that would exceed the limit.

Important!
In order to use the session limiting facility you will also have to configure the listener javawebparts.listener.SessionLimiterListener in your web.xml.

Init parameters are:


Example configuration in web.xml:

<filter>
  <filter-name>SessionLimiterFilter< /filter-name>
  <filter-class>javawebparts.filter.SessionLimiterFilter< /filter-class>
  <init-param>
    <param-name>maxSessions</param-name>
    <param-value>1</param-value>
  </init-param>
  <init-param>
    <param-name>forwardTo</param-name>
    <param-value>/SLFTooMany.jsp.jpg,< /param-value>
  </init-param>
  <init-param>
    <param-name>pathSpec</param-name>
    <param-value>exclude</param-value>
  </init-param>
  <init-param>
    <param-name>pathList</param-name>
    <param-value>/img/header1.gif< /param-value>
  </init-param>
</filter>

<filter-mapping>
  <filter-name>SessionLimiterFilter< /filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Author:
Tamas Szabo

Field Summary
private  javax.servlet.ServletContext ctx
          The ServletContext of the filter.
private  boolean filterExpired
          Filter request with expired session ID.
private  java.lang.String forwardTo
          A path to forward to when access is denied.
private static org.apache.commons.logging.Log log
          Log instance.
private  int maxSessions
          The number of session allowed.
private  java.util.ArrayList pathList
          List of paths for filter functionality determination.
private  java.lang.String pathSpec
          Whether pathList includes or excludes.
 
Constructor Summary
SessionLimiterFilter()
           
 
Method Summary
 void destroy()
          Destroy.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain filterChain)
          Do filter's work.
 void init(javax.servlet.FilterConfig filterConfig)
          Initialize this filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.


forwardTo

private java.lang.String forwardTo
A path to forward to when access is denied.


ctx

private javax.servlet.ServletContext ctx
The ServletContext of the filter.


pathSpec

private java.lang.String pathSpec
Whether pathList includes or excludes.


pathList

private java.util.ArrayList pathList
List of paths for filter functionality determination.


maxSessions

private int maxSessions
The number of session allowed.


filterExpired

private boolean filterExpired
Filter request with expired session ID.

Constructor Detail

SessionLimiterFilter

public SessionLimiterFilter()
Method Detail

destroy

public void destroy()
Destroy.

Specified by:
destroy in interface javax.servlet.Filter

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Initialize this filter.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig - The configuration information for this filter.
Throws:
javax.servlet.ServletException - ServletException.

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain filterChain)
              throws javax.servlet.ServletException,
                     java.io.IOException
Do filter's work.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
request - The current request object.
response - The current response object.
filterChain - The current filter chain.
Throws:
javax.servlet.ServletException - ServletException.
java.io.IOException - IOException.


Copyright © 2005 Frank W. Zammetti