public class JRFC2617 extends Object
See http://www.ietf.org/rfc/rfc2617.txt and http://en.wikipedia.org/wiki/Digest_access_authentication
Note Though the responses exactly match those in the Wikipedia article and thise generated by Chrome, I never got this to actually work on test servers such as httpbin.org. So I cannot guarantee that this will actually work in a real environment. Help!
Modifier and Type | Class and Description |
---|---|
static class |
JRFC2617.Key |
Modifier and Type | Field and Description |
---|---|
protected Map<String,String> |
crMap |
static String |
DIGEST |
protected URL |
failedURL |
protected String |
fullResponse |
protected MessageDigest |
messageDigest |
protected int |
nonceCount |
protected Random |
random |
Constructor and Description |
---|
JRFC2617(HttpURLConnection failedWith401)
Alternative Constructor
|
JRFC2617(String challenge)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
applyToConnection(URLConnection conn)
Convenience method to put the repsonse in the connection
|
protected Map<String,String> |
createChallengeMap(String challenge) |
protected String |
createCnonce()
Create a cnonce.
|
protected MessageDigest |
createMessageDigest(String algo) |
protected String |
createNonceCountString(int count) |
String |
createResponse(String username,
String password,
String cnonce,
String method,
String uri)
Create the response credentials
|
HttpURLConnection |
createRetryConnection(String username,
String password)
This method only works after the failedWith401 style constructor
|
String |
encode16to32(byte[] digest)
Represent the MD5 digest as Hex.
|
protected String |
getChallenge(JRFC2617.Key key) |
String |
MD5(String... args)
Makes the MD5 of arg[0]:arg[1]:arg[2]...
|
String |
unq(String in)
Unquote a String, removing leading and trailing "
|
public static final String DIGEST
protected int nonceCount
protected final MessageDigest messageDigest
protected final Random random
protected String fullResponse
protected URL failedURL
public JRFC2617(String challenge)
challenge
- should begin with "Digest"public JRFC2617(HttpURLConnection failedWith401)
failedWith401
- the connection that gave you a 401public String createResponse(String username, String password, String cnonce, String method, String uri)
username
- non-null usernamepassword
- non-null passwordcnonce
- may be null, typical, in which case one will be createdmethod
- non-nulluri
- non-nullpublic HttpURLConnection createRetryConnection(String username, String password) throws IOException
username
- password
- IOException
public void applyToConnection(URLConnection conn)
conn
- public String MD5(String... args)
args
- public String unq(String in)
in
- public String encode16to32(byte[] digest)
digest
- 16 charsprotected String createCnonce()
protected String getChallenge(JRFC2617.Key key)
protected MessageDigest createMessageDigest(String algo)
protected String createNonceCountString(int count)