Search in sources :

Example 1 with AuthenticationTestContext

use of io.cdap.cdap.security.auth.context.AuthenticationTestContext 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 AuthenticationTestContext

use of io.cdap.cdap.security.auth.context.AuthenticationTestContext 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 AuthenticationTestContext

use of io.cdap.cdap.security.auth.context.AuthenticationTestContext in project cdap by caskdata.

the class AbstractDatasetFrameworkTest method testAuditPublish.

@Test
public void testAuditPublish() throws Exception {
    // Clear all audit messages
    inMemoryAuditPublisher.popMessages();
    List<AuditMessage> expectedMessages = new ArrayList<>();
    // Adding modules
    DatasetFramework framework = getFramework();
    framework.addModule(IN_MEMORY, new InMemoryTableModule());
    // Creating instances
    framework.addInstance(Table.class.getName(), MY_TABLE, DatasetProperties.EMPTY);
    expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
    framework.addInstance(Table.class.getName(), MY_TABLE2, DatasetProperties.EMPTY);
    expectedMessages.add(new AuditMessage(0, MY_TABLE2, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
    // Update instance
    framework.updateInstance(MY_TABLE, DatasetProperties.EMPTY);
    expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.UPDATE, AuditPayload.EMPTY_PAYLOAD));
    // Access instance
    ProgramRunId runId = new ProgramId("ns", "app", ProgramType.WORKER, "worker").run(RunIds.generate().getId());
    LineageWriterDatasetFramework lineageFramework = new LineageWriterDatasetFramework(framework, new NoOpLineageWriter(), new NoOpUsageRegistry(), new AuthenticationTestContext(), new NoOpAccessController());
    lineageFramework.setContext(new TestProgramContext(runId));
    lineageFramework.setAuditPublisher(inMemoryAuditPublisher);
    lineageFramework.getDataset(MY_TABLE, ImmutableMap.<String, String>of(), getClass().getClassLoader());
    expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.ACCESS, new AccessPayload(AccessType.UNKNOWN, runId)));
    // Truncate instance
    framework.truncateInstance(MY_TABLE);
    expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.TRUNCATE, AuditPayload.EMPTY_PAYLOAD));
    // Delete instance
    framework.deleteInstance(MY_TABLE);
    expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
    // Delete all instances in a namespace
    framework.deleteAllInstances(MY_TABLE2.getParent());
    expectedMessages.add(new AuditMessage(0, MY_TABLE2, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
    Assert.assertEquals(expectedMessages, inMemoryAuditPublisher.popMessages());
    // cleanup
    framework.deleteModule(IN_MEMORY);
}
Also used : AuditMessage(io.cdap.cdap.proto.audit.AuditMessage) Table(io.cdap.cdap.api.dataset.table.Table) ArrayList(java.util.ArrayList) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) NoOpUsageRegistry(io.cdap.cdap.data2.registry.NoOpUsageRegistry) ProgramId(io.cdap.cdap.proto.id.ProgramId) LineageWriterDatasetFramework(io.cdap.cdap.data2.metadata.writer.LineageWriterDatasetFramework) LineageWriterDatasetFramework(io.cdap.cdap.data2.metadata.writer.LineageWriterDatasetFramework) InMemoryTableModule(io.cdap.cdap.data2.dataset2.module.lib.inmemory.InMemoryTableModule) AccessPayload(io.cdap.cdap.proto.audit.payload.access.AccessPayload) NoOpLineageWriter(io.cdap.cdap.data2.metadata.writer.NoOpLineageWriter) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) NoOpAccessController(io.cdap.cdap.security.spi.authorization.NoOpAccessController) Test(org.junit.Test)

Example 4 with AuthenticationTestContext

use of io.cdap.cdap.security.auth.context.AuthenticationTestContext 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 5 with AuthenticationTestContext

use of io.cdap.cdap.security.auth.context.AuthenticationTestContext in project cdap by caskdata.

the class TetheringServerHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    // Define all StructuredTable before starting any services that need StructuredTable
    StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
    cConf.setBoolean(Constants.Tethering.TETHERING_SERVER_ENABLED, true);
    cConf.setInt(Constants.Tethering.CONNECTION_TIMEOUT_SECONDS, 1);
    List<Permission> tetheringPermissions = Arrays.asList(InstancePermission.TETHER);
    InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
    inMemoryAccessController.grant(Authorizable.fromEntityId(InstanceId.SELF), MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(tetheringPermissions)));
    ContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(new AuthenticationTestContext(), inMemoryAccessController);
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    service = new CommonNettyHttpServiceBuilder(CConfiguration.create(), getClass().getSimpleName()).setHttpHandlers(new TetheringServerHandler(cConf, tetheringStore, messagingService, contextAccessEnforcer), new TetheringHandler(cConf, tetheringStore, messagingService)).build();
    service.start();
    config = ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(service.getBindAddress().getHostName()).setPort(service.getBindAddress().getPort()).setSSLEnabled(false).build()).build();
}
Also used : CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) InMemoryAccessController(io.cdap.cdap.security.authorization.InMemoryAccessController) InstancePermission(io.cdap.cdap.proto.security.InstancePermission) Permission(io.cdap.cdap.proto.security.Permission) DefaultContextAccessEnforcer(io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) DefaultContextAccessEnforcer(io.cdap.cdap.security.authorization.DefaultContextAccessEnforcer) ContextAccessEnforcer(io.cdap.cdap.security.spi.authorization.ContextAccessEnforcer) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

AuthenticationTestContext (io.cdap.cdap.security.auth.context.AuthenticationTestContext)15 DefaultInternalAuthenticator (io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator)10 RemoteClientFactory (io.cdap.cdap.common.internal.remote.RemoteClientFactory)10 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)7 BeforeClass (org.junit.BeforeClass)6 LocationFactory (org.apache.twill.filesystem.LocationFactory)5 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)4 CommonNettyHttpServiceBuilder (io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder)4 IOException (java.io.IOException)4 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)4 MessagingService (io.cdap.cdap.messaging.MessagingService)3 StructuredTableAdmin (io.cdap.cdap.spi.data.StructuredTableAdmin)3 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)3 Test (org.junit.Test)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 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)2 AccessException (io.cdap.cdap.api.security.AccessException)2