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();
}
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);
}
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();
}
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");
}
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();
}
Aggregations