Search in sources :

Example 6 with Authenticator

use of com.sun.net.httpserver.Authenticator in project jetty.project by eclipse.

the class JettyHttpContext method setAuthenticator.

@Override
public Authenticator setAuthenticator(Authenticator auth) {
    Authenticator previous = _authenticator;
    _authenticator = auth;
    return previous;
}
Also used : Authenticator(com.sun.net.httpserver.Authenticator)

Example 7 with Authenticator

use of com.sun.net.httpserver.Authenticator in project data-prepper by opensearch-project.

the class DataPrepperServerConfigurationTest method testGivenPrometheusMeterRegistryAndAuthenticatorThenServerIsCreated.

@Test
public void testGivenPrometheusMeterRegistryAndAuthenticatorThenServerIsCreated() {
    final PrometheusMeterRegistry meterRegistry = mock(PrometheusMeterRegistry.class);
    final Authenticator authenticator = mock(Authenticator.class);
    when(httpServerProvider.get()).thenReturn(httpServer);
    when(httpServer.createContext(any(String.class), any(HttpHandler.class))).thenReturn(context);
    final HttpServer server = serverConfiguration.httpServer(httpServerProvider, listPipelinesHandler, shutdownHandler, meterRegistry, authenticator);
    assertThat(server, is(httpServer));
    verify(server).createContext(eq("/list"), eq(listPipelinesHandler));
    verify(server).createContext(eq("/shutdown"), eq(shutdownHandler));
    verify(server).createContext(eq("/metrics/prometheus"), any(PrometheusMetricsHandler.class));
    verify(server).createContext(eq("/metrics/sys"), any(PrometheusMetricsHandler.class));
    verify(context, times(4)).setAuthenticator(eq(authenticator));
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) HttpHandler(com.sun.net.httpserver.HttpHandler) HttpServer(com.sun.net.httpserver.HttpServer) Authenticator(com.sun.net.httpserver.Authenticator) PrometheusMetricsHandler(com.amazon.dataprepper.pipeline.server.PrometheusMetricsHandler) Test(org.junit.jupiter.api.Test)

Example 8 with Authenticator

use of com.sun.net.httpserver.Authenticator in project data-prepper by opensearch-project.

the class DataPrepperServerConfigurationTest method testGivenGetAuthenticatorReturnsValueThenReturnOptionalContainingValue.

@Test
public void testGivenGetAuthenticatorReturnsValueThenReturnOptionalContainingValue() {
    final DataPrepperCoreAuthenticationProvider provider = mock(DataPrepperCoreAuthenticationProvider.class);
    final Authenticator authenticatorMock = mock(Authenticator.class);
    when(provider.getAuthenticator()).thenReturn(authenticatorMock);
    final Authenticator authenticator = serverConfiguration.authenticator(provider);
    assertThat(authenticator, is(authenticatorMock));
}
Also used : DataPrepperCoreAuthenticationProvider(com.amazon.dataprepper.pipeline.server.DataPrepperCoreAuthenticationProvider) Authenticator(com.sun.net.httpserver.Authenticator) Test(org.junit.jupiter.api.Test)

Example 9 with Authenticator

use of com.sun.net.httpserver.Authenticator in project data-prepper by opensearch-project.

the class HttpBasicDataPrepperCoreAuthenticationProviderTest method getAuthenticator_should_return_Authenticator_with_core_Realm.

@Test
void getAuthenticator_should_return_Authenticator_with_core_Realm() {
    final Authenticator authenticator = createObjectUnderTest().getAuthenticator();
    assertThat(authenticator, notNullValue());
    assertThat(authenticator, instanceOf(BasicAuthenticator.class));
    final BasicAuthenticator basicAuthenticator = (BasicAuthenticator) authenticator;
    assertThat(basicAuthenticator.getRealm(), equalTo("core"));
}
Also used : BasicAuthenticator(com.sun.net.httpserver.BasicAuthenticator) BasicAuthenticator(com.sun.net.httpserver.BasicAuthenticator) Authenticator(com.sun.net.httpserver.Authenticator) Test(org.junit.jupiter.api.Test)

Example 10 with Authenticator

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_password.

@Test
void getAuthenticator_should_return_Authenticator_which_returns_false_for_incorrect_password() {
    final Authenticator authenticator = createObjectUnderTest().getAuthenticator();
    assertThat(authenticator, notNullValue());
    assertThat(authenticator, instanceOf(BasicAuthenticator.class));
    final BasicAuthenticator basicAuthenticator = (BasicAuthenticator) authenticator;
    assertThat(basicAuthenticator.checkCredentials(username, UUID.randomUUID().toString()), equalTo(false));
}
Also used : BasicAuthenticator(com.sun.net.httpserver.BasicAuthenticator) BasicAuthenticator(com.sun.net.httpserver.BasicAuthenticator) Authenticator(com.sun.net.httpserver.Authenticator) Test(org.junit.jupiter.api.Test)

Aggregations

Authenticator (com.sun.net.httpserver.Authenticator)10 Test (org.junit.jupiter.api.Test)8 BasicAuthenticator (com.sun.net.httpserver.BasicAuthenticator)6 DataPrepperCoreAuthenticationProvider (com.amazon.dataprepper.pipeline.server.DataPrepperCoreAuthenticationProvider)1 PrometheusMetricsHandler (com.amazon.dataprepper.pipeline.server.PrometheusMetricsHandler)1 Result (com.sun.net.httpserver.Authenticator.Result)1 HttpHandler (com.sun.net.httpserver.HttpHandler)1 HttpPrincipal (com.sun.net.httpserver.HttpPrincipal)1 HttpServer (com.sun.net.httpserver.HttpServer)1 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)1 List (java.util.List)1 Map (java.util.Map)1