Esempio n. 1
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. 2
0
  /**
   * Associates a trust bundle to a domain along with directional trust.
   *
   * @param bundleName The name of the bundle to associate to a domain.
   * @param domainName The name of the domain to associate to a bundle.
   * @param incoming Indicates if trust should be allowed for incoming messages.
   * @param outgoing Indicates if trust should be allowed for outgoing messages.
   * @return Status of 204 if the association was made or a status of 404 if either a domain or
   *     trust bundle with its given name does not exist.
   */
  @POST
  @Path("{bundle}/{domain}")
  public Response associateTrustBundleToDomain(
      @PathParam("bundle") String bundleName,
      @PathParam("domain") String domainName,
      @QueryParam("incoming") @DefaultValue("true") boolean incoming,
      @QueryParam("outgoing") @DefaultValue("true") boolean outgoing) {
    // make sure the bundle exists
    org.nhindirect.config.store.TrustBundle entityBundle;
    try {
      entityBundle = bundleDao.getTrustBundleByName(bundleName);
      if (entityBundle == null)
        return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error looking up bundle.", e);
      return Response.serverError().cacheControl(noCache).build();
    }

    // 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();
    }

    // now make the association
    try {
      bundleDao.associateTrustBundleToDomain(
          entityDomain.getId(), entityBundle.getId(), incoming, outgoing);
      return Response.noContent().cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error associating trust bundle to domain.", e);
      return Response.serverError().cacheControl(noCache).build();
    }
  }
Esempio n. 3
0
  /**
   * Removes all trust bundle from a domain.
   *
   * @param domainName The name of the domain to remove trust bundle from.
   * @return Status of 200 if trust bundles were removed from the domain or a status of 404 if a
   *     domain with the given name does not exist.
   */
  @DELETE
  @Path("{domain}/deleteFromDomain")
  public Response disassociateTrustBundlesFromDomain(@PathParam("domain") String domainName) {
    // 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();
    }

    // now make the disassociation
    try {
      bundleDao.disassociateTrustBundlesFromDomain(entityDomain.getId());
      return Response.ok().cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error disassociating trust bundles from domain.", e);
      return Response.serverError().cacheControl(noCache).build();
    }
  }