/** {@inheritDoc} */
  @Override
  public Collection<X509Certificate> getAllCertificates() {
    // get everything from the configuration service.... no caching here
    Collection<org.nhindirect.config.model.Certificate> certificates;
    try {
      certificates = certService.getAllCertificates();
    } catch (Exception e) {
      throw new NHINDException("WebService error getting all certificates: " + e.getMessage(), e);
    }

    // purge everything
    this.flush(true);

    if (certificates == null || certificates.isEmpty()) return Collections.emptyList();

    // convert to X509Certificates and store
    Collection<X509Certificate> retVal = new ArrayList<X509Certificate>();
    for (org.nhindirect.config.model.Certificate cert : certificates) {
      X509Certificate storeCert = certFromData(cert.getData());
      retVal.add(storeCert);

      // add to JCS and cache
      try {
        if (cache != null) cache.put(cert.getOwner(), retVal);
      } catch (CacheException e) {
        /*
         * TODO: handle exception
         */
      }
    }

    return retVal;
  }
  private Collection<X509Certificate> lookupFromConfigStore(String subjectName) {
    String domain;

    Collection<org.nhindirect.config.model.Certificate> certificates;
    try {
      certificates = certService.getCertificatesByOwner(subjectName);
    } catch (Exception e) {
      throw new NHINDException(
          "WebService error getting certificates by subject: " + e.getMessage(), e);
    }

    if (certificates == null || certificates.isEmpty()) {
      // try again with the domain name
      int index;
      if ((index = subjectName.indexOf("@")) > -1) domain = subjectName.substring(index + 1);
      else domain = subjectName;

      try {
        certificates = certService.getCertificatesByOwner(domain);
      } catch (Exception e) {
        throw new NHINDException(
            "WebService error getting certificates by domain: " + e.getMessage(), e);
      }
    }

    if (certificates == null || certificates.isEmpty()) return Collections.emptyList();

    Collection<X509Certificate> retVal = new ArrayList<X509Certificate>();
    for (org.nhindirect.config.model.Certificate cert : certificates) {
      X509Certificate storeCert = certFromData(cert.getData());
      retVal.add(storeCert);
    }

    // add to JCS and cache
    try {
      if (cache != null) cache.put(subjectName, retVal);
    } catch (CacheException e) {
      /*
       * TODO: handle exception
       */
    }

    return retVal;
  }