Search in sources :

Example 1 with TokenValidator

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();
}
Also used : InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TokenValidator(io.cdap.cdap.security.auth.TokenValidator) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) Injector(com.google.inject.Injector) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule) UserIdentityExtractor(io.cdap.cdap.security.auth.UserIdentityExtractor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TokenValidator

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));
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) Logger(ch.qos.logback.classic.Logger) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TokenValidator(io.cdap.cdap.security.auth.TokenValidator) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass)

Example 3 with TokenValidator

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();
}
Also used : TokenValidator(io.cdap.cdap.security.auth.TokenValidator) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Test(org.junit.Test)

Example 4 with TokenValidator

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()));
}
Also used : TokenValidator(io.cdap.cdap.security.auth.TokenValidator) Discoverable(org.apache.twill.discovery.Discoverable) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass)

Aggregations

TokenValidator (io.cdap.cdap.security.auth.TokenValidator)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)3 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)3 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)2 Discoverable (org.apache.twill.discovery.Discoverable)2 BeforeClass (org.junit.BeforeClass)2 Logger (ch.qos.logback.classic.Logger)1 Injector (com.google.inject.Injector)1 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)1 AppFabricTestModule (io.cdap.cdap.internal.guice.AppFabricTestModule)1 UserIdentityExtractor (io.cdap.cdap.security.auth.UserIdentityExtractor)1 CoreSecurityRuntimeModule (io.cdap.cdap.security.guice.CoreSecurityRuntimeModule)1 ExternalAuthenticationModule (io.cdap.cdap.security.guice.ExternalAuthenticationModule)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)1 Test (org.junit.Test)1