use of co.cask.cdap.proto.security.Privilege 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.proto.security.Privilege 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);
}
use of co.cask.cdap.proto.security.Privilege 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.proto.security.Privilege 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());
}
Aggregations