Java Code Examples for javax.naming.directory.DirContext#destroySubcontext()

The following examples show how to use javax.naming.directory.DirContext#destroySubcontext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ldapConnection.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * deletes the entry with the set DN.
 */

public void delete() throws NamingException{
  //Get a reference to a directory context
  DirContext ctx = new InitialDirContext(env);
  ctx.destroySubcontext(dn);
  ctx.close();
}
 
Example 2
Source File: LdifScript.java    From scriptella-etl with Apache License 2.0 5 votes vote down vote up
/**
 * Adds/modifies ctx using entry information.
 *
 * @param ctx directory context to use for change.
 * @param e   entry with change description.
 * @throws NamingException if operation with directory failed.
 */
static void modify(DirContext ctx, final Entry e) throws NamingException {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Processing " + e);
    }
    Attributes atts = e.getAttributes();
    final String rootDn = ctx.getNameInNamespace();
    if (atts != null) { //If add entry
        ctx.createSubcontext(getRelativeDN(rootDn, e.getDn()), e.getAttributes());
    } else if (e.isChangeDelete()) {
        ctx.destroySubcontext(getRelativeDN(rootDn, e.getDn()));
    } else if (e.isChangeModDn() || e.isChangeModRdn()) {
        Name newRdn;
        if (e.getNewSuperior() != null) { //If new superior
            newRdn = getRelativeDN(rootDn, e.getNewSuperior());
        } else { //otherwise use DN as a base
            newRdn = getRelativeDN(rootDn, e.getDn());
            newRdn.remove(newRdn.size() - 1);
        }
        newRdn.add(e.getNewRdn());
        ctx.addToEnvironment("java.naming.ldap.deleteRDN", String.valueOf(e.isDeleteOldRdn()));
        ctx.rename(getRelativeDN(rootDn, e.getDn()), newRdn);
        ctx.removeFromEnvironment("java.naming.ldap.deleteRDN");//a better solution to use the previous value

    } else {
        List<ModificationItem> items = e.getModificationItems();
        ctx.modifyAttributes(getRelativeDN(rootDn, e.getDn()),
                items.toArray(new ModificationItem[items.size()]));
    }
}
 
Example 3
Source File: LdapUtil.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
 * 删除
 * 
 * @param dn
 */
public static void delete(String dn, DirContext dc) {
	try {
		dc.destroySubcontext(dn);
	} catch (Exception e) {
		LogUtil.error("Exception in delete():" + e);
	}
}