Digest digest = new Digest(line);
if (authComponent != null) {
AuthUser user = authComponent.getAuthUser(digest.getUsername(), context);
String hashedPassword = null;
if (user == null) throw new UnauthorizedException();
if (user.isEncrypted() == false) {
//A1 = username:realm:password
String a1 = user.getAuthUsername() + ":"
+ realm + ":" + user.getAuthPassword();
String hash1 = encode(getMD5(a1));
//A2 = Method:URI
String a2 = request.getRequestLine().getMethod()
+ ":" + request.getRequestLine().getUri();
String hash2 = encode(getMD5(a2));
//Digest = A1:nonce:nonce-count:cnonce:qop:A2
String digestPassword = hash1 + ":" + digest.getNonce()
+ ":" + digest.getNc() + ":" + digest.getCnonce()
+ ":" + digest.getQop() + ":" + hash2;
hashedPassword = encode(getMD5(digestPassword));
}
String username = digest.getUsername();
String password = digest.getResponse();
if (username != null && password != null
&& username.equals(user.getAuthUsername())
&& password.equals(hashedPassword)) {
return user.getAuthUsername();
}
}
}
throw new UnauthorizedException();
}