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

The following examples show how to use javax.naming.directory.DirContext#unbind() . 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: LdapUtil.java    From herd-mdl with Apache License 2.0 5 votes vote down vote up
/**
 * delete ldap AD group with provided group name
 *
 * @param groupName ldap AD group name to delete
 * @throws NamingException
 */
public static void deleteAdGroup(String groupName) throws NamingException {
    LOGGER.info(String.format("Remove AD group: %s", groupName));
    DirContext ldapContext = getLdapContext(User.getLdapAdminUser());
    String groupDn = constructGroupDn(groupName, OU_GROUPS);
    ldapContext.unbind(groupDn);
}
 
Example 2
Source File: LdapUtil.java    From herd-mdl with Apache License 2.0 5 votes vote down vote up
/**
 * Delete ldap user from ldap entry
 *
 * @param userId ldap user id
 * @throws NamingException
 */
private static void deleteEntry(String userId, String ou) throws NamingException {
    LOGGER.info(String.format("Delete user: %s", userId));
    String entryDN = constructEntryCn(userId, ou);
    DirContext ldapContext = getLdapContext(User.getLdapAdminUser());
    ldapContext.unbind(entryDN);
}
 
Example 3
Source File: AbstractCachedLDAPAuthorizationMapLegacyTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public static void cleanAndLoad(String deleteFromDn,
                                String ldifResourcePath,
                                String ldapHost,
                                int ldapPort,
                                String ldapUser,
                                String ldapPass,
                                DirContext context) throws Exception {
   // Cleanup everything used for testing.
   List<String> dns = new LinkedList<>();
   dns.add(deleteFromDn);

   while (!dns.isEmpty()) {
      String name = dns.get(dns.size() - 1);
      Context currentContext = (Context) context.lookup(name);
      NamingEnumeration<NameClassPair> namingEnum = currentContext.list("");

      if (namingEnum.hasMore()) {
         while (namingEnum.hasMore()) {
            dns.add(namingEnum.next().getNameInNamespace());
         }
      } else {
         context.unbind(name);
         dns.remove(dns.size() - 1);
      }
   }

   // A bit of a hacked approach to loading an LDIF into OpenLDAP since there isn't an easy way to do it
   // otherwise.  This approach invokes the command line tool programmatically but has
   // to short-circuit the call to System.exit that the command line tool makes when it finishes.
   // We are assuming that there isn't already a security manager in place.
   final SecurityManager securityManager = new SecurityManager() {

      @Override
      public void checkPermission(java.security.Permission permission) {
         if (permission.getName().contains("exitVM")) {
            throw new SecurityException("System.exit calls disabled for the moment.");
         }
      }
   };

   System.setSecurityManager(securityManager);

   File file = new File(AbstractCachedLDAPAuthorizationMapLegacyTest.class.getClassLoader().getResource(ldifResourcePath).toURI());

   Class<?> clazz = Class.forName("LDAPModify");
   Method mainMethod = clazz.getMethod("main", String[].class);

   try {
      mainMethod.invoke(null, new Object[]{new String[]{"-v", "-h", ldapHost, "-p", String.valueOf(ldapPort), "-D", ldapUser, "-w", ldapPass, "-a", "-f", file.toString()}});
   } catch (InvocationTargetException e) {
      if (!(e.getTargetException() instanceof SecurityException)) {
         throw e;
      }
   }

   System.setSecurityManager(null);
}
 
Example 4
Source File: LdapDao.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
public void delete(final DirContext ctx, final T obj) throws NamingException
{
  final String dn = buildDn(null, obj);
  log.info("Delete " + getObjectClass() + ": " + dn + ": " + getLogInfo(obj));
  ctx.unbind(dn);
}