use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class AuthorizationTest method createAuthNamespace.
private void createAuthNamespace() throws Exception {
Authorizer authorizer = getAuthorizer();
grantAndAssertSuccess(instance, ALICE, ImmutableSet.of(Action.ADMIN));
getNamespaceAdmin().create(AUTH_NAMESPACE_META);
Assert.assertEquals(ImmutableSet.of(new Privilege(instance, Action.ADMIN), new Privilege(AUTH_NAMESPACE, Action.ADMIN), new Privilege(AUTH_NAMESPACE, Action.READ), new Privilege(AUTH_NAMESPACE, Action.WRITE), new Privilege(AUTH_NAMESPACE, Action.EXECUTE)), authorizer.listPrivileges(ALICE));
}
use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class AuthorizationTest method assertNoAccess.
private void assertNoAccess(Principal principal, final EntityId entityId) throws Exception {
Authorizer authorizer = getAuthorizer();
Predicate<Privilege> entityFilter = new Predicate<Privilege>() {
@Override
public boolean apply(Privilege input) {
return entityId.equals(input.getEntity());
}
};
Assert.assertTrue(Sets.filter(authorizer.listPrivileges(principal), entityFilter).isEmpty());
}
use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class AuthorizationTest method revokeAndAssertSuccess.
private void revokeAndAssertSuccess(final EntityId entityId) throws Exception {
Authorizer authorizer = getAuthorizer();
authorizer.revoke(entityId);
assertNoAccess(entityId);
}
use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class AuthorizationTest method testSparkStreamAuth.
@Test
@Category(SlowTests.class)
public void testSparkStreamAuth() throws Exception {
createAuthNamespace();
Authorizer authorizer = getAuthorizer();
StreamId streamId = AUTH_NAMESPACE.stream(StreamAuthApp.STREAM);
ApplicationManager appManager = deployApplication(AUTH_NAMESPACE, StreamAuthApp.class);
// After deploy, change Alice from ALL to ADMIN on the namespace
authorizer.revoke(AUTH_NAMESPACE, ALICE, EnumSet.allOf(Action.class));
authorizer.grant(AUTH_NAMESPACE, ALICE, EnumSet.of(Action.ADMIN));
StreamManager streamManager = getStreamManager(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM));
streamManager.send("Hello");
final SparkManager sparkManager = appManager.getSparkManager(StreamAuthApp.SPARK);
sparkManager.start();
sparkManager.waitForRun(ProgramRunStatus.COMPLETED, 1, TimeUnit.MINUTES);
DataSetManager<KeyValueTable> kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
try (KeyValueTable kvTable = kvManager.get()) {
byte[] value = kvTable.read("Hello");
Assert.assertArrayEquals(Bytes.toBytes("Hello"), value);
}
streamManager.send("World");
// Revoke READ permission on STREAM for Alice
authorizer.revoke(streamId, ALICE, EnumSet.allOf(Action.class));
authorizer.grant(streamId, ALICE, EnumSet.of(Action.WRITE, Action.ADMIN, Action.EXECUTE));
sparkManager.start();
sparkManager.waitForRun(ProgramRunStatus.FAILED, 1, TimeUnit.MINUTES);
kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
try (KeyValueTable kvTable = kvManager.get()) {
byte[] value = kvTable.read("World");
Assert.assertNull(value);
}
// Grant ALICE, READ permission on STREAM and now Spark job should run successfully
authorizer.grant(streamId, ALICE, ImmutableSet.of(Action.READ));
sparkManager.start();
sparkManager.waitForRuns(ProgramRunStatus.COMPLETED, 2, 1, TimeUnit.MINUTES);
kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
try (KeyValueTable kvTable = kvManager.get()) {
byte[] value = kvTable.read("World");
Assert.assertArrayEquals(Bytes.toBytes("World"), value);
}
appManager.delete();
assertNoAccess(AUTH_NAMESPACE.app(StreamAuthApp.APP));
}
Aggregations