예제 #1
0
 /**
  * Modifies index using the provided connection.
  *
  * @param ctx the connection to be used to update the index configuration.
  * @throws OpenDsException if there is an error updating the server.
  */
 private void modifyIndexOnline(final InitialLdapContext ctx) throws OpenDsException {
   final ManagementContext mCtx =
       LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
   final BackendCfgClient backend = mCtx.getRootConfiguration().getBackend(backendName);
   if (backend instanceof LocalDBBackendCfgClient) {
     modifyLocalDBIndexOnline((LocalDBBackendCfgClient) backend);
     return;
   }
   modifyBackendIndexOnline((PluggableBackendCfgClient) backend);
 }
예제 #2
0
  /**
   * Creates the Administration Suffix.
   *
   * @param ctx the DirContext to be used.
   * @param backendName the name of the backend where the administration suffix is stored.
   * @throws ADSContextException if the administration suffix could not be created.
   */
  void createAdministrationSuffix(InitialLdapContext ctx, String backendName)
      throws ADSContextException {
    try {
      ManagementContext mCtx =
          LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
      RootCfgClient root = mCtx.getRootConfiguration();
      LDIFBackendCfgClient backend = null;
      try {
        backend = (LDIFBackendCfgClient) root.getBackend(backendName);
      } catch (ManagedObjectNotFoundException e) {
      } catch (ClassCastException cce) {
        throw new ADSContextException(ErrorType.UNEXPECTED_ADS_BACKEND_TYPE, cce);
      }

      if (backend == null) {
        LDIFBackendCfgDefn provider = LDIFBackendCfgDefn.getInstance();
        backend = root.createBackend(provider, backendName, null);
        backend.setEnabled(true);
        backend.setLDIFFile(ADSContext.getAdminLDIFFile());
        backend.setBackendId(backendName);
        backend.setWritabilityMode(BackendCfgDefn.WritabilityMode.ENABLED);
        backend.setIsPrivateBackend(true);
      }
      SortedSet<DN> suffixes = backend.getBaseDN();
      if (suffixes == null) {
        suffixes = new TreeSet<>();
      }
      DN newDN = DN.valueOf(ADSContext.getAdministrationSuffixDN());
      if (suffixes.add(newDN)) {
        backend.setBaseDN(suffixes);
        backend.commit();
      }
    } catch (Throwable t) {
      throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, t);
    }
  }