Search in sources :

Example 1 with ExternalAuthenticationModule

use of io.cdap.cdap.security.guice.ExternalAuthenticationModule 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 ExternalAuthenticationModule

use of io.cdap.cdap.security.guice.ExternalAuthenticationModule in project cdap by caskdata.

the class AuthenticationServerMain method init.

@Override
public void init(String[] args) {
    Injector injector = Guice.createInjector(new ConfigModule(), new IOModule(), RemoteAuthenticatorModules.getDefaultModule(), new ZKClientModule(), new ZKDiscoveryModule(), new CoreSecurityRuntimeModule().getDistributedModules(), new ExternalAuthenticationModule());
    configuration = injector.getInstance(CConfiguration.class);
    if (SecurityUtil.isManagedSecurity(configuration)) {
        this.zkClientService = injector.getInstance(ZKClientService.class);
        this.authServer = injector.getInstance(ExternalAuthenticationServer.class);
    }
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) ZKClientService(org.apache.twill.zookeeper.ZKClientService) ExternalAuthenticationServer(io.cdap.cdap.security.server.ExternalAuthenticationServer) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration)

Example 3 with ExternalAuthenticationModule

use of io.cdap.cdap.security.guice.ExternalAuthenticationModule in project cdap by caskdata.

the class ExternalAuthenticationServerTestBase method setup.

protected void setup() throws Exception {
    Assert.assertNotNull("CConfiguration needs to be set by derived classes", configuration);
    // Intentionally set "security.auth.server.announce.urls" to invalid
    // values verify that they are not used by external authentication server
    configuration.set(Constants.Security.AUTH_SERVER_ANNOUNCE_URLS, "invalid.urls");
    Module externalAuthenticationModule = Modules.override(new ExternalAuthenticationModule()).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(AuditLogHandler.class).annotatedWith(Names.named(ExternalAuthenticationServer.NAMED_EXTERNAL_AUTH)).toInstance(new AuditLogHandler(TEST_AUDIT_LOGGER));
        }
    });
    Injector injector = Guice.createInjector(new IOModule(), externalAuthenticationModule, new CoreSecurityRuntimeModule().getInMemoryModules(), new ConfigModule(getConfiguration(configuration), HBaseConfiguration.create(), sConfiguration), new InMemoryDiscoveryModule());
    server = injector.getInstance(ExternalAuthenticationServer.class);
    tokenCodec = injector.getInstance(AccessTokenCodec.class);
    discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    startExternalAuthenticationServer();
    server.startAndWait();
    LOG.info("Auth server running on address {}", server.getSocketAddress());
    TimeUnit.SECONDS.sleep(3);
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AbstractModule(com.google.inject.AbstractModule) AccessTokenCodec(io.cdap.cdap.security.auth.AccessTokenCodec) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) Injector(com.google.inject.Injector) Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) IOModule(io.cdap.cdap.common.guice.IOModule) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) AbstractModule(com.google.inject.AbstractModule)

Example 4 with ExternalAuthenticationModule

use of io.cdap.cdap.security.guice.ExternalAuthenticationModule in project cdap by caskdata.

the class RouterServiceMain method getServiceModules.

@Override
protected List<Module> getServiceModules(MasterEnvironment masterEnv, EnvironmentOptions options, CConfiguration cConf) {
    List<Module> modules = new ArrayList<>();
    modules.add(new MessagingClientModule());
    modules.add(new RouterModules().getDistributedModules());
    modules.add(new DFSLocationModule());
    modules.add(new ExternalAuthenticationModule());
    return modules;
}
Also used : MessagingClientModule(io.cdap.cdap.messaging.guice.MessagingClientModule) DFSLocationModule(io.cdap.cdap.common.guice.DFSLocationModule) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) ArrayList(java.util.ArrayList) Module(com.google.inject.Module) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) DFSLocationModule(io.cdap.cdap.common.guice.DFSLocationModule) MessagingClientModule(io.cdap.cdap.messaging.guice.MessagingClientModule) RouterModules(io.cdap.cdap.gateway.router.RouterModules)

Example 5 with ExternalAuthenticationModule

use of io.cdap.cdap.security.guice.ExternalAuthenticationModule in project cdap by caskdata.

the class GatewayTestBase method startGateway.

