use of io.cdap.cdap.security.auth.TokenValidator in project cdap by caskdata.
the class RouterResource method before.
@Override
protected void before() {
CConfiguration cConf = CConfiguration.create();
Injector injector = Guice.createInjector(new CoreSecurityRuntimeModule().getStandaloneModules(), new ExternalAuthenticationModule(), new InMemoryDiscoveryModule(), new AppFabricTestModule(cConf));
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
TokenValidator mockValidator = new MockTokenValidator("failme");
UserIdentityExtractor extractor = new MockAccessTokenIdentityExtractor(mockValidator);
SConfiguration sConf = injector.getInstance(SConfiguration.class);
cConf.set(Constants.Router.ADDRESS, hostname);
cConf.setInt(Constants.Router.ROUTER_PORT, 0);
for (Map.Entry<String, String> entry : additionalConfig.entrySet()) {
cConf.set(entry.getKey(), entry.getValue());
}
router = new NettyRouter(cConf, sConf, InetAddresses.forString(hostname), new RouterServiceLookup(cConf, (DiscoveryServiceClient) discoveryService, new RouterPathLookup()), mockValidator, extractor, discoveryServiceClient);
router.startAndWait();
}
use of io.cdap.cdap.security.auth.TokenValidator in project cdap by caskdata.
the class AuditLogTest method init.
@BeforeClass
public static void init() throws Exception {
// Configure a log appender programmatically for the audit log
TestLogAppender.addAppender(Constants.Router.AUDIT_LOGGER_NAME);
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Constants.Router.AUDIT_LOGGER_NAME)).setLevel(Level.TRACE);
CConfiguration cConf = CConfiguration.create();
SConfiguration sConf = SConfiguration.create();
cConf.set(Constants.Router.ADDRESS, InetAddress.getLoopbackAddress().getHostAddress());
cConf.setInt(Constants.Router.ROUTER_PORT, 0);
cConf.setBoolean(Constants.Router.ROUTER_AUDIT_LOG_ENABLED, true);
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
RouterServiceLookup serviceLookup = new RouterServiceLookup(cConf, discoveryService, new RouterPathLookup());
TokenValidator successValidator = new SuccessTokenValidator();
router = new NettyRouter(cConf, sConf, InetAddress.getLoopbackAddress(), serviceLookup, successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService);
router.startAndWait();
httpService = NettyHttpService.builder("test").setHttpHandlers(new TestHandler()).build();
httpService.start();
cancelDiscovery = discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, httpService.getBindAddress()));
int port = router.getBoundAddress().orElseThrow(IllegalStateException::new).getPort();
baseURI = URI.create(String.format("http://%s:%d", cConf.get(Constants.Router.ADDRESS), port));
}
use of io.cdap.cdap.security.auth.TokenValidator in project cdap by caskdata.
the class NettyRouterTestBase method testConfigReloading.
@Test
public void testConfigReloading() throws Exception {
long reloadIntervalSeconds = 10;
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
TokenValidator successValidator = new SuccessTokenValidator();
// Configure router with some config-reloading time set
CConfiguration cConfSpy1 = Mockito.spy(CConfiguration.create());
cConfSpy1.setLong(Constants.Router.CCONF_RELOAD_INTERVAL_SECONDS, reloadIntervalSeconds);
cConfSpy1.setInt(Constants.Router.ROUTER_PORT, 0);
NettyRouter router1 = new NettyRouter(cConfSpy1, SConfiguration.create(), InetAddress.getLoopbackAddress(), new RouterServiceLookup(cConfSpy1, discoveryService, new RouterPathLookup()), successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService);
router1.startAndWait();
// Configure router with config-reloading time set to 0
CConfiguration cConfSpy2 = Mockito.spy(CConfiguration.create());
cConfSpy2.setLong(Constants.Router.CCONF_RELOAD_INTERVAL_SECONDS, 0);
cConfSpy2.setInt(Constants.Router.ROUTER_PORT, 0);
NettyRouter router2 = new NettyRouter(cConfSpy2, SConfiguration.create(), InetAddress.getLoopbackAddress(), new RouterServiceLookup(cConfSpy2, discoveryService, new RouterPathLookup()), successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService);
router2.startAndWait();
// Wait sometime for cConf to reload
Thread.sleep(TimeUnit.MILLISECONDS.convert(reloadIntervalSeconds + 2, TimeUnit.SECONDS));
Mockito.verify(cConfSpy1, Mockito.times(1)).reloadConfiguration();
Mockito.verify(cConfSpy2, Mockito.never()).reloadConfiguration();
router1.stopAndWait();
router2.stopAndWait();
}
use of io.cdap.cdap.security.auth.TokenValidator in project cdap by caskdata.
the class ConfigBasedRequestBlockingTest method init.
@BeforeClass
public static void init() throws Exception {
cConf = CConfiguration.create();
cConf.set(Constants.Router.ADDRESS, InetAddress.getLoopbackAddress().getHostAddress());
cConf.setInt(Constants.Router.ROUTER_PORT, 0);
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
TokenValidator successValidator = new SuccessTokenValidator();
router = new NettyRouter(cConf, SConfiguration.create(), InetAddress.getLoopbackAddress(), new RouterServiceLookup(cConf, discoveryService, new RouterPathLookup()), successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService);
router.startAndWait();
httpService = NettyHttpService.builder("test").setHttpHandlers(new AuditLogTest.TestHandler()).build();
httpService.start();
cancelDiscovery = discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, httpService.getBindAddress()));
}
Aggregations