net.spy.jwebkit.auth
Class AuthFilter

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.jwebkit.JWFilter
          extended by net.spy.jwebkit.auth.AuthFilter
All Implemented Interfaces:
javax.servlet.Filter
Direct Known Subclasses:
BasicAuthFilter, BasicOrDigestAuthFilter, DigestAuthFilter, FormAuthFilter

public abstract class AuthFilter
extends JWFilter

ServletFilter to intercept requests and ensure they're authenticated and authorized.


Field Summary
static java.lang.String AUTH_REQ_HEADER
          The HTTP request header used to send authentication credentials.
static java.lang.String AUTH_RES_HEADER
          The HTTP response header used to issue the authentication challenge.
 
Constructor Summary
AuthFilter()
           
 
Method Summary
protected  void doAuthedChain(java.security.Principal p, javax.servlet.http.HttpServletRequest hreq, javax.servlet.http.HttpServletResponse hres, javax.servlet.FilterChain chain)
          Invoked when the authentication credentials match and the user should be permitted to access the requested resource.
protected abstract  void doCheckedFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
          Run whatever authentication filters need to be attempted here.
 void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
           
protected  AuthAdaptor getAuthAdaptor()
          Get the AuthAdaptor used by this filter.
protected abstract  java.lang.String getAuthType()
          Get the authentication type used by this filter.
protected  javax.servlet.http.HttpServletRequest getRequestWithPrincipal(java.security.Principal p, javax.servlet.http.HttpServletRequest hreq, javax.servlet.http.HttpServletResponse hres)
          Get a wrapper HttpServletRequest instance that wraps the given request and contains the given principal.
protected  javax.servlet.http.HttpServletRequest getRequestWithPrincipal(java.security.Principal p, javax.servlet.http.HttpServletRequest hreq, javax.servlet.http.HttpServletResponse hres, java.lang.String authType)
          Get a wrapper HttpServletRequest instance that wraps the given request and contains the given principal.
 void init(javax.servlet.FilterConfig c)
           
 
Methods inherited from class net.spy.jwebkit.JWFilter
destroy, getConfig
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTH_RES_HEADER

public static final java.lang.String AUTH_RES_HEADER
The HTTP response header used to issue the authentication challenge.

See Also:
Constant Field Values

AUTH_REQ_HEADER

public static final java.lang.String AUTH_REQ_HEADER
The HTTP request header used to send authentication credentials.

See Also:
Constant Field Values
Constructor Detail

AuthFilter

public AuthFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig c)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Overrides:
init in class JWFilter
Throws:
javax.servlet.ServletException

getAuthAdaptor

protected AuthAdaptor getAuthAdaptor()
Get the AuthAdaptor used by this filter.


getRequestWithPrincipal

protected javax.servlet.http.HttpServletRequest getRequestWithPrincipal(java.security.Principal p,
                                                                        javax.servlet.http.HttpServletRequest hreq,
                                                                        javax.servlet.http.HttpServletResponse hres,
                                                                        java.lang.String authType)
Get a wrapper HttpServletRequest instance that wraps the given request and contains the given principal.

Parameters:
p - the given principal
hreq - the http servlet request
hres - the http servlet response
authType - the authentication type
Returns:
the wrapper request

getRequestWithPrincipal

protected javax.servlet.http.HttpServletRequest getRequestWithPrincipal(java.security.Principal p,
                                                                        javax.servlet.http.HttpServletRequest hreq,
                                                                        javax.servlet.http.HttpServletResponse hres)
Get a wrapper HttpServletRequest instance that wraps the given request and contains the given principal. Defaults to the auth type returned from getAuthType().

Parameters:
p - the given principal
hreq - the http servlet request
hres - the http servlet response
Returns:
the wrapper request

getAuthType

protected abstract java.lang.String getAuthType()
Get the authentication type used by this filter.

Returns:
one of the HttpServletRequest auth types.
See Also:
HttpServletRequest

doAuthedChain

protected void doAuthedChain(java.security.Principal p,
                             javax.servlet.http.HttpServletRequest hreq,
                             javax.servlet.http.HttpServletResponse hres,
                             javax.servlet.FilterChain chain)
                      throws java.io.IOException,
                             javax.servlet.ServletException
Invoked when the authentication credentials match and the user should be permitted to access the requested resource. The default implementation creates a wrapped request containing the principal and invokes the next item in the chain.

Parameters:
p - the principal of the remote requester
hreq - the request
hres - the response
chain - the filter chain
Throws:
java.io.IOException
javax.servlet.ServletException
See Also:
getRequestWithPrincipal(Principal, HttpServletRequest, HttpServletResponse)

doFilter

public void doFilter(javax.servlet.ServletRequest req,
                     javax.servlet.ServletResponse res,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Throws:
java.io.IOException
javax.servlet.ServletException

doCheckedFilter

protected abstract void doCheckedFilter(javax.servlet.ServletRequest req,
                                        javax.servlet.ServletResponse res,
                                        javax.servlet.FilterChain chain)
                                 throws java.io.IOException,
                                        javax.servlet.ServletException
Run whatever authentication filters need to be attempted here. This will only be evaluated when there is no exception list.

Parameters:
req - the request
res - the response
chain - the chain
Throws:
java.io.IOException - if there are errors reading or writing
javax.servlet.ServletException - if there's a general error


Copyright © 1995-2007 SPY Internetworking. All Rights Reserved.