예제 #1
0
  /**
   * Add the new entry to the directory.
   *
   * @param newEntry the new entry containing the replacement set of attributes.
   * @return the operation's success status
   */
  public boolean addEntry(DXEntry newEntry) {
    if (newEntry == null) {
      CBUtility.log("Internal Error: null Entry passed to DXOps addEntry");
      return false;
    } else if (newEntry.getDN() == null) {
      CBUtility.log("Internal Error: Entry with null DN passed to DXOps addEntry");
      return false;
    }

    return addObject(newEntry.getDN(), newEntry);
  }
예제 #2
0
  /**
   * Update an entry with the designated DN.
   *
   * @param oldEntry the old entry containing the old set of attributes.
   * @param newEntry the new entry containing the replacement set of attributes.
   * @return the operation's success status.
   */
  public boolean modifyEntry(DXEntry oldEntry, DXEntry newEntry) {
    if (oldEntry == null && newEntry == null) return true; // nothing to do.

    if (oldEntry != null) oldEntry.removeEmptyAttributes();
    if (newEntry != null) newEntry.removeEmptyAttributes();

    if (oldEntry == null || (newEntry != null) && (newEntry.getStatus() == DXEntry.NEW)) // add
    {
      return addEntryToDirectory(newEntry);
    } else if (newEntry == null) // delete
    {
      deleteTree(oldEntry.getDN());
      return true;
    }

    // sanity check

    if (oldEntry.getDN() == null || newEntry.getDN() == null) {
      CBUtility.log(
          "Internal Error: Entry with null DN passed to JNDIBroker unthreadedModify!  Modify Request Cancelled!");
      return false;
    }

    // see if the name has changed, and modify it if it has
    if (handleAnyNameChange(oldEntry, newEntry) == false) return false;

    // check for change of attributes done in modify()
    return updateEntry(oldEntry, newEntry);
  }
예제 #3
0
  /**
   * Update an entry with the designated DN.
   *
   * @param oldSet the old entry containing teh old set of attributes.
   * @param newSet the new entry containing the replacement set of attributes.
   * @return the operation's success status.
   */
  public boolean updateEntry(DXEntry oldSet, DXEntry newSet) {

    try {
      if (DXAttributes.attributesEqual(oldSet, newSet)) return true; // nothing to do.

      DN nodeDN = newSet.getDN();
      RDN newRDN = nodeDN.getLowestRDN();

      DXAttributes adds =
          null; // use modify-add for new attribute values (inc entirely new attribute)
      DXAttributes reps = null; // use modify-replace for changed attribute values
      DXAttributes dels =
          null; // use modify-delete for deleted attribute values (inc deleting entire attribute)

      reps = DXAttributes.getReplacementSet(newRDN, oldSet, newSet);
      dels = DXAttributes.getDeletionSet(newRDN, oldSet, newSet);
      adds = DXAttributes.getAdditionSet(newRDN, oldSet, newSet);

      /*if (false)
      printDebug(oldSet, newSet, adds, reps, dels);*/

      CBUtility.log("updateNode: ", 4);

      ModificationItem[] mods;

      mods = new ModificationItem[dels.size() + reps.size() + adds.size()];

      int modIndex = 0;
      modIndex = loadMods(mods, dels.getAll(), DirContext.REMOVE_ATTRIBUTE, modIndex);
      modIndex = loadMods(mods, adds.getAll(), DirContext.ADD_ATTRIBUTE, modIndex);
      modIndex = loadMods(mods, reps.getAll(), DirContext.REPLACE_ATTRIBUTE, modIndex);

      return modifyAttributes(nodeDN, mods); // TE: This may fail, returning false.
    } catch (NamingException e) {
      error("Unable to update node " + oldSet.getDN() + "! " + e.toString(), e);
      e.printStackTrace();
      return false;
    } catch (Exception e) {
      error("Unexpected Error updating node " + oldSet.getDN() + "! " + e.toString(), e);
      e.printStackTrace();
      return false;
    }
  }
예제 #4
0
  /**
   * This postparses a namingEnumeration of NameClassPairs, after it has been returned from the jndi
   * operation. Usefull to over-ride if the names in the enumeration need to be unescaped or
   * reformatted.
   *
   * @param e the post jndi operation namingEnumeration.
   * @param base the 'base' dn from which the names in the enumeration (may) be relative. If the
   *     Names in the enumeration are suffixed by the searchBase, they are unaltered, otherwise the
   *     searchBase is added to the names to give the full DN in the namespace.
   * @return the re-formatted version used by the application.
   */
  public NamingEnumeration postParseNameClassPairs(NamingEnumeration e, Name base)
      throws NamingException {
    log.log(Level.FINER, "parsing with base :" + base.toString());
    DXNamingEnumeration dxe = new DXNamingEnumeration();

    String baseString = null;

    if (base != null && base.isEmpty() == false) baseString = base.toString();

    try {
      while (e.hasMore()) {
        NameClassPair ncp = (NameClassPair) e.next();

        String rawName = postParseString(ncp.getName()).toString();

        // IMPORTANT!
        // This appends the 'base' DN to the enumerated DNs in order to get absolute DNs...

        if (ncp.isRelative() && baseString != null) {
          if (rawName.length() != 0) rawName = rawName + "," + baseString;
          else rawName = baseString;
        }

        log.log(Level.FINER, "ended up with: '" + rawName + "'");
        ncp.setName(rawName);
        dxe.add(ncp);
      }
    } catch (NamingException ex) {
      CBUtility.error(
          CBIntText.get("Search partially failed! - only ")
              + dxe.size()
              + CBIntText.get(" entries returned."),
          ex);
    }

    return dxe;
  }