use of org.apache.http.auth.UsernamePasswordCredentials in project hive by apache.
the class JIRAService method publishComments.
void publishComments(String comments) {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
String url = String.format("%s/rest/api/2/issue/%s/comment", mUrl, mName);
URL apiURL = new URL(mUrl);
httpClient.getCredentialsProvider().setCredentials(new AuthScope(apiURL.getHost(), apiURL.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(mUser, mPassword));
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute("preemptive-auth", new BasicScheme());
httpClient.addRequestInterceptor(new PreemptiveAuth(), 0);
HttpPost request = new HttpPost(url);
ObjectMapper mapper = new ObjectMapper();
StringEntity params = new StringEntity(mapper.writeValueAsString(new Body(comments)));
request.addHeader("Content-Type", "application/json");
request.setEntity(params);
HttpResponse httpResponse = httpClient.execute(request, localcontext);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() != 201) {
throw new RuntimeException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
}
mLogger.info("JIRA Response Metadata: " + httpResponse);
} catch (Exception e) {
mLogger.error("Encountered error attempting to post comment to " + mName, e);
} finally {
httpClient.getConnectionManager().shutdown();
}
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jersey by jersey.
the class AuthTest method testPreemptiveAuth.
@Test
public void testPreemptiveAuth() {
CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
ClientConfig cc = new ClientConfig();
cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider).property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
assertEquals("GET", r.request().get(String.class));
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jersey by jersey.
the class AuthTest method testAuthInteractiveGet.
@Test
public void testAuthInteractiveGet() {
CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
ClientConfig cc = new ClientConfig();
cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri()).path("test");
assertEquals("GET", r.request().get(String.class));
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jersey by jersey.
the class AuthTest method testAuthDelete.
@Test
public void testAuthDelete() {
CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
ClientConfig cc = new ClientConfig();
cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri()).path("test");
Response response = r.request().delete();
assertEquals(response.getStatus(), 204);
}
use of org.apache.http.auth.UsernamePasswordCredentials in project android_frameworks_base by ParanoidAndroid.
the class DefaultHttpClientTest method authenticateDigestAlgorithm.
private void authenticateDigestAlgorithm(String algorithm) throws Exception {
String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
DigestScheme digestScheme = new DigestScheme();
digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
HttpGet get = new HttpGet();
digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
Aggregations