* @param header
* The HTTP header value to parse.
* @return The parsed challenge request.
*/
public static ChallengeRequest parseAuthenticateHeader(String header) {
ChallengeRequest result = null;
if (header != null) {
final int space = header.indexOf(' ');
if (space != -1) {
final String scheme = header.substring(0, space);
result = new ChallengeRequest(new ChallengeScheme("HTTP_"
+ scheme, scheme), null);
// Parse the parameters to extract the realm
final String rest = header.substring(space + 1);
parseParameters(rest, result.getParameters());
result.setRealm(result.getParameters().getFirstValue("realm"));
} else {
final String scheme = header.substring(0);
result = new ChallengeRequest(new ChallengeScheme("HTTP_"
+ scheme, scheme), null);
}
}
// Give a chance to the authentication helper to do further parsing
final AuthenticationHelper helper = Engine.getInstance().findHelper(
result.getScheme(), true, false);
if (helper != null) {
helper.parseRequest(result, header);
} else {
Context.getCurrentLogger().warning(
"Challenge scheme " + result.getScheme()
+ " not supported by the Restlet engine.");
}
return result;
}