Search in sources :

Example 71 with ProgramType

use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.

the class ProgramLifecycleServiceAuthorizationTest method testProgramList.

@Test
public void testProgramList() throws Exception {
    SecurityRequestContext.setUserId(ALICE.getName());
    ApplicationId applicationId = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
    Map<EntityId, Set<Action>> neededPrivileges = ImmutableMap.<EntityId, Set<Action>>builder().put(applicationId, EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.artifact(AllProgramsApp.class.getSimpleName(), "1.0-SNAPSHOT"), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME2), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME3), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DS_WITH_SCHEMA_NAME), EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME), EnumSet.of(Action.ADMIN)).build();
    setUpPrivilegesAndExpectFailedDeploy(neededPrivileges);
    // now we should be able to deploy
    AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT, AllProgramsApp.class, null, cConf);
    // no auto grant now, the list will be empty for all program types
    for (ProgramType type : ProgramType.values()) {
        if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
            Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty());
        }
    }
    // no auto grant now, need to have privileges on the program to be able to see the programs
    authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.FLOW, AllProgramsApp.NoOpFlow.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
    authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.SERVICE, AllProgramsApp.NoOpService.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
    authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.WORKER, AllProgramsApp.NoOpWorker.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
    authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.SPARK, AllProgramsApp.NoOpSpark.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
    authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.MAPREDUCE, AllProgramsApp.NoOpMR.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
    authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.MAPREDUCE, AllProgramsApp.NoOpMR2.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
    authorizer.grant(Authorizable.fromEntityId(applicationId.program(ProgramType.WORKFLOW, AllProgramsApp.NoOpWorkflow.NAME)), ALICE, Collections.singleton(Action.EXECUTE));
    for (ProgramType type : ProgramType.values()) {
        if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
            Assert.assertFalse(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty());
            SecurityRequestContext.setUserId("bob");
            Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT, type).isEmpty());
            SecurityRequestContext.setUserId("alice");
        }
    }
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) EnumSet(java.util.EnumSet) Set(java.util.Set) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Aggregations

ProgramType (co.cask.cdap.proto.ProgramType)71 ProgramId (co.cask.cdap.proto.id.ProgramId)33 ApplicationId (co.cask.cdap.proto.id.ApplicationId)22 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)21 Path (javax.ws.rs.Path)16 BadRequestException (co.cask.cdap.common.BadRequestException)13 GET (javax.ws.rs.GET)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)12 NotFoundException (co.cask.cdap.common.NotFoundException)12 RunId (org.apache.twill.api.RunId)11 ProgramController (co.cask.cdap.app.runtime.ProgramController)8 ArrayList (java.util.ArrayList)8 ProgramContextAware (co.cask.cdap.data.ProgramContextAware)6 BasicProgramContext (co.cask.cdap.internal.app.runtime.BasicProgramContext)6 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)5 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)5 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)4 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)4 PluginInstantiator (co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator)4