use of com.sun.net.httpserver.Authenticator in project jetty.project by eclipse.
the class HttpSpiContextHandler method handleAuthentication.
private void handleAuthentication(HttpServletResponse resp, HttpExchange httpExchange, Authenticator auth) throws IOException {
Result result = auth.authenticate(httpExchange);
if (result instanceof Authenticator.Failure) {
int rc = ((Authenticator.Failure) result).getResponseCode();
for (Map.Entry<String, List<String>> header : httpExchange.getResponseHeaders().entrySet()) {
for (String value : header.getValue()) resp.addHeader(header.getKey(), value);
}
resp.sendError(rc);
} else if (result instanceof Authenticator.Retry) {
int rc = ((Authenticator.Retry) result).getResponseCode();
for (Map.Entry<String, List<String>> header : httpExchange.getResponseHeaders().entrySet()) {
for (String value : header.getValue()) resp.addHeader(header.getKey(), value);
}
resp.setStatus(rc);
resp.flushBuffer();
} else if (result instanceof Authenticator.Success) {
HttpPrincipal principal = ((Authenticator.Success) result).getPrincipal();
((JettyExchange) httpExchange).setPrincipal(principal);
_httpHandler.handle(httpExchange);
}
}
use of com.sun.net.httpserver.Authenticator in project data-prepper by opensearch-project.
the class HttpBasicDataPrepperCoreAuthenticationProviderTest method getAuthenticator_should_return_Authenticator_which_returns_true_for_matching_username_and_password.
@Test
void getAuthenticator_should_return_Authenticator_which_returns_true_for_matching_username_and_password() {
final Authenticator authenticator = createObjectUnderTest().getAuthenticator();
assertThat(authenticator, notNullValue());
assertThat(authenticator, instanceOf(BasicAuthenticator.class));
final BasicAuthenticator basicAuthenticator = (BasicAuthenticator) authenticator;
assertThat(basicAuthenticator.checkCredentials(username, password), equalTo(true));
}
use of com.sun.net.httpserver.Authenticator in project data-prepper by opensearch-project.
the class HttpBasicDataPrepperCoreAuthenticationProviderTest method getAuthenticator_should_return_Authenticator_which_returns_false_for_null_password.
@Test
void getAuthenticator_should_return_Authenticator_which_returns_false_for_null_password() {
final Authenticator authenticator = createObjectUnderTest().getAuthenticator();
assertThat(authenticator, notNullValue());
assertThat(authenticator, instanceOf(BasicAuthenticator.class));
final BasicAuthenticator basicAuthenticator = (BasicAuthenticator) authenticator;
assertThat(basicAuthenticator.checkCredentials(username, null), equalTo(false));
}
use of com.sun.net.httpserver.Authenticator in project data-prepper by opensearch-project.
the class HttpBasicDataPrepperCoreAuthenticationProviderTest method getAuthenticator_should_return_Authenticator_which_returns_false_for_null_username.
@Test
void getAuthenticator_should_return_Authenticator_which_returns_false_for_null_username() {
final Authenticator authenticator = createObjectUnderTest().getAuthenticator();
assertThat(authenticator, notNullValue());
assertThat(authenticator, instanceOf(BasicAuthenticator.class));
final BasicAuthenticator basicAuthenticator = (BasicAuthenticator) authenticator;
assertThat(basicAuthenticator.checkCredentials(null, password), equalTo(false));
}
use of com.sun.net.httpserver.Authenticator in project data-prepper by opensearch-project.
the class HttpBasicDataPrepperCoreAuthenticationProviderTest method getAuthenticator_should_return_Authenticator_which_returns_false_for_incorrect_username.
@Test
void getAuthenticator_should_return_Authenticator_which_returns_false_for_incorrect_username() {
final Authenticator authenticator = createObjectUnderTest().getAuthenticator();
assertThat(authenticator, notNullValue());
assertThat(authenticator, instanceOf(BasicAuthenticator.class));
final BasicAuthenticator basicAuthenticator = (BasicAuthenticator) authenticator;
assertThat(basicAuthenticator.checkCredentials(UUID.randomUUID().toString(), password), equalTo(false));
}
Aggregations