### Question:
DefaultAuthorizationEnforcer extends AbstractAuthorizationEnforcer { @Override public void enforce(EntityId entity, Principal principal, Action action) throws Exception { if (!isSecurityAuthorizationEnabled()) { return; } doEnforce(entity, principal, Collections.singleton(action)); } @Inject  DefaultAuthorizationEnforcer(CConfiguration cConf, AuthorizerInstantiator authorizerInstantiator); @Override void enforce(EntityId entity, Principal principal, Action action); @Override Set<? extends EntityId> isVisible(Set<? extends EntityId> entityIds, Principal principal);  }### Answer:
@Test public void testPropagationDisabled() throws Exception { CConfiguration cConfCopy = CConfiguration.copy(CCONF); try (AuthorizerInstantiator authorizerInstantiator = new AuthorizerInstantiator(cConfCopy, AUTH_CONTEXT_FACTORY)) { DefaultAuthorizationEnforcer authorizationEnforcer = new DefaultAuthorizationEnforcer(cConfCopy, authorizerInstantiator); authorizerInstantiator.get().grant(Authorizable.fromEntityId(NS), ALICE, ImmutableSet.of(Action.ADMIN)); authorizationEnforcer.enforce(NS, ALICE, Action.ADMIN); try { authorizationEnforcer.enforce(APP, ALICE, Action.ADMIN); Assert.fail("Alice should not have ADMIN privilege on the APP."); } catch (UnauthorizedException ignored) { } } }
@Test public void testAuthEnforce() throws Exception { try (AuthorizerInstantiator authorizerInstantiator = new AuthorizerInstantiator(CCONF, AUTH_CONTEXT_FACTORY)) { Authorizer authorizer = authorizerInstantiator.get(); DefaultAuthorizationEnforcer authEnforcementService = new DefaultAuthorizationEnforcer(CCONF, authorizerInstantiator); assertAuthorizationFailure(authEnforcementService, NS, ALICE, Action.ADMIN); DatasetId ds = NS.dataset("ds"); authorizer.grant(Authorizable.fromEntityId(NS), ALICE, ImmutableSet.of(Action.READ, Action.WRITE)); authorizer.grant(Authorizable.fromEntityId(ds), BOB, ImmutableSet.of(Action.ADMIN)); authEnforcementService.enforce(NS, ALICE, ImmutableSet.of(Action.READ, Action.WRITE)); assertAuthorizationFailure(authEnforcementService, NS, ALICE, EnumSet.allOf(Action.class)); assertAuthorizationFailure(authEnforcementService, ds, ALICE, Action.READ); assertAuthorizationFailure(authEnforcementService, ds, ALICE, Action.WRITE); assertAuthorizationFailure(authEnforcementService, NS, ALICE, Action.ADMIN); authEnforcementService.enforce(ds, BOB, Action.ADMIN); authorizer.revoke(Authorizable.fromEntityId(NS), ALICE, ImmutableSet.of(Action.READ)); try { authEnforcementService.enforce(NS, ALICE, Action.READ); Assert.fail(String.format("Expected %s to not have '%s' privilege on %s but it does.", ALICE, Action.READ, NS)); } catch (UnauthorizedException ignored) { } authorizer.revoke(Authorizable.fromEntityId(NS)); assertAuthorizationFailure(authEnforcementService, NS, ALICE, Action.READ); assertAuthorizationFailure(authEnforcementService, NS, ALICE, Action.WRITE); authEnforcementService.enforce(ds, BOB, Action.ADMIN); } }