@Test public void testGetAuths() { Map<String, Object> appBody = new HashMap<String, Object>(); Entity app = repo.create("application", appBody); Map<String, Object> auth = new HashMap<String, Object>(); auth.put("applicationId", app.getEntityId()); auth.put("edorgs", getAuthList(SecurityUtil.getEdOrgId())); repo.create("applicationAuthorization", auth); ResponseImpl resp = (ResponseImpl) res.getAuthorizations(null); Assert.assertEquals(200, resp.getStatus()); List ents = (List) resp.getEntity(); Assert.assertEquals(1, ents.size()); }
@GET @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorizations(@QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Iterable<EntityBody> ents = null; if (principal.isAdminRealmAuthenticated()) { ents = service.list(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs))); } else { ents = filterOutAutoAuthorized(service.listBasedOnContextualRoles(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs)))); } Iterable<Entity> appQuery = repo.findAll("application", new NeutralQuery()); Map<String, Entity> allApps = new HashMap<String, Entity>(); for (Entity ent : appQuery) { if(!isAutoAuthorizedApp(ent)) { allApps.put(ent.getEntityId(), ent); } } List<Map> results = new ArrayList<Map>(); for (EntityBody body : ents) { HashMap<String, Object> entity = new HashMap<String, Object>(); String appId = (String) body.get("applicationId"); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) body.get("edorgs"); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", true); if(!isSEAAdmin()) { entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } results.add(entity); allApps.remove(appId); } for (Map.Entry<String, Entity> entry : allApps.entrySet()) { Boolean autoApprove = (Boolean) entry.getValue().getBody().get("allowed_for_all_edorgs"); List<String> approvedEdorgs = (List<String>) entry.getValue().getBody().get("authorized_ed_orgs"); if ((autoApprove != null && autoApprove) || isSEAAdmin() || (approvedEdorgs != null && CollectionUtils.containsAny(approvedEdorgs, inScopeEdOrgs))) { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", entry.getKey()); entity.put("appId", entry.getKey()); entity.put("authorized", false); results.add(entity); } } return Response.status(Status.OK).entity(results).build(); }
ApplicationAuthorizationResource { @GET @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorizations(@QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Iterable<EntityBody> ents = null; if (principal.isAdminRealmAuthenticated()) { ents = service.list(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs))); } else { ents = filterOutAutoAuthorized(service.listBasedOnContextualRoles(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs)))); } Iterable<Entity> appQuery = repo.findAll("application", new NeutralQuery()); Map<String, Entity> allApps = new HashMap<String, Entity>(); for (Entity ent : appQuery) { if(!isAutoAuthorizedApp(ent)) { allApps.put(ent.getEntityId(), ent); } } List<Map> results = new ArrayList<Map>(); for (EntityBody body : ents) { HashMap<String, Object> entity = new HashMap<String, Object>(); String appId = (String) body.get("applicationId"); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) body.get("edorgs"); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", true); if(!isSEAAdmin()) { entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } results.add(entity); allApps.remove(appId); } for (Map.Entry<String, Entity> entry : allApps.entrySet()) { Boolean autoApprove = (Boolean) entry.getValue().getBody().get("allowed_for_all_edorgs"); List<String> approvedEdorgs = (List<String>) entry.getValue().getBody().get("authorized_ed_orgs"); if ((autoApprove != null && autoApprove) || isSEAAdmin() || (approvedEdorgs != null && CollectionUtils.containsAny(approvedEdorgs, inScopeEdOrgs))) { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", entry.getKey()); entity.put("appId", entry.getKey()); entity.put("authorized", false); results.add(entity); } } return Response.status(Status.OK).entity(results).build(); } }
ApplicationAuthorizationResource { @GET @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorizations(@QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Iterable<EntityBody> ents = null; if (principal.isAdminRealmAuthenticated()) { ents = service.list(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs))); } else { ents = filterOutAutoAuthorized(service.listBasedOnContextualRoles(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs)))); } Iterable<Entity> appQuery = repo.findAll("application", new NeutralQuery()); Map<String, Entity> allApps = new HashMap<String, Entity>(); for (Entity ent : appQuery) { if(!isAutoAuthorizedApp(ent)) { allApps.put(ent.getEntityId(), ent); } } List<Map> results = new ArrayList<Map>(); for (EntityBody body : ents) { HashMap<String, Object> entity = new HashMap<String, Object>(); String appId = (String) body.get("applicationId"); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) body.get("edorgs"); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", true); if(!isSEAAdmin()) { entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } results.add(entity); allApps.remove(appId); } for (Map.Entry<String, Entity> entry : allApps.entrySet()) { Boolean autoApprove = (Boolean) entry.getValue().getBody().get("allowed_for_all_edorgs"); List<String> approvedEdorgs = (List<String>) entry.getValue().getBody().get("authorized_ed_orgs"); if ((autoApprove != null && autoApprove) || isSEAAdmin() || (approvedEdorgs != null && CollectionUtils.containsAny(approvedEdorgs, inScopeEdOrgs))) { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", entry.getKey()); entity.put("appId", entry.getKey()); entity.put("authorized", false); results.add(entity); } } return Response.status(Status.OK).entity(results).build(); }  }
ApplicationAuthorizationResource { @GET @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorizations(@QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Iterable<EntityBody> ents = null; if (principal.isAdminRealmAuthenticated()) { ents = service.list(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs))); } else { ents = filterOutAutoAuthorized(service.listBasedOnContextualRoles(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs)))); } Iterable<Entity> appQuery = repo.findAll("application", new NeutralQuery()); Map<String, Entity> allApps = new HashMap<String, Entity>(); for (Entity ent : appQuery) { if(!isAutoAuthorizedApp(ent)) { allApps.put(ent.getEntityId(), ent); } } List<Map> results = new ArrayList<Map>(); for (EntityBody body : ents) { HashMap<String, Object> entity = new HashMap<String, Object>(); String appId = (String) body.get("applicationId"); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) body.get("edorgs"); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", true); if(!isSEAAdmin()) { entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } results.add(entity); allApps.remove(appId); } for (Map.Entry<String, Entity> entry : allApps.entrySet()) { Boolean autoApprove = (Boolean) entry.getValue().getBody().get("allowed_for_all_edorgs"); List<String> approvedEdorgs = (List<String>) entry.getValue().getBody().get("authorized_ed_orgs"); if ((autoApprove != null && autoApprove) || isSEAAdmin() || (approvedEdorgs != null && CollectionUtils.containsAny(approvedEdorgs, inScopeEdOrgs))) { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", entry.getKey()); entity.put("appId", entry.getKey()); entity.put("authorized", false); results.add(entity); } } return Response.status(Status.OK).entity(results).build(); }  @PostConstruct void init(); @GET @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) Response getAuthorization(@PathParam("appId") String appId, @QueryParam("edorg") String edorg); boolean isAutoAuthorizedApp(Entity appEntity); @PUT @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) Response updateAuthorization(@PathParam("appId") String appId, EntityBody auth); static List<Map<String, Object>> enrichAuthorizedEdOrgsList(List<String> edOrgIds); @GET @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) Response getAuthorizations(@QueryParam("edorg") String edorg); }
ApplicationAuthorizationResource { @GET @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorizations(@QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Iterable<EntityBody> ents = null; if (principal.isAdminRealmAuthenticated()) { ents = service.list(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs))); } else { ents = filterOutAutoAuthorized(service.listBasedOnContextualRoles(new NeutralQuery(new NeutralCriteria("edorgs.authorizedEdorg", NeutralCriteria.CRITERIA_IN, inScopeEdOrgs)))); } Iterable<Entity> appQuery = repo.findAll("application", new NeutralQuery()); Map<String, Entity> allApps = new HashMap<String, Entity>(); for (Entity ent : appQuery) { if(!isAutoAuthorizedApp(ent)) { allApps.put(ent.getEntityId(), ent); } } List<Map> results = new ArrayList<Map>(); for (EntityBody body : ents) { HashMap<String, Object> entity = new HashMap<String, Object>(); String appId = (String) body.get("applicationId"); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) body.get("edorgs"); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", true); if(!isSEAAdmin()) { entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } results.add(entity); allApps.remove(appId); } for (Map.Entry<String, Entity> entry : allApps.entrySet()) { Boolean autoApprove = (Boolean) entry.getValue().getBody().get("allowed_for_all_edorgs"); List<String> approvedEdorgs = (List<String>) entry.getValue().getBody().get("authorized_ed_orgs"); if ((autoApprove != null && autoApprove) || isSEAAdmin() || (approvedEdorgs != null && CollectionUtils.containsAny(approvedEdorgs, inScopeEdOrgs))) { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", entry.getKey()); entity.put("appId", entry.getKey()); entity.put("authorized", false); results.add(entity); } } return Response.status(Status.OK).entity(results).build(); }  @PostConstruct void init(); @GET @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) Response getAuthorization(@PathParam("appId") String appId, @QueryParam("edorg") String edorg); boolean isAutoAuthorizedApp(Entity appEntity); @PUT @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) Response updateAuthorization(@PathParam("appId") String appId, EntityBody auth); static List<Map<String, Object>> enrichAuthorizedEdOrgsList(List<String> edOrgIds); @GET @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) Response getAuthorizations(@QueryParam("edorg") String edorg); static final String RESOURCE_NAME; static final String APP_ID; static final String EDORG_IDS; }