public static Injector startGateway(final CConfiguration conf) throws Exception {
    // Set up our Guice injections
    injector = Guice.createInjector(Modules.override(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @SuppressWarnings("unused")
        @Provides
        @Named(Constants.Router.ADDRESS)
        public final InetAddress providesHostname(CConfiguration cConf) {
            return Networks.resolve(cConf.get(Constants.Router.ADDRESS), new InetSocketAddress("localhost", 0).getAddress());
        }
    }, new CoreSecurityRuntimeModule().getInMemoryModules(), new ExternalAuthenticationModule(), new AppFabricTestModule(conf)).with(new AbstractModule() {

        @Override
        protected void configure() {
            // It's a bit hacky to add it here. Need to refactor these
            // bindings out as it overlaps with
            // AppFabricServiceModule
            bind(LogReader.class).to(MockLogReader.class).in(Scopes.SINGLETON);
            bind(PermissionManager.class).to(NoOpAccessController.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    }));
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    txService = injector.getInstance(TransactionManager.class);
    txService.startAndWait();
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    metadataStorage = injector.getInstance(MetadataStorage.class);
    metadataStorage.createIndex();
    metadataService = injector.getInstance(MetadataService.class);
    metadataService.startAndWait();
    dsOpService = injector.getInstance(DatasetOpExecutorService.class);
    dsOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    appFabricServer = injector.getInstance(AppFabricServer.class);
    appFabricServer.startAndWait();
    logQueryService = injector.getInstance(LogQueryService.class);
    logQueryService.startAndWait();
    metricsQueryService = injector.getInstance(MetricsQueryService.class);
    metricsQueryService.startAndWait();
    metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
    metricsCollectionService.startAndWait();
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    namespaceAdmin.create(TEST_NAMESPACE_META1);
    namespaceAdmin.create(TEST_NAMESPACE_META2);
    // Restart handlers to check if they are resilient across restarts.
    router = injector.getInstance(NettyRouter.class);
    router.startAndWait();
    port = router.getBoundAddress().orElseThrow(IllegalStateException::new).getPort();
    return injector;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) AppFabricServer(io.cdap.cdap.internal.app.services.AppFabricServer) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) MetadataService(io.cdap.cdap.metadata.MetadataService) LogQueryService(io.cdap.cdap.logging.service.LogQueryService) CoreSecurityRuntimeModule(io.cdap.cdap.security.guice.CoreSecurityRuntimeModule) NoOpAccessController(io.cdap.cdap.security.spi.authorization.NoOpAccessController) MetricsQueryService(io.cdap.cdap.metrics.query.MetricsQueryService) ExternalAuthenticationModule(io.cdap.cdap.security.guice.ExternalAuthenticationModule) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) MetricsQueryService(io.cdap.cdap.metrics.query.MetricsQueryService) MessagingService(io.cdap.cdap.messaging.MessagingService) DatasetService(io.cdap.cdap.data2.datafabric.dataset.service.DatasetService) LogQueryService(io.cdap.cdap.logging.service.LogQueryService) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) MetadataService(io.cdap.cdap.metadata.MetadataService) DefaultOwnerAdmin(io.cdap.cdap.security.impersonation.DefaultOwnerAdmin) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NettyRouter(io.cdap.cdap.gateway.router.NettyRouter) AbstractModule(com.google.inject.AbstractModule) MessagingService(io.cdap.cdap.messaging.MessagingService) TransactionManager(org.apache.tephra.TransactionManager) DatasetOpExecutorService(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) MockLogReader(io.cdap.cdap.gateway.handlers.log.MockLogReader) LogReader(io.cdap.cdap.logging.read.LogReader) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) AppFabricTestModule(io.cdap.cdap.internal.guice.AppFabricTestModule)

Aggregations

ExternalAuthenticationModule (io.cdap.cdap.security.guice.ExternalAuthenticationModule)8 CoreSecurityRuntimeModule (io.cdap.cdap.security.guice.CoreSecurityRuntimeModule)6 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)5 Injector (com.google.inject.Injector)4 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)4 AbstractModule (com.google.inject.AbstractModule)3 Module (com.google.inject.Module)3 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)3 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)3 IOModule (io.cdap.cdap.common.guice.IOModule)3 AppFabricTestModule (io.cdap.cdap.internal.guice.AppFabricTestModule)3 ZKClientModule (io.cdap.cdap.common.guice.ZKClientModule)2 RouterModules (io.cdap.cdap.gateway.router.RouterModules)2 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)2 Service (com.google.common.util.concurrent.Service)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 AppFabricServiceRuntimeModule (io.cdap.cdap.app.guice.AppFabricServiceRuntimeModule)1 AuthorizationModule (io.cdap.cdap.app.guice.AuthorizationModule)1 MonitorHandlerModule (io.cdap.cdap.app.guice.MonitorHandlerModule)1 ProgramRunnerRuntimeModule (io.cdap.cdap.app.guice.ProgramRunnerRuntimeModule)1