Search in sources :

Example 1 with AuthenticationService

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

the class ProxyService method start.

public void start() throws Exception {
    ServiceConfiguration serviceConfiguration = PulsarConfigurationLoader.convertFrom(proxyConfig);
    authenticationService = new AuthenticationService(serviceConfiguration);
    if (!isBlank(proxyConfig.getZookeeperServers()) && !isBlank(proxyConfig.getGlobalZookeeperServers())) {
        localZooKeeperConnectionService = new LocalZooKeeperConnectionService(getZooKeeperClientFactory(), proxyConfig.getZookeeperServers(), proxyConfig.getZookeeperSessionTimeoutMs());
        localZooKeeperConnectionService.start(new ShutdownService() {

            @Override
            public void shutdown(int exitCode) {
                LOG.error("Lost local ZK session. Shutting down the proxy");
                Runtime.getRuntime().halt(-1);
            }
        });
        discoveryProvider = new BrokerDiscoveryProvider(this.proxyConfig, getZooKeeperClientFactory());
        this.configurationCacheService = new ConfigurationCacheService(discoveryProvider.globalZkCache);
        authorizationService = new AuthorizationService(serviceConfiguration, configurationCacheService);
    }
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    bootstrap.group(acceptorGroup, workerGroup);
    bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
    bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(1024, 16 * 1024, 1 * 1024 * 1024));
    bootstrap.channel(EventLoopUtil.getServerSocketChannelClass(workerGroup));
    EventLoopUtil.enableTriggeredMode(bootstrap);
    bootstrap.childHandler(new ServiceChannelInitializer(this, proxyConfig, false));
    // Bind and start to accept incoming connections.
    bootstrap.bind(proxyConfig.getServicePort()).sync();
    LOG.info("Started Pulsar Proxy at {}", serviceUrl);
    if (proxyConfig.isTlsEnabledInProxy()) {
        ServerBootstrap tlsBootstrap = bootstrap.clone();
        tlsBootstrap.childHandler(new ServiceChannelInitializer(this, proxyConfig, true));
        tlsBootstrap.bind(proxyConfig.getServicePortTls()).sync();
        LOG.info("Started Pulsar TLS Proxy on port {}", proxyConfig.getServicePortTls());
    }
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) AdaptiveRecvByteBufAllocator(io.netty.channel.AdaptiveRecvByteBufAllocator) LocalZooKeeperConnectionService(org.apache.pulsar.zookeeper.LocalZooKeeperConnectionService) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) ShutdownService(org.apache.pulsar.zookeeper.ZooKeeperSessionWatcher.ShutdownService) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 2 with AuthenticationService

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

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 authorizationService
    if (config.isAuthorizationEnabled()) {
        if (configurationCacheService == null) {
            throw new PulsarServerException("Failed to initialize authorization manager due to empty GlobalZookeeperServers");
        }
        authorizationService = new AuthorizationService(this.config, configurationCacheService);
    }
    // start authentication service
    authenticationService = new AuthenticationService(this.config);
    log.info("Pulsar WebSocket Service started");
}
Also used : PulsarServerException(org.apache.pulsar.broker.PulsarServerException) GlobalZooKeeperCache(org.apache.pulsar.zookeeper.GlobalZooKeeperCache) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) IOException(java.io.IOException) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService)

Example 3 with AuthenticationService

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

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

Example 4 with AuthenticationService

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

the class AuthenticationServiceTest method testAuthentication.

@Test(timeOut = 10000)
public void testAuthentication() 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);
    String result = service.authenticate(null, "auth");
    assertEquals(result, s_authentication_success);
    service.close();
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Example 5 with AuthenticationService

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

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 = PulsarConfigurationLoader.convertFrom(config);
    authenticationService = new AuthenticationService(serviceConfiguration);
    authorizationService = new AuthorizationService(serviceConfiguration, configurationCacheService);
    startServer();
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService)

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