예제 #1
0
  private List<DN> findBaseDNs() throws IOException {
    final List<DN> baseDNs = new LinkedList<DN>();
    final SearchRequest request =
        Requests.newSearchRequest(
            "cn=backends,cn=config",
            SearchScope.WHOLE_SUBTREE,
            "(objectclass=ds-cfg-local-db-backend)",
            "ds-cfg-base-dn");
    FileInputStream is = null;
    LDIFEntryReader reader = null;

    try {
      is = new FileInputStream(installRoot + "/config/config.ldif");
      reader = new LDIFEntryReader(is);
      final EntryReader filteredReader = LDIF.search(reader, request);

      while (filteredReader.hasNext()) {
        final Entry entry = filteredReader.readEntry();
        final Attribute values = entry.getAttribute("ds-cfg-base-dn");

        if (values != null) {
          for (final ByteString value : values) {
            baseDNs.add(DN.valueOf(value.toString()));
          }
        }
      }
    } finally {
      closeIfNotNull(reader);
      closeIfNotNull(is);
    }

    return baseDNs;
  }
예제 #2
0
 /**
  * Retrieves the backends from the current configuration file. The backends must be enabled to be
  * listed. No operations should be done within a disabled backend.
  *
  * @return A backend list.
  */
 static List<String> getIndexedBackendsFromConfig() {
   final SearchRequest sr =
       Requests.newSearchRequest(
           "",
           SearchScope.WHOLE_SUBTREE,
           "(&(objectclass=ds-cfg-pluggable-backend)(ds-cfg-enabled=true))",
           "ds-cfg-base-dn");
   final List<String> listBackends = new LinkedList<>();
   try (final EntryReader entryReader = searchConfigFile(sr)) {
     while (entryReader.hasNext()) {
       final Entry entry = entryReader.readEntry();
       listBackends.addAll(entry.parseAttribute("ds-cfg-base-dn").asSetOfString());
     }
   } catch (Exception ex) {
     logger.error(LocalizableMessage.raw(ex.getMessage()));
   }
   return listBackends;
 }