String oldUserName = "CN=Albert Einstein,OU=Research,DC=antipodes,DC=com"; String newUserName = "CN=Albert Einstein,OU=Sales,DC=antipodes,DC=com"; // Create the initial directory context LdapContext ctx = new InitialLdapContext(env,null); // Move the user ctx.rename(oldUserName,newUserName);
/** * * @param oldDn * @param newDn * @throws LDAPException * @see org.mule.module.ldap.api.LDAPConnection#renameEntry(java.lang.String, java.lang.String) */ public void renameEntry(String oldDn, String newDn) throws LDAPException { try { if(logger.isDebugEnabled()) { logger.debug("About to rename entry " + oldDn + " to " + newDn); } getConn().rename(oldDn, newDn); if(logger.isInfoEnabled()) { logger.info("Renamed entry " + oldDn + " to " + newDn); } } catch (NamingException nex) { throw handleNamingException(nex, "Rename entry failed."); } }
/** * LDAP modify DN operation. * * @param dn Distinguished name of the entry. * @param newRDN new realtive distinguished name of the entry. * @param deleteOldRDN if old relative distinguished name should be deleted * @param newSuperior new superior DN * @throws NamingException if DN can not be resolved */ public void modifyDn(final String dn, final String newRDN, final boolean deleteOldRDN, final String newSuperior) throws NamingException { WithContext<Object> action = ctx -> { LdapName source = new LdapName(dn); LdapName target = new LdapName(newSuperior); target.add(newRDN); ctx.addToEnvironment("java.naming.ldap.deleteRDN", Boolean.toString(deleteOldRDN)); ctx.rename(source, target); return null; }; performWithContext(action); }
ctx.rename( new LdapName(rewriteBase(jm.getDistinguishName())), new LdapName(rewriteBase(jm.getNewDistinguishName())));
@Override public Response<Void> modifyDn(final ModifyDnRequest request) throws LdapException { Response<Void> response = null; LdapContext ctx = null; try { try { ctx = initializeContext(request); ctx.addToEnvironment("java.naming.ldap.deleteRDN", Boolean.valueOf(request.getDeleteOldRDn()).toString()); ctx.rename(new LdapName(request.getDn()), new LdapName(request.getNewDn())); response = createResponse(request, null, ResultCode.SUCCESS, null, ctx); } finally { if (ctx != null) { ctx.close(); } } } catch (ReferralException e) { final String[] refUrls = e.getReferralInfo() != null ? new String[] {(String) e.getReferralInfo()} : null; response = createResponse(request, null, ResultCode.REFERRAL, refUrls, ctx); } catch (NamingException e) { processNamingException(request, e, null, ctx); } return response; }
@Override public Response<Void> modifyDn(final ModifyDnRequest request) throws LdapException { Response<Void> response = null; LdapContext ctx = null; try { try { ctx = initializeContext(request); ctx.addToEnvironment("java.naming.ldap.deleteRDN", Boolean.valueOf(request.getDeleteOldRDn()).toString()); ctx.rename(new LdapName(request.getDn()), new LdapName(request.getNewDn())); response = createResponse(request, null, ResultCode.SUCCESS, null, ctx); } finally { if (ctx != null) { ctx.close(); } } } catch (ReferralException e) { final String[] refUrls = e.getReferralInfo() != null ? new String[] {(String) e.getReferralInfo()} : null; response = createResponse(request, null, ResultCode.REFERRAL, refUrls, ctx); } catch (NamingException e) { processNamingException(request, e, null, ctx); } return response; }
@Override public Response<Void> modifyDn(final ModifyDnRequest request) throws LdapException { Response<Void> response = null; LdapContext ctx = null; try { try { ctx = initializeContext(request); ctx.addToEnvironment("java.naming.ldap.deleteRDN", Boolean.valueOf(request.getDeleteOldRDn()).toString()); ctx.rename(new LdapName(request.getDn()), new LdapName(request.getNewDn())); response = createResponse(request, null, ResultCode.SUCCESS, null, ctx); } finally { if (ctx != null) { ctx.close(); } } } catch (ReferralException e) { final String[] refUrls = e.getReferralInfo() != null ? new String[] {(String) e.getReferralInfo()} : null; response = createResponse(request, null, ResultCode.REFERRAL, refUrls, ctx); } catch (NamingException e) { processNamingException(request, e, null, ctx); } return response; }
modCtx.rename( getSaveJndiName( oldDn ), getSaveJndiName( newDn ) );