case DIGEST: this.basicAuth = null; this.digestAuth = new DigestAuthenticator(digestCredentials, limit); break; case UNIVERSAL: this.basicAuth = new BasicAuthenticator(basicCredentials); this.digestAuth = new DigestAuthenticator(digestCredentials, limit); break; default:
final StringBuilder sb = new StringBuilder(100); sb.append("Digest "); append(sb, "username", credentials.getUsername()); append(sb, "realm", ds.getRealm()); append(sb, "nonce", ds.getNonce()); append(sb, "opaque", ds.getOpaque()); append(sb, "algorithm", ds.getAlgorithm().toString(), false); append(sb, "qop", ds.getQop().toString(), false); append(sb, "uri", uri); ha1 = md5(md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType())))); } else { ha1 = md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType()))); final String ha2 = md5(requestContext.getMethod(), uri); response = md5(ha1, ds.getNonce(), ha2); } else { final String cnonce = randomBytes(CLIENT_NONCE_BYTE_COUNT); // client nonce append(sb, "cnonce", cnonce); final String nc = String.format("%08x", ds.incrementCounter()); // counter append(sb, "nc", nc, false); response = md5(ha1, ds.getNonce(), nc, cnonce, ds.getQop().toString(), ha2); append(sb, "response", response);
/** * Generate a random sequence of bytes and return its hex representation * * @param nbBytes number of bytes to generate * @return hex string */ private String randomBytes(final int nbBytes) { final byte[] bytes = new byte[nbBytes]; randomGenerator.nextBytes(bytes); return bytesToHex(bytes); }
final DigestScheme digestScheme = parseAuthHeaders(response.getHeaders().get(HttpHeaders.WWW_AUTHENTICATE)); if (digestScheme == null) { return false; final boolean success = HttpAuthenticationFilter.repeatRequest(request, response, createNextAuthToken(digestScheme, request, cred)); if (success) {
/** * Append comma separated key=value token. The value gets enclosed in * quotes. * * @param sb string builder instance * @param key key string * @param value value string */ private static void append(final StringBuilder sb, final String key, final String value) { append(sb, key, value, true); }
/** * Process request and add authentication information if possible. * * @param request Request context. * @return {@code true} if authentication information was added. * @throws IOException When error with encryption occurs. */ boolean filterRequest(final ClientRequestContext request) throws IOException { final DigestScheme digestScheme = digestCache.get(request.getUri()); if (digestScheme != null) { final HttpAuthenticationFilter.Credentials cred = HttpAuthenticationFilter.getCredentials(request, this.credentials, HttpAuthenticationFilter.Type.DIGEST); if (cred != null) { request.getHeaders().add(HttpHeaders.AUTHORIZATION, createNextAuthToken(digestScheme, request, cred)); return true; } } return false; }
if (digestAuth.filterRequest(request)) { operation = Type.DIGEST; operation = Type.BASIC; } else if (lastSuccessfulMethod == Type.DIGEST) { if (digestAuth.filterRequest(request)) { operation = Type.DIGEST;
digestAuth.filterResponse(request, response); success = basicAuth.filterResponseAndAuthenticate(request, response); } else if (result == Type.DIGEST) { success = digestAuth.filterResponse(request, response);
final DigestScheme digestScheme = parseAuthHeaders(response.getHeaders().get(HttpHeaders.WWW_AUTHENTICATE)); if (digestScheme == null) { return false; final boolean success = HttpAuthenticationFilter.repeatRequest(request, response, createNextAuthToken(digestScheme, request, cred)); if (success) {
/** * Append comma separated key=value token. The value gets enclosed in * quotes. * * @param sb string builder instance * @param key key string * @param value value string */ private static void append(final StringBuilder sb, final String key, final String value) { append(sb, key, value, true); }
/** * Process request and add authentication information if possible. * * @param request Request context. * @return {@code true} if authentication information was added. * @throws IOException When error with encryption occurs. */ boolean filterRequest(final ClientRequestContext request) throws IOException { final DigestScheme digestScheme = digestCache.get(request.getUri()); if (digestScheme != null) { final HttpAuthenticationFilter.Credentials cred = HttpAuthenticationFilter.getCredentials(request, this.credentials, HttpAuthenticationFilter.Type.DIGEST); if (cred != null) { request.getHeaders().add(HttpHeaders.AUTHORIZATION, createNextAuthToken(digestScheme, request, cred)); return true; } } return false; }
if (digestAuth.filterRequest(request)) { operation = Type.DIGEST; operation = Type.BASIC; } else if (lastSuccessfulMethod == Type.DIGEST) { if (digestAuth.filterRequest(request)) { operation = Type.DIGEST;
digestAuth.filterResponse(request, response); success = basicAuth.filterResponseAndAuthenticate(request, response); } else if (result == Type.DIGEST) { success = digestAuth.filterResponse(request, response);
final StringBuilder sb = new StringBuilder(100); sb.append("Digest "); append(sb, "username", credentials.getUsername()); append(sb, "realm", ds.getRealm()); append(sb, "nonce", ds.getNonce()); append(sb, "opaque", ds.getOpaque()); append(sb, "algorithm", ds.getAlgorithm().toString(), false); append(sb, "qop", ds.getQop().toString(), false); append(sb, "uri", uri); ha1 = md5(md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType())))); } else { ha1 = md5(credentials.getUsername(), ds.getRealm(), new String(credentials.getPassword(), MessageUtils.getCharset(requestContext.getMediaType()))); final String ha2 = md5(requestContext.getMethod(), uri); response = md5(ha1, ds.getNonce(), ha2); } else { final String cnonce = randomBytes(CLIENT_NONCE_BYTE_COUNT); // client nonce append(sb, "cnonce", cnonce); final String nc = String.format("%08x", ds.incrementCounter()); // counter append(sb, "nc", nc, false); response = md5(ha1, ds.getNonce(), nc, cnonce, ds.getQop().toString(), ha2); append(sb, "response", response);
final DigestScheme digestScheme = parseAuthHeaders(response.getHeaders().get(HttpHeaders.WWW_AUTHENTICATE)); if (digestScheme == null) { return false; final boolean success = HttpAuthenticationFilter.repeatRequest(request, response, createNextAuthToken(digestScheme, request, cred)); if (success) {
/** * Generate a random sequence of bytes and return its hex representation * * @param nbBytes number of bytes to generate * @return hex string */ private String randomBytes(final int nbBytes) { final byte[] bytes = new byte[nbBytes]; randomGenerator.nextBytes(bytes); return bytesToHex(bytes); }
/** * Append comma separated key=value token. The value gets enclosed in * quotes. * * @param sb string builder instance * @param key key string * @param value value string */ private static void append(final StringBuilder sb, final String key, final String value) { append(sb, key, value, true); }
/** * Process request and add authentication information if possible. * * @param request Request context. * @return {@code true} if authentication information was added. * @throws IOException When error with encryption occurs. */ boolean filterRequest(final ClientRequestContext request) throws IOException { final DigestScheme digestScheme = digestCache.get(request.getUri()); if (digestScheme != null) { final HttpAuthenticationFilter.Credentials cred = HttpAuthenticationFilter.getCredentials(request, this.credentials, HttpAuthenticationFilter.Type.DIGEST); if (cred != null) { request.getHeaders().add(HttpHeaders.AUTHORIZATION, createNextAuthToken(digestScheme, request, cred)); return true; } } return false; }
if (digestAuth.filterRequest(request)) { operation = Type.DIGEST; operation = Type.BASIC; } else if (lastSuccessfulMethod == Type.DIGEST) { if (digestAuth.filterRequest(request)) { operation = Type.DIGEST;
case DIGEST: this.basicAuth = null; this.digestAuth = new DigestAuthenticator(digestCredentials, limit); break; case UNIVERSAL: this.basicAuth = new BasicAuthenticator(basicCredentials); this.digestAuth = new DigestAuthenticator(digestCredentials, limit); break; default: