@Test public void testGetAuthForExistingAppAndExistingAuth2() { 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("someOtherEdorg")); repo.create("applicationAuthorization", auth); ResponseImpl resp = (ResponseImpl) res.getAuthorization(app.getEntityId(), null); Assert.assertEquals(200, resp.getStatus()); Map ent = (Map) resp.getEntity(); Assert.assertFalse((Boolean) ent.get("authorized")); }
@GET @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorization(@PathParam("appId") String appId, @QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); EntityBody appAuth = getAppAuth(appId); if (appAuth == null) { Entity appEntity = repo.findOne("application", new NeutralQuery(new NeutralCriteria("_id", "=", appId))); if (appEntity == null || isAutoAuthorizedApp(appEntity)) { return Response.status(Status.NOT_FOUND).build(); } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", false); entity.put("edorgs", Collections.emptyList()); return Response.status(Status.OK).entity(entity).build(); } } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("appId", appId); entity.put("id", appId); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) appAuth.get("edorgs"); Map<String,Object> authorizingInfo = getAuthorizingInfo(edOrgs, myEdorgs); entity.put("authorized", ( authorizingInfo == null)?false:true); if(!isSEAAdmin()) { Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } return Response.status(Status.OK).entity(entity).build(); } }
ApplicationAuthorizationResource { @GET @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorization(@PathParam("appId") String appId, @QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); EntityBody appAuth = getAppAuth(appId); if (appAuth == null) { Entity appEntity = repo.findOne("application", new NeutralQuery(new NeutralCriteria("_id", "=", appId))); if (appEntity == null || isAutoAuthorizedApp(appEntity)) { return Response.status(Status.NOT_FOUND).build(); } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", false); entity.put("edorgs", Collections.emptyList()); return Response.status(Status.OK).entity(entity).build(); } } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("appId", appId); entity.put("id", appId); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) appAuth.get("edorgs"); Map<String,Object> authorizingInfo = getAuthorizingInfo(edOrgs, myEdorgs); entity.put("authorized", ( authorizingInfo == null)?false:true); if(!isSEAAdmin()) { Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } return Response.status(Status.OK).entity(entity).build(); } } }
ApplicationAuthorizationResource { @GET @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorization(@PathParam("appId") String appId, @QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); EntityBody appAuth = getAppAuth(appId); if (appAuth == null) { Entity appEntity = repo.findOne("application", new NeutralQuery(new NeutralCriteria("_id", "=", appId))); if (appEntity == null || isAutoAuthorizedApp(appEntity)) { return Response.status(Status.NOT_FOUND).build(); } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", false); entity.put("edorgs", Collections.emptyList()); return Response.status(Status.OK).entity(entity).build(); } } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("appId", appId); entity.put("id", appId); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) appAuth.get("edorgs"); Map<String,Object> authorizingInfo = getAuthorizingInfo(edOrgs, myEdorgs); entity.put("authorized", ( authorizingInfo == null)?false:true); if(!isSEAAdmin()) { Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } return Response.status(Status.OK).entity(entity).build(); } }  }
ApplicationAuthorizationResource { @GET @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorization(@PathParam("appId") String appId, @QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); EntityBody appAuth = getAppAuth(appId); if (appAuth == null) { Entity appEntity = repo.findOne("application", new NeutralQuery(new NeutralCriteria("_id", "=", appId))); if (appEntity == null || isAutoAuthorizedApp(appEntity)) { return Response.status(Status.NOT_FOUND).build(); } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", false); entity.put("edorgs", Collections.emptyList()); return Response.status(Status.OK).entity(entity).build(); } } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("appId", appId); entity.put("id", appId); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) appAuth.get("edorgs"); Map<String,Object> authorizingInfo = getAuthorizingInfo(edOrgs, myEdorgs); entity.put("authorized", ( authorizingInfo == null)?false:true); if(!isSEAAdmin()) { Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } return Response.status(Status.OK).entity(entity).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 @Path("{appId}") @RightsAllowed({Right.EDORG_APP_AUTHZ, Right.APP_AUTHORIZE}) public Response getAuthorization(@PathParam("appId") String appId, @QueryParam("edorg") String edorg) { Set<String> myEdorgs = validateEdOrg(edorg); EntityBody appAuth = getAppAuth(appId); if (appAuth == null) { Entity appEntity = repo.findOne("application", new NeutralQuery(new NeutralCriteria("_id", "=", appId))); if (appEntity == null || isAutoAuthorizedApp(appEntity)) { return Response.status(Status.NOT_FOUND).build(); } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("id", appId); entity.put("appId", appId); entity.put("authorized", false); entity.put("edorgs", Collections.emptyList()); return Response.status(Status.OK).entity(entity).build(); } } else { HashMap<String, Object> entity = new HashMap<String, Object>(); entity.put("appId", appId); entity.put("id", appId); List<Map<String,Object>> edOrgs = (List<Map<String,Object>>) appAuth.get("edorgs"); Map<String,Object> authorizingInfo = getAuthorizingInfo(edOrgs, myEdorgs); entity.put("authorized", ( authorizingInfo == null)?false:true); if(!isSEAAdmin()) { Set<String> inScopeEdOrgs = getChildEdorgs(myEdorgs); entity.put("edorgs", filter(edOrgs, inScopeEdOrgs)); } else { entity.put("edorgs", edOrgs); } return Response.status(Status.OK).entity(entity).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; }