use of org.apache.http.impl.auth.DigestSchemeFactory in project robovm by robovm.
the class DefaultHttpClient method createAuthSchemeRegistry.
@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
AuthSchemeRegistry registry = new AuthSchemeRegistry();
registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
return registry;
}
use of org.apache.http.impl.auth.DigestSchemeFactory in project apex-core by apache.
the class WebServicesClient method initAuth.
public static void initAuth(ConfigProvider configuration) {
// Setting up BASIC and DIGEST auth
setupUserPassAuthScheme(AuthScheme.BASIC, AuthSchemes.BASIC, new BasicSchemeFactory(), configuration);
setupUserPassAuthScheme(AuthScheme.DIGEST, AuthSchemes.DIGEST, new DigestSchemeFactory(), configuration);
// Adding kerberos standard auth
setupHttpAuthScheme(AuthSchemes.KERBEROS, new KerberosSchemeFactory(), AuthScope.ANY, DEFAULT_TOKEN_CREDENTIALS);
authRegistry = registryBuilder.build();
}
use of org.apache.http.impl.auth.DigestSchemeFactory in project platform_external_apache-http by android.
the class DefaultHttpClient method createAuthSchemeRegistry.
@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
AuthSchemeRegistry registry = new AuthSchemeRegistry();
registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
return registry;
}
use of org.apache.http.impl.auth.DigestSchemeFactory in project XobotOS by xamarin.
the class DefaultHttpClient method createAuthSchemeRegistry.
@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
AuthSchemeRegistry registry = new AuthSchemeRegistry();
registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
return registry;
}
use of org.apache.http.impl.auth.DigestSchemeFactory in project wildfly by wildfly.
the class Utils method makeCallWithBasicAuthn.
/**
* Returns response body for the given URL request as a String. It also checks if the returned HTTP status code is the
* expected one. If the server returns {@link HttpServletResponse#SC_UNAUTHORIZED} and username is provided, then a new
* request is created with the provided credentials (basic authentication).
*
* @param url URL to which the request should be made
* @param user Username (may be null)
* @param pass Password (may be null)
* @param expectedStatusCode expected status code returned from the requested server
* @param checkFollowupAuthState whether to check auth state for followup request - if set to true, followup
* request is sent to server and 200 OK is expected directly (no re-authentication
* challenge - 401 Unauthorized - is expected)
* @return HTTP response body
* @throws IOException
* @throws URISyntaxException
*/
public static String makeCallWithBasicAuthn(URL url, String user, String pass, int expectedStatusCode, boolean checkFollowupAuthState) throws IOException, URISyntaxException {
LOGGER.trace("Requesting URL " + url);
// use UTF-8 charset for credentials
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.BASIC, new BasicSchemeFactory(StandardCharsets.UTF_8)).register(AuthSchemes.DIGEST, new DigestSchemeFactory(StandardCharsets.UTF_8)).build();
try (CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultAuthSchemeRegistry(authSchemeRegistry).build()) {
final HttpGet httpGet = new HttpGet(url.toURI());
HttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
if (HttpServletResponse.SC_UNAUTHORIZED != statusCode || StringUtils.isEmpty(user)) {
assertEquals("Unexpected HTTP response status code.", expectedStatusCode, statusCode);
return EntityUtils.toString(response.getEntity());
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("HTTP response was SC_UNAUTHORIZED, let's authenticate the user " + user);
}
HttpEntity entity = response.getEntity();
if (entity != null)
EntityUtils.consume(entity);
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, pass);
HttpClientContext hc = new HttpClientContext();
hc.setCredentialsProvider(new BasicCredentialsProvider());
hc.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), url.getPort()), credentials);
// enable auth
response = httpClient.execute(httpGet, hc);
statusCode = response.getStatusLine().getStatusCode();
assertEquals("Unexpected status code returned after the authentication.", expectedStatusCode, statusCode);
if (checkFollowupAuthState) {
// Let's disable authentication for this client as we already have all the context necessary to be
// authorized (we expect that gained 'nonce' value can be re-used in our case here).
// By disabling authentication we simply get first server response and thus we can check whether we've
// got 200 OK or different response code.
RequestConfig reqConf = RequestConfig.custom().setAuthenticationEnabled(false).build();
httpGet.setConfig(reqConf);
response = httpClient.execute(httpGet, hc);
statusCode = response.getStatusLine().getStatusCode();
assertEquals("Unexpected status code returned after the authentication.", HttpURLConnection.HTTP_OK, statusCode);
}
return EntityUtils.toString(response.getEntity());
}
}
Aggregations