Search in sources :

Example 1 with DefaultInternalAuthenticator

use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.

the class ArtifactLocalizerServiceTest method setupArtifactLocalizerService.

private ArtifactLocalizerService setupArtifactLocalizerService(CConfiguration cConf) {
    DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
    RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    ArtifactLocalizerService artifactLocalizerService = new ArtifactLocalizerService(cConf, new ArtifactLocalizer(cConf, remoteClientFactory, (namespaceId, retryStrategy) -> {
        return new NoOpArtifactManager();
    }));
    // start the service
    artifactLocalizerService.startAndWait();
    return artifactLocalizerService;
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) AccessException(io.cdap.cdap.api.security.AccessException) AppFabricTestBase(io.cdap.cdap.internal.app.services.http.AppFabricTestBase) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) NoOpInternalAuthenticator(io.cdap.cdap.common.internal.remote.NoOpInternalAuthenticator) InetAddress(java.net.InetAddress) Files(com.google.common.io.Files) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) After(org.junit.After) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) Locations(io.cdap.cdap.common.io.Locations) CloseableClassLoader(io.cdap.cdap.api.artifact.CloseableClassLoader) ClassRule(org.junit.ClassRule) Nullable(javax.annotation.Nullable) ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) Before(org.junit.Before) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) Test(org.junit.Test) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) File(java.io.File) Id(io.cdap.cdap.common.id.Id) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) List(java.util.List) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TaskWorkerServiceTest(io.cdap.cdap.internal.app.worker.TaskWorkerServiceTest) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) Constants(io.cdap.cdap.common.conf.Constants) Assert(org.junit.Assert) DirUtils(io.cdap.cdap.common.utils.DirUtils) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext)

Example 2 with DefaultInternalAuthenticator

use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.

the class OAuthMacroEvaluatorTest method init.

@BeforeClass
public static void init() throws Exception {
    httpService = NettyHttpService.builder("OAuthTest").setHttpHandlers(new OAuthHandler(ImmutableMap.of(PROVIDER, ImmutableMap.of(CREDENTIAL_ID, new OAuthInfo("accessToken", "bearer"))))).build();
    httpService.start();
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    String discoveryName = ServiceDiscoverable.getName(NamespaceId.SYSTEM.getNamespace(), Constants.PIPELINEID, ProgramType.SERVICE, Constants.STUDIO_SERVICE_NAME);
    discoveryService.register(new Discoverable(discoveryName, httpService.getBindAddress()));
    RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    serviceDiscoverer = new AbstractServiceDiscoverer(NamespaceId.DEFAULT.app("testapp").spark("testspark")) {

        @Override
        protected RemoteClientFactory getRemoteClientFactory() {
            return remoteClientFactory;
        }
    };
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) Discoverable(org.apache.twill.discovery.Discoverable) ServiceDiscoverable(io.cdap.cdap.common.service.ServiceDiscoverable) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) AbstractServiceDiscoverer(io.cdap.cdap.app.services.AbstractServiceDiscoverer) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass)

Example 3 with DefaultInternalAuthenticator

use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.

the class DefaultMasterEnvironmentRunnableContextTest method setup.

@BeforeClass
public static void setup() throws Exception {
    DiscoveryService discoveryService = new InMemoryDiscoveryService();
    LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
    RemoteClientFactory remoteClientFactory = new RemoteClientFactory((DiscoveryServiceClient) discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    context = new DefaultMasterEnvironmentRunnableContext(locationFactory, remoteClientFactory);
    httpService = NettyHttpService.builder(Constants.Service.APP_FABRIC_HTTP).setHttpHandlers(new MockHttpHandler()).build();
    httpService.start();
    cancelDiscovery = discoveryService.register(ResolvingDiscoverable.of(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService)));
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) BeforeClass(org.junit.BeforeClass)

Example 4 with DefaultInternalAuthenticator

use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.

the class RemoteConfiguratorTest method init.

