net.spy.jwebkit.auth
Class DigestAuthFilter

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.jwebkit.JWFilter
          extended by net.spy.jwebkit.auth.AuthFilter
              extended by net.spy.jwebkit.auth.DigestAuthFilter
All Implemented Interfaces:
javax.servlet.Filter

public class DigestAuthFilter
extends AuthFilter

AuthFilter implementating digest authentication.


Nested Class Summary
protected static class DigestAuthFilter.ValidationState
          Validation states for digest authentication.
 
Field Summary
 
Fields inherited from class net.spy.jwebkit.auth.AuthFilter
AUTH_REQ_HEADER, AUTH_RES_HEADER
 
Constructor Summary
DigestAuthFilter()
           
 
Method Summary
protected  DigestAuthFilter.ValidationState checkCreds(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.util.Map<java.lang.String,java.lang.String> parsed)
          Check the credentials of this client.
protected  java.lang.String computeResponse(java.lang.String ha1, java.lang.String nonce, java.lang.String nc, java.lang.String cnonce, java.lang.String auth, java.lang.String ha2)
          Compute a digest response.
protected  void doCheckedFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
          Run whatever authentication filters need to be attempted here.
 void doNoAuthChain(javax.servlet.http.HttpServletRequest hreq, javax.servlet.http.HttpServletResponse hres, javax.servlet.FilterChain chain, DigestAuthFilter.ValidationState state)
          Invoked when the authentication credentials do not match, or the credentials are rejected.
protected  java.lang.String generateNonce()
          Generate a nonce to be used in a digest challenge.
protected  java.lang.String generateOpaque()
          Generate an opaque value to be used in a digest challenge.
protected  java.lang.String getAuthType()
          Get the authentication type used by this filter.
protected  java.security.Principal getPrincipal(java.lang.String username)
          Get a principal for the given authenticated username.
 void init(javax.servlet.FilterConfig c)
           
protected  boolean isNonceValid(java.lang.String n)
          Determine whether the given nonce should be considered valid.
 
Methods inherited from class net.spy.jwebkit.auth.AuthFilter
doAuthedChain, doFilter, getAuthAdaptor, getRequestWithPrincipal, getRequestWithPrincipal
 
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
 

Constructor Detail

DigestAuthFilter

public DigestAuthFilter()
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 AuthFilter
Throws:
javax.servlet.ServletException

doNoAuthChain

public void doNoAuthChain(javax.servlet.http.HttpServletRequest hreq,
                          javax.servlet.http.HttpServletResponse hres,
                          javax.servlet.FilterChain chain,
                          DigestAuthFilter.ValidationState state)
                   throws java.io.IOException,
                          javax.servlet.ServletException
Invoked when the authentication credentials do not match, or the credentials are rejected. The default implementation sets the status to SC_UNAUTHORIZED and sets the WWW-Authenticate header appropriately.

Parameters:
hreq - servlet request
hres - servlet response
chain - the current filter chain
state - the state (should be INVALID or STALE)
Throws:
java.io.IOException
javax.servlet.ServletException

generateNonce

protected java.lang.String generateNonce()
Generate a nonce to be used in a digest challenge.


isNonceValid

protected boolean isNonceValid(java.lang.String n)
Determine whether the given nonce should be considered valid.

Parameters:
n - the given nonce
Returns:
true if this nonce should be considered valid

generateOpaque

protected java.lang.String generateOpaque()
Generate an opaque value to be used in a digest challenge.


getAuthType

protected java.lang.String getAuthType()
Description copied from class: AuthFilter
Get the authentication type used by this filter.

Specified by:
getAuthType in class AuthFilter
Returns:
one of the HttpServletRequest auth types.
See Also:
HttpServletRequest

doCheckedFilter

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

Specified by:
doCheckedFilter in class AuthFilter
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

computeResponse

protected java.lang.String computeResponse(java.lang.String ha1,
                                           java.lang.String nonce,
                                           java.lang.String nc,
                                           java.lang.String cnonce,
                                           java.lang.String auth,
                                           java.lang.String ha2)
Compute a digest response.

Parameters:
ha1 - H(unq(username-value) ":" unq(realm-value) ":" passwd)
nonce - the nonce sent from the client
nc - the client nonce count
cnonce - the client nonce
auth - the qop type
ha2 - H(Method ":" digest-uri-value)
Returns:
the computed response

checkCreds

protected DigestAuthFilter.ValidationState checkCreds(javax.servlet.http.HttpServletRequest req,
                                                      javax.servlet.http.HttpServletResponse res,
                                                      java.util.Map<java.lang.String,java.lang.String> parsed)
Check the credentials of this client.

Parameters:
req - the request
res - the response
parsed - the parsed authorization header
Returns:
the appropriate validation state

getPrincipal

protected java.security.Principal getPrincipal(java.lang.String username)
Get a principal for the given authenticated username.



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