Beispiel #1
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);
    }
  }