|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sunlabs.brazil.handler.DigestAuthHandler
Perform digest authentication. This is a minimal implementation of RFC 2069. The "optional" qos parameter is required by IE. The "password" file is at startup time, either as a resource or from the file system, and may contain either plain text or digested passwords (see main() below to digest passwords).
Future enhancements
WWW-Authenticate: Digest realm="myrealm", qop="auth", [req'd for IE] nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41", [optional] domain="/foo" [optional]Sample client return header
Authorization: Digest username="name", realm="foo@bar", nonce="mynonce10", uri="/da.html", response="d58f3f9fa7554da651d3f1901d22ea04", qop=auth, nc=00000001, cnonce="b6ac242cb324c38a" response algorithm: A1 = md5(user:realm:pass) A2 = md5(method:uri) response=md5(A1:nonce:nonceCount:cnonce:qop:A2) - all MD5's are represented as hex: [0-9a-f] - all quotes (") are removed before digesting
Constructor Summary | |
DigestAuthHandler()
|
Method Summary | |
static String |
computeA1(String user,
String realm,
String pass)
Compute the A1 parameter as per the RFC. |
static Properties |
extractAuth(String header)
Parse an auth header, placing the results into a Properties object. |
boolean |
init(Server server,
String propsPrefix)
Initializes the handler. |
static boolean |
isMd5Digest(String s)
See if a string is a valid md5 digest. |
static void |
main(String[] args)
Convert a "plain text" password file into a digested one. |
static String |
md5Digest(String s)
Compute the md5 digest of a string, returning the digest as a hex string. |
boolean |
respond(Request request)
Responds to an HTTP request. |
static boolean |
responseOk(String A1,
String method,
Properties h)
Check the digest response string. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DigestAuthHandler()
Method Detail |
public boolean init(Server server, String propsPrefix)
Handler
init
in interface Handler
server
- The HTTP server that created this Handler
.
Typical Handler
s will use Server.props
to obtain run-time configuration information.propsPrefix
- The handlers name.
The string this Handler
may prepend to all
of the keys that it uses to extract configuration information
from Server.props
. This is set (by the Server
and ChainHandler
) to help avoid configuration parameter
namespace collisions.
true
if this Handler
initialized
successfully, false
otherwise. If
false
is returned, this Handler
should not be used.public boolean respond(Request request) throws IOException
Handler
respond
in interface Handler
request
- The Request
object that represents the HTTP
request.
true
if the request was handled. A request was
handled if a response was supplied to the client, typically
by calling Request.sendResponse()
or
Request.sendError
.
IOException
- if there was an I/O error while sending the response to
the client. Typically, in that case, the Server
will (try to) send an error message to the client and then
close the client's connection.
The IOException
should not be used to silently
ignore problems such as being unable to access some
server-side resource (for example getting a
FileNotFoundException
due to not being able
to open a file). In that case, the Handler
's
duty is to turn that IOException
into a
HTTP response indicating, in this case, that a file could
not be found.
public static boolean responseOk(String A1, String method, Properties h)
A1
- The "A1" hash from the RFCmethod
- The http request method.h
- Properties containing all the name=value options
from the http authentiation header field
(see extractAuth(String)
).public static String computeA1(String user, String realm, String pass)
public static String md5Digest(String s)
public static boolean isMd5Digest(String s)
public static Properties extractAuth(String header)
public static void main(String[] args) throws Exception
Usage: DigestAuthHandler [realm]The stdin, in Properties format, is emitted on stdout with all plain-text passwords digested. If an entry is already digested, it is left alone.
Note, this handler will except either plaintext or digested passwords in the credentials file.
Exception
|
Version 2.1, Generated 12/30/04 Copyright (c) 2001-2004, Sun Microsystems. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |