use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project wildfly by wildfly.
the class ProactiveAuthModeTestCase method testSecuredResourceWithValidCredential.
@Test
public void testSecuredResourceWithValidCredential() throws Exception {
HttpGet request = new HttpGet(new URI(url.toExternalForm() + "secure.jsp"));
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user1", "password1");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, credentials);
request.addHeader(new BasicScheme().authenticate(credentials, "UTF-8", false));
try (CloseableHttpClient httpClient = HttpClients.custom().build()) {
try (CloseableHttpResponse response = httpClient.execute(request)) {
int statusCode = response.getStatusLine().getStatusCode();
assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode);
assertEquals("Unexpected content of HTTP response.", "user1", EntityUtils.toString(response.getEntity()));
}
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project wildfly by wildfly.
the class ProactiveAuthModeTestCase method testSecuredResourceWithInvalidCredential.
@Test
public void testSecuredResourceWithInvalidCredential() throws Exception {
HttpGet request = new HttpGet(new URI(url.toExternalForm() + "secure.jsp"));
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user1", "password2");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, credentials);
request.addHeader(new BasicScheme().authenticate(credentials, request));
try (CloseableHttpClient httpClient = HttpClients.custom().build()) {
try (CloseableHttpResponse response = httpClient.execute(request)) {
int statusCode = response.getStatusLine().getStatusCode();
assertEquals("Unexpected status code in HTTP response.", SC_UNAUTHORIZED, statusCode);
}
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project wildfly by wildfly.
the class ProactiveAuthModeTestCase method testUnsecuredResourceWithValidCredential.
@Test
public void testUnsecuredResourceWithValidCredential() throws Exception {
HttpGet request = new HttpGet(new URI(url.toExternalForm() + "unsecure.jsp"));
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user1", "password1");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, credentials);
request.addHeader(new BasicScheme().authenticate(credentials, "UTF-8", false));
try (CloseableHttpClient httpClient = HttpClients.custom().build()) {
try (CloseableHttpResponse response = httpClient.execute(request)) {
int statusCode = response.getStatusLine().getStatusCode();
assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode);
assertEquals("Unexpected content of HTTP response.", "user1", EntityUtils.toString(response.getEntity()));
}
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project wildfly by wildfly.
the class HttpManagementConstantHeadersTestCase method createClient.
@Before
public void createClient() throws Exception {
String address = managementClient.getMgmtAddress();
this.managementConsoleUrl = new URL("http", address, MGMT_PORT, CONSOLE_CTX);
this.errorUrl = new URL("http", address, MGMT_PORT, ERROR_CTX);
this.metricsUrl = new URL("http", address, MGMT_PORT, METRICS_CTX);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(managementConsoleUrl.getHost(), managementConsoleUrl.getPort()), new UsernamePasswordCredentials(Authentication.USERNAME, Authentication.PASSWORD));
this.httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project wildfly by wildfly.
the class PasswordMechTestBase method testInvalidPrincipal.
@Test
public void testInvalidPrincipal() throws Exception {
HttpGet request = new HttpGet(new URI(url.toExternalForm() + "role1"));
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user1wrong", "password1");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, credentials);
try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build()) {
try (CloseableHttpResponse response = httpClient.execute(request)) {
int statusCode = response.getStatusLine().getStatusCode();
assertEquals("Unexpected status code in HTTP response.", SC_UNAUTHORIZED, statusCode);
}
}
}
Aggregations