Search in sources :

Example 1 with AuthenticationService

use of com.yahoo.pulsar.broker.authentication.AuthenticationService in project pulsar by yahoo.

the class ServerCnxTest method testConnectCommandWithAuthenticationPositive.

@Test(timeOut = 30000)
public void testConnectCommandWithAuthenticationPositive() throws Exception {
    AuthenticationService authenticationService = mock(AuthenticationService.class);
    doReturn(authenticationService).when(brokerService).getAuthenticationService();
    doReturn("appid1").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", "");
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    assertTrue(getResponse() instanceof CommandConnected);
    channel.finish();
}
Also used : AuthenticationDataCommand(com.yahoo.pulsar.broker.authentication.AuthenticationDataCommand) CommandConnected(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) AuthenticationService(com.yahoo.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Example 2 with AuthenticationService

use of com.yahoo.pulsar.broker.authentication.AuthenticationService in project pulsar by yahoo.

the class ApiVersionFilterTest method testAuthFilterTest.

@Test
public void testAuthFilterTest() throws Exception {
    BrokerService nativeService = mock(BrokerService.class);
    AuthenticationService authService = mock(AuthenticationService.class);
    doReturn(nativeService).when(pulsar).getBrokerService();
    doReturn(authService).when(nativeService).getAuthenticationService();
    doReturn("test-role").when(authService).authenticateHttpRequest(mock(HttpServletRequest.class));
    AuthenticationFilter filter = new AuthenticationFilter(pulsar);
    HttpServletRequest request = mock(HttpServletRequest.class);
    ServletResponse response = null;
    doNothing().when(request).setAttribute(anyString(), anyObject());
    filter.doFilter(request, response, chain);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) AuthenticationService(com.yahoo.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Example 3 with AuthenticationService

use of com.yahoo.pulsar.broker.authentication.AuthenticationService in project pulsar by yahoo.

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", "");
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Start);
    assertTrue(getResponse() instanceof CommandError);
    channel.finish();
}
Also used : AuthenticationDataCommand(com.yahoo.pulsar.broker.authentication.AuthenticationDataCommand) AuthenticationException(javax.naming.AuthenticationException) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) AuthenticationService(com.yahoo.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Example 4 with AuthenticationService

use of com.yahoo.pulsar.broker.authentication.AuthenticationService in project pulsar by yahoo.

the class WebSocketService method start.

public void start() throws PulsarServerException, PulsarClientException, MalformedURLException, ServletException, DeploymentException {
    if (isNotBlank(config.getGlobalZookeeperServers())) {
        this.globalZkCache = new GlobalZooKeeperCache(getZooKeeperClientFactory(), (int) config.getZooKeeperSessionTimeoutMillis(), config.getGlobalZookeeperServers(), this.orderedExecutor, this.executor);
        try {
            this.globalZkCache.start();
        } catch (IOException e) {
            throw new PulsarServerException(e);
        }
        this.configurationCacheService = new ConfigurationCacheService(getGlobalZkCache());
        log.info("Global Zookeeper cache started");
    }
    // start authorizationManager
    if (config.isAuthorizationEnabled()) {
        if (configurationCacheService == null) {
            throw new PulsarServerException("Failed to initialize authorization manager due to empty GlobalZookeeperServers");
        }
        authorizationManager = new AuthorizationManager(this.config, configurationCacheService);
    }
    // start authentication service
    authenticationService = new AuthenticationService(this.config);
    log.info("Pulsar WebSocket Service started");
}
Also used : PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) GlobalZooKeeperCache(com.yahoo.pulsar.zookeeper.GlobalZooKeeperCache) ConfigurationCacheService(com.yahoo.pulsar.broker.cache.ConfigurationCacheService) IOException(java.io.IOException) AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) AuthenticationService(com.yahoo.pulsar.broker.authentication.AuthenticationService)

Example 5 with AuthenticationService

use of com.yahoo.pulsar.broker.authentication.AuthenticationService in project pulsar by yahoo.

the class DiscoveryService method start.

/**
     * Starts discovery service by initializing zookkeeper and server
     * @throws Exception
     */
public void start() throws Exception {
    discoveryProvider = new BrokerDiscoveryProvider(this.config, getZooKeeperClientFactory());
    this.configurationCacheService = new ConfigurationCacheService(discoveryProvider.globalZkCache);
    ServiceConfiguration serviceConfiguration = createServiceConfiguration(config);
    authenticationService = new AuthenticationService(serviceConfiguration);
    authorizationManager = new AuthorizationManager(serviceConfiguration, configurationCacheService);
    startServer();
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) ConfigurationCacheService(com.yahoo.pulsar.broker.cache.ConfigurationCacheService) AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) AuthenticationService(com.yahoo.pulsar.broker.authentication.AuthenticationService)

Aggregations

AuthenticationService (com.yahoo.pulsar.broker.authentication.AuthenticationService)9 Test (org.testng.annotations.Test)7 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)5 Matchers.anyString (org.mockito.Matchers.anyString)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 AuthenticationDataCommand (com.yahoo.pulsar.broker.authentication.AuthenticationDataCommand)2 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)2 ConfigurationCacheService (com.yahoo.pulsar.broker.cache.ConfigurationCacheService)2 ByteBuf (io.netty.buffer.ByteBuf)2 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)1 BrokerService (com.yahoo.pulsar.broker.service.BrokerService)1 CommandConnected (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected)1 CommandError (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError)1 GlobalZooKeeperCache (com.yahoo.pulsar.zookeeper.GlobalZooKeeperCache)1 IOException (java.io.IOException)1 AuthenticationException (javax.naming.AuthenticationException)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1