Search in sources :

Example 6 with AuthenticationService

use of org.apache.pulsar.broker.authentication.AuthenticationService in project incubator-pulsar by apache.

the class ServerCnxTest method testConnectCommandWithAuthenticationNegative.

@Test(timeOut = 30000)
public void testConnectCommandWithAuthenticationNegative() throws Exception {
    AuthenticationException e = new AuthenticationException();
    AuthenticationService authenticationService = mock(AuthenticationService.class);
    doReturn(authenticationService).when(brokerService).getAuthenticationService();
    doThrow(e).when(authenticationService).authenticate(new AuthenticationDataCommand(Mockito.anyString()), Mockito.anyString());
    doReturn(true).when(brokerService).isAuthenticationEnabled();
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "", null);
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Start);
    assertTrue(getResponse() instanceof CommandError);
    channel.finish();
}
Also used : AuthenticationDataCommand(org.apache.pulsar.broker.authentication.AuthenticationDataCommand) AuthenticationException(javax.naming.AuthenticationException) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Example 7 with AuthenticationService

use of org.apache.pulsar.broker.authentication.AuthenticationService in project incubator-pulsar by apache.

the class AuthenticationServiceTest method testAuthenticationHttp.

@Test(timeOut = 10000)
public void testAuthenticationHttp() throws Exception {
    ServiceConfiguration config = new ServiceConfiguration();
    Set<String> providersClassNames = Sets.newHashSet(MockAuthenticationProvider.class.getName());
    config.setAuthenticationProviders(providersClassNames);
    config.setAuthenticationEnabled(true);
    AuthenticationService service = new AuthenticationService(config);
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRemoteAddr()).thenReturn("192.168.1.1");
    when(request.getRemotePort()).thenReturn(8080);
    when(request.getHeader(anyString())).thenReturn("data");
    String result = service.authenticateHttpRequest(request);
    assertEquals(result, s_authentication_success);
    service.close();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Aggregations

AuthenticationService (org.apache.pulsar.broker.authentication.AuthenticationService)7 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)4 Test (org.testng.annotations.Test)4 AuthorizationService (org.apache.pulsar.broker.authorization.AuthorizationService)3 ConfigurationCacheService (org.apache.pulsar.broker.cache.ConfigurationCacheService)3 ByteBuf (io.netty.buffer.ByteBuf)2 AuthenticationDataCommand (org.apache.pulsar.broker.authentication.AuthenticationDataCommand)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 AdaptiveRecvByteBufAllocator (io.netty.channel.AdaptiveRecvByteBufAllocator)1 IOException (java.io.IOException)1 AuthenticationException (javax.naming.AuthenticationException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)1 CommandConnected (org.apache.pulsar.common.api.proto.PulsarApi.CommandConnected)1 CommandError (org.apache.pulsar.common.api.proto.PulsarApi.CommandError)1 GlobalZooKeeperCache (org.apache.pulsar.zookeeper.GlobalZooKeeperCache)1 LocalZooKeeperConnectionService (org.apache.pulsar.zookeeper.LocalZooKeeperConnectionService)1 ShutdownService (org.apache.pulsar.zookeeper.ZooKeeperSessionWatcher.ShutdownService)1