### Question:
DataAuthorizable implements Authorizable, EnforcePolicyPermissionsThroughBaseResource { @Override public void authorize(Authorizer authorizer, RequestAction action, NiFiUser user, Map<String, String> resourceContext) throws AccessDeniedException { if (user == null) { throw new AccessDeniedException("Unknown user."); } NiFiUser chainedUser = user; do { try { Authorizable.super.authorize(authorizer, action, chainedUser, resourceContext); chainedUser = chainedUser.getChain(); } catch (final ResourceNotFoundException e) { throw new AccessDeniedException("Unknown source component."); } } while (chainedUser != null); } DataAuthorizable(final Authorizable authorizable); @Override Authorizable getBaseAuthorizable(); @Override Authorizable getParentAuthorizable(); @Override Resource getResource(); @Override AuthorizationResult checkAuthorization(Authorizer authorizer, RequestAction action, NiFiUser user, Map<String, String> resourceContext); @Override void authorize(Authorizer authorizer, RequestAction action, NiFiUser user, Map<String, String> resourceContext);  }### Answer:
@Test(expected = AccessDeniedException.class) public void testAuthorizeNullUser() { testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, null, null); }
@Test(expected = AccessDeniedException.class) public void testAuthorizeUnauthorizedUser() { final NiFiUser user = new StandardNiFiUser("unknown"); testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); }
@Test public void testAuthorizedUser() { final NiFiUser user = new StandardNiFiUser(IDENTITY_1); testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() { @Override public boolean matches(Object o) { return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity()); } })); }
@Test public void testAuthorizedUserChain() { final NiFiUser proxy2 = new StandardNiFiUser(PROXY_2); final NiFiUser proxy1 = new StandardNiFiUser(PROXY_1, proxy2); final NiFiUser user = new StandardNiFiUser(IDENTITY_1, proxy1); testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); verify(testAuthorizer, times(3)).authorize(any(AuthorizationRequest.class)); verifyAuthorizeForUser(IDENTITY_1); verifyAuthorizeForUser(PROXY_1); verifyAuthorizeForUser(PROXY_2); }
@Test(expected = AccessDeniedException.class) public void testAuthorizeUnauthorizedUser() { final NiFiUser user = new Builder().identity("unknown").build(); testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); }
@Test public void testAuthorizedUser() { final NiFiUser user = new Builder().identity(IDENTITY_1).build(); testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); verify(testAuthorizer, times(1)).authorize(argThat(new ArgumentMatcher<AuthorizationRequest>() { @Override public boolean matches(Object o) { return IDENTITY_1.equals(((AuthorizationRequest) o).getIdentity()); } })); }
@Test public void testAuthorizedUserChain() { final NiFiUser proxy2 = new Builder().identity(PROXY_2).build(); final NiFiUser proxy1 = new Builder().identity(PROXY_1).chain(proxy2).build(); final NiFiUser user = new Builder().identity(IDENTITY_1).chain(proxy1).build(); testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); verify(testAuthorizer, times(3)).authorize(any(AuthorizationRequest.class)); verifyAuthorizeForUser(IDENTITY_1); verifyAuthorizeForUser(PROXY_1); verifyAuthorizeForUser(PROXY_2); }