use of org.apache.http.impl.auth.BasicScheme in project knox by apache.
the class GatewayBasicFuncTest method oozieQueryJobStatus.
/* GET /oozie/v1/jobs?filter=user%3Dbansalm&offset=1&len=50 (body JSON; contains URL)
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 46
Server: Apache-Coyote/1.1
Date: Thu, 14 Feb 2013 16:10:25 GMT
*/
/* GET /oozie/v1/job/0000000-130214094519989-oozie-oozi-W
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 2611
Server: Apache-Coyote/1.1
Date: Thu, 14 Feb 2013 17:39:36 GMT
*/
/* http://192.168.56.101:11000/oozie/v1/job/0000000-130214094519989-oozie-oozi-W?action=start&user.name=sandbox
HTTP/1.1 200 OK
Date: Thu, 14 Feb 2013 17:52:13 GMT
Content-Length: 0
Server: Apache-Coyote/1.1
Set-Cookie: hadoop.auth="u=sandbox&p=sandbox&t=simple&e=1360900333149&s=AU/GeHDNBuK9RBRaBJfrqatjfz8="; Version=1; Path=/
*/
/* PUT /oozie/v1/job/job-3?action=rerun (request body XML, contains URL)
HTTP/1.1 200 OK
Date: Thu, 14 Feb 2013 18:07:45 GMT
Content-Length: 0
Server: Apache-Coyote/1.1
Set-Cookie: hadoop.auth="u=sandbox&p=sandbox&t=simple&e=1360901264892&s=DCOczPqn9mcisCeOb5x2C7LIRc8="; Version=1; Path=/
*/
/* GET /oozie/v1/job/0000000-130214094519989-oozie-oozi-W?show=info (body JSON, contains URL)
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 2611
Server: Apache-Coyote/1.1
Date: Thu, 14 Feb 2013 17:45:23 GMT
*/
private String oozieQueryJobStatus(String user, String password, String id, int status) throws Exception {
driver.getMock("OOZIE").expect().method("GET").pathInfo("/v1/job/" + id).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes("oozie-job-show-info.json")).contentType("application/json");
// NOTE: For some reason REST-assured doesn't like this and ends up failing with Content-Length issues.
URL url = new URL(driver.getUrl("OOZIE") + "/v1/job/" + id + (driver.isUseGateway() ? "" : "?user.name=" + user));
HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
HttpClientBuilder builder = HttpClientBuilder.create();
CloseableHttpClient client = builder.build();
HttpClientContext context = HttpClientContext.create();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost), new UsernamePasswordCredentials(user, password));
context.setCredentialsProvider(credsProvider);
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
context.setAuthCache(authCache);
HttpGet request = new HttpGet(url.toURI());
request.setHeader("X-XSRF-Header", "ksdhfjkhdsjkf");
HttpResponse response = client.execute(targetHost, request, context);
assertThat(response.getStatusLine().getStatusCode(), Matchers.is(status));
String json = EntityUtils.toString(response.getEntity());
String jobStatus = JsonPath.from(json).getString("status");
return jobStatus;
}
use of org.apache.http.impl.auth.BasicScheme in project knox by apache.
the class GatewayMultiFuncTest method testPostWithContentTypeKnox681.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testPostWithContentTypeKnox681() throws Exception {
LOG_ENTER();
MockServer mock = new MockServer("REPEAT", true);
params = new Properties();
params.put("MOCK_SERVER_PORT", mock.getPort());
params.put("LDAP_URL", driver.getLdapUrl());
String topoStr = TestUtils.merge(DAT, "topologies/test-knox678-utf8-chars-topology.xml", params);
File topoFile = new File(config.getGatewayTopologyDir(), "knox681.xml");
FileUtils.writeStringToFile(topoFile, topoStr);
topos.reloadTopologies();
mock.expect().method("PUT").pathInfo("/repeat-context/").respond().status(HttpStatus.SC_CREATED).content("{\"name\":\"value\"}".getBytes()).contentLength(-1).contentType("application/json; charset=UTF-8").header("Location", gatewayUrl + "/knox681/repeat");
String uname = "guest";
String pword = uname + "-password";
HttpHost targetHost = new HttpHost("localhost", gatewayPort, "http");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(uname, pword));
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
CloseableHttpClient client = HttpClients.createDefault();
HttpPut request = new HttpPut(gatewayUrl + "/knox681/repeat");
request.addHeader("X-XSRF-Header", "jksdhfkhdsf");
request.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = client.execute(request, context);
assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_CREATED));
assertThat(response.getFirstHeader("Location").getValue(), endsWith("/gateway/knox681/repeat"));
assertThat(response.getFirstHeader("Content-Type").getValue(), is("application/json; charset=UTF-8"));
String body = new String(IOUtils.toByteArray(response.getEntity().getContent()), Charset.forName("UTF-8"));
assertThat(body, is("{\"name\":\"value\"}"));
response.close();
client.close();
mock.expect().method("PUT").pathInfo("/repeat-context/").respond().status(HttpStatus.SC_CREATED).content("<test-xml/>".getBytes()).contentType("application/xml; charset=UTF-8").header("Location", gatewayUrl + "/knox681/repeat");
client = HttpClients.createDefault();
request = new HttpPut(gatewayUrl + "/knox681/repeat");
request.addHeader("X-XSRF-Header", "jksdhfkhdsf");
request.addHeader("Content-Type", "application/xml");
response = client.execute(request, context);
assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_CREATED));
assertThat(response.getFirstHeader("Location").getValue(), endsWith("/gateway/knox681/repeat"));
assertThat(response.getFirstHeader("Content-Type").getValue(), is("application/xml; charset=UTF-8"));
body = new String(IOUtils.toByteArray(response.getEntity().getContent()), Charset.forName("UTF-8"));
assertThat(the(body), hasXPath("/test-xml"));
response.close();
client.close();
mock.stop();
LOG_EXIT();
}
use of org.apache.http.impl.auth.BasicScheme in project knox by apache.
the class GatewaySslFuncTest method testKnox674SslCipherSuiteConfig.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testKnox674SslCipherSuiteConfig() throws Exception {
LOG_ENTER();
String topoStr = TestUtils.merge(DAT, "test-admin-topology.xml", params);
File topoFile = new File(config.getGatewayTopologyDir(), "test-topology.xml");
FileUtils.writeStringToFile(topoFile, topoStr);
topos.reloadTopologies();
String username = "guest";
String password = "guest-password";
String serviceUrl = gatewayUrl + "/test-topology/api/v1/version";
HttpHost targetHost = new HttpHost("localhost", gatewayPort, gatewayScheme);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(username, password));
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(createInsecureSslContext(), new String[] { "TLSv1.2" }, new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" }, new TrustAllHosts())).build();
HttpGet request = new HttpGet(serviceUrl);
CloseableHttpResponse response = client.execute(request, context);
assertThat(the(new StreamSource(response.getEntity().getContent())), hasXPath("/ServerVersion/version"));
response.close();
client.close();
gateway.stop();
config.setExcludedSSLCiphers(Arrays.asList(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" }));
config.setIncludedSSLCiphers(Arrays.asList(new String[] { "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" }));
startGatewayServer();
serviceUrl = gatewayUrl + "/test-topology/api/v1/version";
try {
client = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(createInsecureSslContext(), new String[] { "TLSv1.2" }, new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" }, new TrustAllHosts())).build();
request = new HttpGet(serviceUrl);
client.execute(request, context);
fail("Expected SSLHandshakeException");
} catch (SSLHandshakeException e) {
// Expected.
client.close();
}
client = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(createInsecureSslContext(), new String[] { "TLSv1.2" }, new String[] { "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" }, new TrustAllHosts())).build();
request = new HttpGet(serviceUrl);
response = client.execute(request, context);
assertThat(the(new StreamSource(response.getEntity().getContent())), hasXPath("/ServerVersion/version"));
response.close();
client.close();
LOG_EXIT();
}
use of org.apache.http.impl.auth.BasicScheme in project jackrabbit by apache.
the class WebDAVTestBase method setUp.
protected void setUp() throws Exception {
super.setUp();
File home = new File("target/jackrabbit-repository");
if (!home.exists()) {
home.mkdirs();
}
File config = new File(home, "repository.xml");
if (!config.exists()) {
createDefaultConfiguration(config);
}
File keystore = new File(home, KEYSTORE);
if (!keystore.exists()) {
createKeystore(keystore);
}
if (repoContext == null) {
repoContext = RepositoryContext.create(RepositoryConfig.create(config.toURI(), home.getPath()));
}
if (server == null) {
server = new Server();
ServletHolder simple = new ServletHolder(new SimpleWebdavServlet() {
private static final long serialVersionUID = 8638589328461138178L;
public Repository getRepository() {
return repoContext.getRepository();
}
});
simple.setInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_CONFIG, "/config.xml");
ServletHolder remoting = new ServletHolder(new JcrRemotingServlet() {
private static final long serialVersionUID = -2969534124090379387L;
public Repository getRepository() {
return repoContext.getRepository();
}
});
remoting.setInitParameter(JcrRemotingServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/remoting");
ServletContextHandler schandler = new ServletContextHandler(server, "/");
schandler.addServlet(simple, SIMPLE_WEBDAV_SERVLET_PATH_MAPPING);
schandler.addServlet(remoting, REMOTING_WEBDAV_SERVLET_PATH_MAPPING);
schandler.setBaseResource(Resource.newClassPathResource("/"));
server.setHandler(schandler);
}
if (httpConnector == null) {
httpConnector = new ServerConnector(server);
httpConnector.setHost("localhost");
httpConnector.setPort(0);
server.addConnector(httpConnector);
}
if (httpsConnector == null) {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystore.getPath());
sslContextFactory.setKeyStorePassword(KEYSTOREPW);
sslContextFactory.setKeyManagerPassword(KEYSTOREPW);
sslContextFactory.setTrustStorePath(keystore.getPath());
sslContextFactory.setTrustStorePassword(KEYSTOREPW);
SslConnectionFactory cfac = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());
httpsConnector = new ServerConnector(server, cfac, new HttpConnectionFactory(new HttpConfiguration()));
httpsConnector.setHost("localhost");
httpsConnector.setPort(0);
server.addConnector(httpsConnector);
}
if (!server.isStarted()) {
try {
server.start();
} catch (Exception e) {
throw new RepositoryStubException(e);
}
}
this.uri = new URI("http", null, "localhost", httpConnector.getLocalPort(), "/default/", null, null);
this.remotingUri = new URI("http", null, "localhost", httpConnector.getLocalPort(), REMOTING_PREFIX + "/", null, null);
this.httpsUri = new URI("https", null, "localhost", httpsConnector.getLocalPort(), "/default/", null, null);
this.root = this.uri.toASCIIString();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// cm.setMaxTotal(100);
HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("admin", "admin"));
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
this.context = HttpClientContext.create();
this.context.setCredentialsProvider(credsProvider);
this.context.setAuthCache(authCache);
this.client = HttpClients.custom().setConnectionManager(cm).build();
super.setUp();
}
use of org.apache.http.impl.auth.BasicScheme in project tutorials by eugenp.
the class HttpClientAuthLiveTest method context.
private HttpContext context() {
final HttpHost targetHost = new HttpHost("localhost", 8080, "http");
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS));
// Create AuthCache instance
final AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
authCache.put(targetHost, new BasicScheme());
// Add AuthCache to the execution context
final HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
return context;
}
Aggregations