@Override public URI getURI() { return DigestAuthentication.this.getURI(); }
@Override public Result authenticate(Request request, ContentResponse response, String wwwAuthenticate, Attributes context) { // Avoid case sensitivity problems on the 'D' character String type = "igest"; wwwAuthenticate = wwwAuthenticate.substring(wwwAuthenticate.indexOf(type) + type.length()); Map<String, String> params = parseParams(wwwAuthenticate); String nonce = params.get("nonce"); if (nonce == null || nonce.length() == 0) return null; String opaque = params.get("opaque"); String algorithm = params.get("algorithm"); if (algorithm == null) algorithm = "MD5"; MessageDigest digester = getMessageDigest(algorithm); if (digester == null) return null; String serverQOP = params.get("qop"); String clientQOP = null; if (serverQOP != null) { List<String> serverQOPValues = Arrays.asList(serverQOP.split(",")); if (serverQOPValues.contains("auth")) clientQOP = "auth"; else if (serverQOPValues.contains("auth-int")) clientQOP = "auth-int"; } return new DigestResult(request.getURI(), response.getContent(), realm, user, password, algorithm, nonce, clientQOP, opaque); }
@Override public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context) { Map<String, String> params = headerInfo.getParameters(); String nonce = params.get("nonce"); if (nonce == null || nonce.length() == 0) return null; String opaque = params.get("opaque"); String algorithm = params.get("algorithm"); if (algorithm == null) algorithm = "MD5"; MessageDigest digester = getMessageDigest(algorithm); if (digester == null) return null; String serverQOP = params.get("qop"); String clientQOP = null; if (serverQOP != null) { List<String> serverQOPValues = StringUtil.csvSplit(null,serverQOP,0,serverQOP.length()); if (serverQOPValues.contains("auth")) clientQOP = "auth"; else if (serverQOPValues.contains("auth-int")) clientQOP = "auth-int"; } String realm = getRealm(); if (ANY_REALM.equals(realm)) realm = headerInfo.getRealm(); return new DigestResult(headerInfo.getHeader(), response.getContent(), realm, user, password, algorithm, nonce, clientQOP, opaque); }
private Map<String, String> parseParams(String wwwAuthenticate) { Map<String, String> result = new HashMap<>(); List<String> parts = splitParams(wwwAuthenticate); for (String part : parts) { Matcher matcher = PARAM_PATTERN.matcher(part); if (matcher.matches()) { String name = matcher.group(1).trim().toLowerCase(Locale.ENGLISH); String value = matcher.group(2).trim(); if (value.startsWith("\"") && value.endsWith("\"")) value = value.substring(1, value.length() - 1); result.put(name, value); } } return result; }
@Override public Result authenticate(Request request, ContentResponse response, String wwwAuthenticate, Attributes context) { // Avoid case sensitivity problems on the 'D' character String type = "igest"; wwwAuthenticate = wwwAuthenticate.substring(wwwAuthenticate.indexOf(type) + type.length()); Map<String, String> params = parseParams(wwwAuthenticate); String nonce = params.get("nonce"); if (nonce == null || nonce.length() == 0) return null; String opaque = params.get("opaque"); String algorithm = params.get("algorithm"); if (algorithm == null) algorithm = "MD5"; MessageDigest digester = getMessageDigest(algorithm); if (digester == null) return null; String serverQOP = params.get("qop"); String clientQOP = null; if (serverQOP != null) { List<String> serverQOPValues = Arrays.asList(serverQOP.split(",")); if (serverQOPValues.contains("auth")) clientQOP = "auth"; else if (serverQOPValues.contains("auth-int")) clientQOP = "auth-int"; } return new DigestResult(request.getURI(), response.getContent(), realm, user, password, algorithm, nonce, clientQOP, opaque); }
private Map<String, String> parseParams(String wwwAuthenticate) { Map<String, String> result = new HashMap<>(); List<String> parts = splitParams(wwwAuthenticate); for (String part : parts) { Matcher matcher = PARAM_PATTERN.matcher(part); if (matcher.matches()) { String name = matcher.group(1).trim().toLowerCase(Locale.ENGLISH); String value = matcher.group(2).trim(); if (value.startsWith("\"") && value.endsWith("\"")) value = value.substring(1, value.length() - 1); result.put(name, value); } } return result; }