use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class AuthorizationTest method testFlowStreamAuth.
@Test
@Category(SlowTests.class)
public void testFlowStreamAuth() throws Exception {
createAuthNamespace();
Authorizer authorizer = getAuthorizer();
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));
final FlowManager flowManager = appManager.getFlowManager(StreamAuthApp.FLOW);
StreamId streamId = AUTH_NAMESPACE.stream(StreamAuthApp.STREAM);
StreamManager streamManager = getStreamManager(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM));
StreamManager streamManager2 = getStreamManager(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM2));
streamManager.send("Auth");
flowManager.start();
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> kvTable = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
return kvTable.get().read("Auth") != null;
}
}, 5, TimeUnit.SECONDS);
flowManager.stop();
flowManager.waitForRun(ProgramRunStatus.KILLED, 60, TimeUnit.SECONDS);
// Now revoke read permission for Alice on that stream (revoke ALL and then grant everything other than READ)
authorizer.revoke(streamId, ALICE, EnumSet.allOf(Action.class));
authorizer.grant(streamId, ALICE, EnumSet.of(Action.WRITE, Action.ADMIN, Action.EXECUTE));
streamManager.send("Security");
streamManager2.send("Safety");
try {
flowManager.start();
} catch (RuntimeException e) {
Assert.assertTrue(e.getCause() instanceof UnauthorizedException);
}
authorizer.grant(streamId, ALICE, ImmutableSet.of(Action.READ));
flowManager.start();
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> kvTable = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
return kvTable.get().read("Security") != null;
}
}, 5, TimeUnit.SECONDS);
authorizer.revoke(streamId, ALICE, ImmutableSet.of(Action.READ));
TimeUnit.MILLISECONDS.sleep(10);
flowManager.stop();
flowManager.waitForRuns(ProgramRunStatus.KILLED, 2, 5, TimeUnit.SECONDS);
appManager.delete();
}
use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class StreamAdminTest method grantAndAssertSuccess.
private void grantAndAssertSuccess(EntityId entityId, Principal principal, Set<Action> actions) throws Exception {
Authorizer authorizer = getAuthorizer();
Set<Privilege> existingPrivileges = authorizer.listPrivileges(principal);
authorizer.grant(entityId, principal, actions);
ImmutableSet.Builder<Privilege> expectedPrivilegesAfterGrant = ImmutableSet.builder();
for (Action action : actions) {
expectedPrivilegesAfterGrant.add(new Privilege(entityId, action));
}
Assert.assertEquals(Sets.union(existingPrivileges, expectedPrivilegesAfterGrant.build()), authorizer.listPrivileges(principal));
}
use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class StreamAdminTest method revokeAndAssertSuccess.
private void revokeAndAssertSuccess(EntityId entityId, Principal principal, Set<Action> actions) throws Exception {
Authorizer authorizer = getAuthorizer();
Set<Privilege> existingPrivileges = authorizer.listPrivileges(principal);
authorizer.revoke(entityId, principal, actions);
Set<Privilege> revokedPrivileges = new HashSet<>();
for (Action action : actions) {
revokedPrivileges.add(new Privilege(entityId, action));
}
Assert.assertEquals(Sets.difference(existingPrivileges, revokedPrivileges), authorizer.listPrivileges(principal));
}
use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class AuthorizationTest method grantAndAssertSuccess.
private void grantAndAssertSuccess(EntityId entityId, Principal principal, Set<Action> actions) throws Exception {
Authorizer authorizer = getAuthorizer();
Set<Privilege> existingPrivileges = authorizer.listPrivileges(principal);
authorizer.grant(entityId, principal, actions);
ImmutableSet.Builder<Privilege> expectedPrivilegesAfterGrant = ImmutableSet.builder();
for (Action action : actions) {
expectedPrivilegesAfterGrant.add(new Privilege(entityId, action));
}
Assert.assertEquals(Sets.union(existingPrivileges, expectedPrivilegesAfterGrant.build()), authorizer.listPrivileges(principal));
}
use of co.cask.cdap.security.spi.authorization.Authorizer in project cdap by caskdata.
the class AuthorizationTest method cleanupTest.
@After
public void cleanupTest() throws Exception {
Authorizer authorizer = getAuthorizer();
grantAndAssertSuccess(AUTH_NAMESPACE, SecurityRequestContext.toPrincipal(), EnumSet.allOf(Action.class));
// clean up. remove the namespace. all privileges on the namespace should be revoked
getNamespaceAdmin().delete(AUTH_NAMESPACE);
Assert.assertEquals(ImmutableSet.of(new Privilege(instance, Action.ADMIN)), authorizer.listPrivileges(ALICE));
// revoke privileges on the instance
revokeAndAssertSuccess(instance);
}
Aggregations