com.mycompany.messages
Class AccessControlFilter

java.lang.Object
  extended bycom.mycompany.messages.AccessControlFilter
All Implemented Interfaces:
javax.servlet.Filter

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

This class provides access control for all requests in the Project Billboard application, by looking for the authentication token in the session and forwarding to the login page if not found.

Version:
1.0
Author:
Hans Bergsten, Gefion Software

Field Summary
private  javax.servlet.FilterConfig config
           
private  java.lang.String loginPage
           
 
Constructor Summary
AccessControlFilter()
           
 
Method Summary
 void destroy()
          Resets the instance variable.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Looks for the authentication token in the session and forwards to the login page if not found.
private  java.lang.String getContextRelativeURI(javax.servlet.http.HttpServletRequest request)
          Returns a context-relative path for the request, including the query string, if any.
private  java.lang.String getForwardURI(javax.servlet.http.HttpServletRequest request)
          Returns the context-relative path to the login page, with the parameters used by the login page.
 void init(javax.servlet.FilterConfig config)
          Reads the "loginPage" filter init parameter and saves the value in an instance variable.
private  boolean isAuthenticated(javax.servlet.http.HttpServletRequest request)
          Returns true if the session contains the authentication token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

private javax.servlet.FilterConfig config

loginPage

private java.lang.String loginPage
Constructor Detail

AccessControlFilter

public AccessControlFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
Reads the "loginPage" filter init parameter and saves the value in an instance variable.

Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException - if the "loginPage" parameter is not set.

destroy

public void destroy()
Resets the instance variable.

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Looks for the authentication token in the session and forwards to the login page if not found.

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
java.io.IOException
javax.servlet.ServletException

isAuthenticated

private boolean isAuthenticated(javax.servlet.http.HttpServletRequest request)
Returns true if the session contains the authentication token.


getForwardURI

private java.lang.String getForwardURI(javax.servlet.http.HttpServletRequest request)
Returns the context-relative path to the login page, with the parameters used by the login page.


getContextRelativeURI

private java.lang.String getContextRelativeURI(javax.servlet.http.HttpServletRequest request)
Returns a context-relative path for the request, including the query string, if any.