@BeforeClass
public static void init() throws Exception {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 0);
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    MasterEnvironments.setMasterEnvironment(new TestMasterEnvironment(discoveryService));
    NamespaceAdmin namespaceAdmin = new InMemoryNamespaceAdmin();
    namespaceAdmin.create(NamespaceMeta.SYSTEM);
    namespaceAdmin.create(NamespaceMeta.DEFAULT);
    remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    httpService = new CommonNettyHttpServiceBuilder(cConf, "test").setHttpHandlers(new TaskWorkerHttpHandlerInternal(cConf, className -> {
    }, new NoOpMetricsCollectionService()), new ArtifactHttpHandlerInternal(new TestArtifactRepository(cConf), namespaceAdmin), new ArtifactLocalizerHttpHandlerInternal(new ArtifactLocalizer(cConf, remoteClientFactory, ((namespaceId, retryStrategy) -> {
        return new NoOpArtifactManager();
    })))).setPort(cConf.getInt(Constants.ArtifactLocalizer.PORT)).setChannelPipelineModifier(new ChannelPipelineModifier() {

        @Override
        public void modify(ChannelPipeline pipeline) {
            pipeline.addAfter("compressor", "decompressor", new HttpContentDecompressor());
        }
    }).build();
    httpService.start();
    discoveryService.register(URIScheme.createDiscoverable(Constants.Service.TASK_WORKER, httpService));
    discoveryService.register(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService));
    metricsCollectionService = new NoOpMetricsCollectionService();
}
Also used : ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) AccessException(io.cdap.cdap.api.security.AccessException) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ArtifactClasses(io.cdap.cdap.api.artifact.ArtifactClasses) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) GsonBuilder(com.google.gson.GsonBuilder) ArtifactMeta(io.cdap.cdap.internal.app.runtime.artifact.ArtifactMeta) MasterEnvironments(io.cdap.cdap.master.environment.MasterEnvironments) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) Gson(com.google.gson.Gson) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) MasterEnvironmentRunnableContext(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnableContext) NettyHttpService(io.cdap.http.NettyHttpService) After(org.junit.After) Map(java.util.Map) ConfigTestApp(io.cdap.cdap.ConfigTestApp) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) CloseableClassLoader(io.cdap.cdap.api.artifact.CloseableClassLoader) ClassRule(org.junit.ClassRule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) AfterClass(org.junit.AfterClass) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramType(io.cdap.cdap.api.app.ProgramType) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) ChannelPipeline(io.netty.channel.ChannelPipeline) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) Id(io.cdap.cdap.common.id.Id) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) List(java.util.List) Constants(io.cdap.cdap.common.conf.Constants) Configurator(io.cdap.cdap.app.deploy.Configurator) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) NotFoundException(io.cdap.cdap.common.NotFoundException) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) Location(org.apache.twill.filesystem.Location) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) ConfiguratorTask(io.cdap.cdap.internal.app.worker.ConfiguratorTask) TwillRunnerService(org.apache.twill.api.TwillRunnerService) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Nullable(javax.annotation.Nullable) DiscoveryService(org.apache.twill.discovery.DiscoveryService) URIScheme(io.cdap.cdap.common.discovery.URIScheme) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) Test(org.junit.Test) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) MasterEnvironmentRunnable(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnable) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) BeforeClass(org.junit.BeforeClass)

Example 5 with DefaultInternalAuthenticator

use of io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator in project cdap by caskdata.

the class UGIProviderTest method testRemoteUGIProvider.

@Test
public void testRemoteUGIProvider() throws Exception {
    // Starts a mock server to handle remote UGI requests
    final NettyHttpService httpService = NettyHttpService.builder("remoteUGITest").setHttpHandlers(new UGIProviderTestHandler()).build();
    httpService.start();
    setKeytabDir(localKeytabDirPath.getAbsolutePath());
    OwnerAdmin ownerAdmin = getOwnerAdmin();
    // add an owner for stream
    ownerAdmin.add(aliceEntity, aliceKerberosPrincipalId);
    try {
        InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
        discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, httpService.getBindAddress()));
        RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
        RemoteUGIProvider ugiProvider = new RemoteUGIProvider(cConf, locationFactory, ownerAdmin, remoteClientFactory);
        ImpersonationRequest aliceImpRequest = new ImpersonationRequest(aliceEntity, ImpersonatedOpType.OTHER);
        UGIWithPrincipal aliceUGIWithPrincipal = ugiProvider.getConfiguredUGI(aliceImpRequest);
        // Shouldn't be a kerberos UGI
        Assert.assertFalse(aliceUGIWithPrincipal.getUGI().hasKerberosCredentials());
        // Validate the credentials
        Token<? extends TokenIdentifier> token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("entity"));
        Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
        Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
        Assert.assertEquals(new Text("entity"), token.getKind());
        Assert.assertEquals(new Text("service"), token.getService());
        token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("opType"));
        Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
        Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
        Assert.assertEquals(new Text("opType"), token.getKind());
        Assert.assertEquals(new Text("service"), token.getService());
        // Fetch it again, it should return the same UGI due to caching
        Assert.assertSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
        // Invalid the cache and fetch it again. A different UGI should be returned
        ugiProvider.invalidCache();
        Assert.assertNotSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
    } finally {
        httpService.stop();
    }
    // cleanup
    ownerAdmin.delete(aliceEntity);
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) Discoverable(org.apache.twill.discovery.Discoverable) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) Text(org.apache.hadoop.io.Text) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) NettyHttpService(io.cdap.http.NettyHttpService) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) Test(org.junit.Test)

Aggregations

DefaultInternalAuthenticator (io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator)10 RemoteClientFactory (io.cdap.cdap.common.internal.remote.RemoteClientFactory)10 AuthenticationTestContext (io.cdap.cdap.security.auth.context.AuthenticationTestContext)10 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)7 LocationFactory (org.apache.twill.filesystem.LocationFactory)5 BeforeClass (org.junit.BeforeClass)5 IOException (java.io.IOException)4 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)4 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)3 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)3 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)3 Service (com.google.common.util.concurrent.Service)2 ArtifactInfo (io.cdap.cdap.api.artifact.ArtifactInfo)2 ArtifactManager (io.cdap.cdap.api.artifact.ArtifactManager)2 CloseableClassLoader (io.cdap.cdap.api.artifact.CloseableClassLoader)2 AccessException (io.cdap.cdap.api.security.AccessException)2 ServiceStore (io.cdap.cdap.app.store.ServiceStore)2 DatasetClient (io.cdap.cdap.client.DatasetClient)2 MetadataClient (io.cdap.cdap.client.MetadataClient)2 Constants (io.cdap.cdap.common.conf.Constants)2