### Question:
ApplicationAuthorizationValidator { @SuppressWarnings("unchecked") public boolean isAuthorizedForApp(Entity app, SLIPrincipal principal) { if (principal.isAdminRealmAuthenticated()) { return isAdminVisible(app); } else { if (isAutoAuthorized(app)) { return true; } else if (!isOperatorApproved(app)) { return false; } else { Set<String> edOrgs = helper.locateDirectEdorgs(principal.getEntity()); NeutralQuery appAuthCollQuery = new NeutralQuery(); appAuthCollQuery.addCriteria(new NeutralCriteria("applicationId", "=", app.getEntityId())); appAuthCollQuery.addCriteria(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, edOrgs)); Entity authorizedApps = repo.findOne("applicationAuthorization", appAuthCollQuery); if (authorizedApps != null) { if (isAutoApproved(app)) { return true; } else { List<String> approvedDistricts = new ArrayList<String>((List<String>) app.getBody().get("authorized_ed_orgs")); List<String> myDistricts = helper.getDistricts(edOrgs); approvedDistricts.retainAll(myDistricts); return !approvedDistricts.isEmpty(); } } } } return false; }  @SuppressWarnings("unchecked") boolean isAuthorizedForApp(Entity app, SLIPrincipal principal); Set<String> getAuthorizingEdOrgsForApp(String clientId);  }### Answer:
@Test public void testStaffUser() throws InterruptedException { SLIPrincipal principal = new SLIPrincipal(); principal.setEntity(staff1); principal.setEdOrg(lea1.getEntityId()); principal.setRealm(leaRealm.getEntityId()); injector.setSecurityContext(principal, false); assertTrue("Can see autoApp", validator.isAuthorizedForApp(autoApp, principal)); assertTrue("Can see approvedApp", validator.isAuthorizedForApp(approvedApp, principal)); assertFalse("Cannot see notOperatorApproved", validator.isAuthorizedForApp(notOperatorApproved, principal)); assertFalse("Cannot see approvedAppWithoutOperator", validator.isAuthorizedForApp(approvedAppWithoutOperator, principal)); assertFalse("Cannot see adminApp", validator.isAuthorizedForApp(adminApp, principal)); assertFalse("Cannot see noAuthApp", validator.isAuthorizedForApp(noAuthApp, principal)); assertFalse("Cannot see nonApprovedApp", validator.isAuthorizedForApp(nonApprovedApp, principal)); assertFalse("Cannot see notAuthorizedApp", validator.isAuthorizedForApp(notAuthorizedApp, principal)); }
@Test public void testAdminUser() throws InterruptedException { SLIPrincipal principal = new SLIPrincipal(); principal.setEntity(null); principal.setEdOrg("SOMETHING"); principal.setRealm(sliRealm.getEntityId()); principal.setAdminRealmAuthenticated(true); injector.setSecurityContext(principal, false); assertFalse("Cannot see autoApp", validator.isAuthorizedForApp(autoApp, principal)); assertFalse("Cannot see approvedApp", validator.isAuthorizedForApp(approvedApp, principal)); assertTrue("Can see adminApp", validator.isAuthorizedForApp(adminApp, principal)); assertFalse("Cannot see notOperatorApproved", validator.isAuthorizedForApp(notOperatorApproved, principal)); assertFalse("Cannot see approvedAppWithoutOperator", validator.isAuthorizedForApp(approvedAppWithoutOperator, principal)); assertFalse("Cannot see noAuthApp", validator.isAuthorizedForApp(noAuthApp, principal)); assertFalse("Cannot see nonApprovedApp", validator.isAuthorizedForApp(nonApprovedApp, principal)); assertFalse("Cannot see notAuthorizedApp", validator.isAuthorizedForApp(notAuthorizedApp, principal)); }