use of co.cask.cdap.proto.id.InstanceId in project cdap by caskdata.
the class AuthorizationBootstrapperTest method setup.
@BeforeClass
public static void setup() throws Exception {
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
cConf.setBoolean(Constants.Security.ENABLED, true);
cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), InMemoryAuthorizer.class);
cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, deploymentJar.toURI().getPath());
// make Alice an admin user, so she can create namespaces
cConf.set(Constants.Security.Authorization.ADMIN_USERS, ADMIN_USER.getName());
instanceId = new InstanceId(cConf.get(Constants.INSTANCE_NAME));
// setup a system artifact
File systemArtifactsDir = TMP_FOLDER.newFolder();
cConf.set(Constants.AppFabric.SYSTEM_ARTIFACTS_DIR, systemArtifactsDir.getAbsolutePath());
createSystemArtifact(systemArtifactsDir);
Injector injector = Guice.createInjector(new AppFabricTestModule(cConf));
namespaceQueryAdmin = injector.getInstance(NamespaceQueryAdmin.class);
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
defaultNamespaceEnsurer = new DefaultNamespaceEnsurer(namespaceAdmin);
discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
txManager = injector.getInstance(TransactionManager.class);
datasetService = injector.getInstance(DatasetService.class);
systemArtifactLoader = injector.getInstance(SystemArtifactLoader.class);
authorizationBootstrapper = injector.getInstance(AuthorizationBootstrapper.class);
artifactRepository = injector.getInstance(ArtifactRepository.class);
dsFramework = injector.getInstance(DatasetFramework.class);
authorizationEnforcer = injector.getInstance(AuthorizationEnforcer.class);
}
use of co.cask.cdap.proto.id.InstanceId in project cdap by caskdata.
the class EntityExistenceTest method testDoesNotExist.
@Test
public void testDoesNotExist() {
assertDoesNotExist(new InstanceId(DOES_NOT_EXIST));
assertDoesNotExist(new NamespaceId(DOES_NOT_EXIST));
assertDoesNotExist(NamespaceId.DEFAULT.artifact(DOES_NOT_EXIST, "1.0"));
ApplicationId app = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
assertDoesNotExist(NamespaceId.DEFAULT.app(DOES_NOT_EXIST));
assertDoesNotExist(app.mr(DOES_NOT_EXIST));
assertDoesNotExist(NamespaceId.DEFAULT.dataset(DOES_NOT_EXIST));
assertDoesNotExist(NamespaceId.DEFAULT.stream(DOES_NOT_EXIST));
assertDoesNotExist(NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME).view(DOES_NOT_EXIST));
}
use of co.cask.cdap.proto.id.InstanceId in project cdap by caskdata.
the class AuthEnforceRewriterTest method test.
@Test
public void test() throws Exception {
ByteCodeClassLoader classLoader = new ByteCodeClassLoader(getClass().getClassLoader());
classLoader.addClass(rewrite(DummyAuthEnforce.ValidAuthEnforceAnnotations.class));
classLoader.addClass(rewrite(DummyAuthEnforce.AnotherValidAuthEnforceAnnotations.class));
classLoader.addClass(rewrite(DummyAuthEnforce.ClassImplementingInterfaceWithAuthAnnotation.class));
classLoader.addClass(rewrite(DummyAuthEnforce.ClassWithoutAuthEnforce.class));
classLoader.addClass(rewrite(DummyAuthEnforce.ValidAuthEnforceWithFields.class));
// Need to invoke the method on the object created from the rewritten class in the classloader since trying to
// cast it here to DummyAuthEnforce will fail since the object is created from a class which was loaded from a
// different classloader.
Class<?> cls = classLoader.loadClass(DummyAuthEnforce.ValidAuthEnforceAnnotations.class.getName());
Object rewrittenObject = loadRewritten(classLoader, DummyAuthEnforce.class.getName(), cls.getName());
invokeSetters(cls, rewrittenObject);
// tests a valid AuthEnforce annotation which has single action
testRewrite(getMethod(cls, "testSingleAction", NamespaceId.class), rewrittenObject, ExceptionAuthorizationEnforcer.ExpectedException.class, NamespaceId.DEFAULT);
// tests a valid AuthEnforce annotation which has multiple action
testRewrite(getMethod(cls, "testMultipleAction", NamespaceId.class), rewrittenObject, ExceptionAuthorizationEnforcer.ExpectedException.class, NamespaceId.DEFAULT);
// test that the class rewrite did not affect other non annotated methods
testRewrite(getMethod(cls, "testNoAuthEnforceAnnotation", NamespaceId.class), rewrittenObject, DummyAuthEnforce.EnforceNotCalledException.class, NamespaceId.DEFAULT);
// test that the class rewrite works for method whose signature does not specify throws exception
testRewrite(getMethod(cls, "testMethodWithoutException", NamespaceId.class), rewrittenObject, ExceptionAuthorizationEnforcer.ExpectedException.class, NamespaceId.DEFAULT);
// tests that class rewriting does not happen if an interface has a method with AuthEnforce
cls = classLoader.loadClass(DummyAuthEnforce.ClassImplementingInterfaceWithAuthAnnotation.class.getName());
rewrittenObject = loadRewritten(classLoader, DummyAuthEnforce.class.getName(), cls.getName());
invokeSetters(cls, rewrittenObject);
testRewrite(getMethod(cls, "interfaceMethodWithAuthEnforce", NamespaceId.class), rewrittenObject, DummyAuthEnforce.EnforceNotCalledException.class, NamespaceId.DEFAULT);
// test that class rewriting does not happen for classes which does not have AuthEnforce annotation on its method
cls = classLoader.loadClass(DummyAuthEnforce.ClassWithoutAuthEnforce.class.getName());
rewrittenObject = loadRewritten(classLoader, DummyAuthEnforce.class.getName(), cls.getName());
invokeSetters(cls, rewrittenObject);
testRewrite(getMethod(cls, "methodWithoutAuthEnforce", NamespaceId.class), rewrittenObject, DummyAuthEnforce.EnforceNotCalledException.class, NamespaceId.DEFAULT);
// test that class rewriting works for a valid annotated method in another inner class and needs the
// invokeSetters to called independently for this
cls = classLoader.loadClass(DummyAuthEnforce.AnotherValidAuthEnforceAnnotations.class.getName());
rewrittenObject = loadRewritten(classLoader, DummyAuthEnforce.class.getName(), cls.getName());
invokeSetters(cls, rewrittenObject);
testRewrite(getMethod(cls, "testSomeOtherAction", NamespaceId.class), rewrittenObject, ExceptionAuthorizationEnforcer.ExpectedException.class, NamespaceId.DEFAULT);
// test that class rewriting works for a valid annotation with field instances
cls = classLoader.loadClass(DummyAuthEnforce.ValidAuthEnforceWithFields.class.getName());
rewrittenObject = loadRewritten(classLoader, DummyAuthEnforce.class.getName(), cls.getName());
invokeSetters(cls, rewrittenObject);
testRewrite(getMethod(cls, "testNoParameters"), rewrittenObject, ExceptionAuthorizationEnforcer.ExpectedException.class);
testRewrite(getMethod(cls, "testParaNameSameAsField", NamespaceId.class), rewrittenObject, new NamespaceId("ns"), ExceptionAuthorizationEnforcer.ExpectedException.class, NamespaceId.DEFAULT);
testRewrite(getMethod(cls, "testParaPreference", InstanceId.class), rewrittenObject, new InstanceId("i1"), ExceptionAuthorizationEnforcer.ExpectedException.class, new InstanceId("i1"));
testRewrite(getMethod(cls, "testThisClassPreference", NamespaceId.class), rewrittenObject, new NamespaceId("ns"), ExceptionAuthorizationEnforcer.ExpectedException.class, NamespaceId.DEFAULT);
}
use of co.cask.cdap.proto.id.InstanceId in project cdap by caskdata.
the class AuthorizationTest method setup.
@BeforeClass
public static void setup() {
instance = new InstanceId(getConfiguration().get(Constants.INSTANCE_NAME));
oldUser = SecurityRequestContext.getUserId();
}
use of co.cask.cdap.proto.id.InstanceId in project cdap by caskdata.
the class EntityExistenceTest method testExists.
@Test
@SuppressWarnings("unchecked")
public void testExists() throws NotFoundException {
existenceVerifier.ensureExists(new InstanceId(EXISTS));
existenceVerifier.ensureExists(NAMESPACE);
existenceVerifier.ensureExists(ARTIFACT);
ApplicationId app = NAMESPACE.app(AllProgramsApp.NAME);
existenceVerifier.ensureExists(app);
existenceVerifier.ensureExists(app.mr(AllProgramsApp.NoOpMR.NAME));
existenceVerifier.ensureExists(NAMESPACE.dataset(AllProgramsApp.DATASET_NAME));
existenceVerifier.ensureExists(NAMESPACE.stream(AllProgramsApp.STREAM_NAME));
existenceVerifier.ensureExists(VIEW);
}
Aggregations