Esempio n. 1
0
  /**
   * Gets all trust bundles in the system.
   *
   * @param fetchAnchors Indicates if the retrieval should also include the trust anchors in the
   *     bundle. When only needing bundle names, this parameter should be set to false for better
   *     performance.
   * @return A JSON representation of a collection of all trust bundles in the system. Returns a
   *     status of 204 if no trust bundles exist.
   */
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response getTrustBundles(
      @QueryParam("fetchAnchors") @DefaultValue("true") boolean fetchAnchors) {

    Collection<org.nhindirect.config.store.TrustBundle> retBundles = null;

    try {
      retBundles = bundleDao.getTrustBundles();

      if (retBundles.isEmpty()) return Response.noContent().cacheControl(noCache).build();

    } catch (Throwable e) {
      log.error("Error looking up trust bundles", e);
      return Response.serverError().cacheControl(noCache).build();
    }

    final Collection<TrustBundle> modelBundles = new ArrayList<TrustBundle>();
    for (org.nhindirect.config.store.TrustBundle bundle : retBundles) {
      if (!fetchAnchors) bundle.setTrustBundleAnchors(new ArrayList<TrustBundleAnchor>());

      modelBundles.add(EntityModelConversion.toModelTrustBundle(bundle));
    }

    final GenericEntity<Collection<TrustBundle>> entity =
        new GenericEntity<Collection<TrustBundle>>(modelBundles) {};

    return Response.ok(entity).cacheControl(noCache).build();
  }
Esempio n. 2
0
  /**
   * Gets all trust bundles associated to a domain.
   *
   * @param domainName The name of the domain to fetch trust bundles for.
   * @param fetchAnchors Indicates if the retrieval should also include the trust anchors in the
   *     bundle. When only needing bundle names, this parameter should be set to false for better
   *     performance.
   * @return A JSON representation of a collection of trust bundle that are associated to the given
   *     domain. Returns a status of 404 if a domain with the given name does not exist or a status
   *     of 404 if no trust bundles are associated with the given name.
   */
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("domains/{domainName}")
  public Response getTrustBundlesByDomain(
      @PathParam("domainName") String domainName,
      @QueryParam("fetchAnchors") @DefaultValue("true") boolean fetchAnchors) {

    // make sure the domain exists
    org.nhindirect.config.store.Domain entityDomain;
    try {
      entityDomain = domainDao.getDomainByName(domainName);
      if (entityDomain == null)
        return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();

    } catch (Exception e) {
      log.error("Error looking up domain.", e);
      return Response.serverError().cacheControl(noCache).build();
    }

    Collection<org.nhindirect.config.store.TrustBundleDomainReltn> retBundles = null;

    try {
      retBundles = bundleDao.getTrustBundlesByDomain(entityDomain.getId());

      if (retBundles.isEmpty()) return Response.noContent().cacheControl(noCache).build();

    } catch (Throwable e) {
      log.error("Error looking up trust bundles", e);
      return Response.serverError().cacheControl(noCache).build();
    }

    final Collection<TrustBundleDomainReltn> modelBundles = new ArrayList<TrustBundleDomainReltn>();
    for (org.nhindirect.config.store.TrustBundleDomainReltn bundleReltn : retBundles) {
      if (!fetchAnchors)
        bundleReltn.getTrustBundle().setTrustBundleAnchors(new ArrayList<TrustBundleAnchor>());

      final TrustBundleDomainReltn newReltn = new TrustBundleDomainReltn();
      newReltn.setIncoming(bundleReltn.isIncoming());
      newReltn.setOutgoing(bundleReltn.isOutgoing());
      newReltn.setDomain(EntityModelConversion.toModelDomain(bundleReltn.getDomain()));
      newReltn.setTrustBundle(
          EntityModelConversion.toModelTrustBundle(bundleReltn.getTrustBundle()));

      modelBundles.add(newReltn);
    }

    final GenericEntity<Collection<TrustBundleDomainReltn>> entity =
        new GenericEntity<Collection<TrustBundleDomainReltn>>(modelBundles) {};

    return Response.ok(entity).cacheControl(noCache).build();
  }
Esempio n. 3
0
  /**
   * Gets a trust bundle by name.
   *
   * @param bundleName The name of the trust bundle to retrieve.
   * @return A JSON representation of a the trust bundle. Returns a status of 404 if a trust bundle
   *     with the given name does not exist.
   */
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("{bundleName}")
  public Response getTrustBundleByName(@PathParam("bundleName") String bundleName) {
    try {
      final org.nhindirect.config.store.TrustBundle retBundle =
          bundleDao.getTrustBundleByName(bundleName);

      if (retBundle == null) return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();

      final TrustBundle modelBundle = EntityModelConversion.toModelTrustBundle(retBundle);

      return Response.ok(modelBundle).cacheControl(noCache).build();

    } catch (Throwable e) {
      log.error("Error looking up trust bundles", e);
      return Response.serverError().cacheControl(noCache).build();
    }
  }