@Override protected DeleteRequest createReferralRequest(final DeleteRequest request, final LdapURL url) { final DeleteRequest referralRequest = new DeleteRequest(); referralRequest.setControls(request.getControls()); referralRequest.setIntermediateResponseHandlers(request.getIntermediateResponseHandlers()); referralRequest.setReferralHandler( new DeleteReferralHandler(getReferralLimit(), getReferralDepth() + 1, getReferralConnectionFactory())); if (!url.getEntry().isDefaultBaseDn()) { referralRequest.setDn(url.getEntry().getBaseDn()); } else { referralRequest.setDn(request.getDn()); } return referralRequest; }
@Override public String toString() { return String.format( "[%s@%d::deleteDn=%s, controls=%s, referralHandler=%s, " + "intermediateResponseHandlers=%s]", getClass().getName(), hashCode(), deleteDn, Arrays.toString(getControls()), getReferralHandler(), Arrays.toString(getIntermediateResponseHandlers())); } }
/** * Executes a {@link DeleteOperation} on the supplied DN. * * @param dn to delete * * @return response for the delete operation * * @throws LdapException if the operation fails */ @Nonnull private Response<Void> delete(@Nonnull final String dn) throws LdapException { Connection conn = null; try { conn = connectionFactory.getConnection(); final DeleteOperation delete = new DeleteOperation(conn); return delete.execute(new DeleteRequest(dn)); } finally { conn.close(); } }
/** * Execute delete operation boolean. * * @param connectionFactory the connection factory * @param entry the entry * @return the boolean * @throws LdapException the ldap exception */ public static boolean executeDeleteOperation(final ConnectionFactory connectionFactory, final LdapEntry entry) throws LdapException { try (Connection connection = createConnection(connectionFactory)) { final DeleteOperation delete = new DeleteOperation(connection); final DeleteRequest request = new DeleteRequest(entry.getDn()); request.setReferralHandler(new DeleteReferralHandler()); final Response<Void> res = delete.execute(request); return res.getResultCode() == ResultCode.SUCCESS; } catch (final LdapException e) { LOGGER.error(e.getMessage(), e); } return false; } }
@Override public Response<Void> delete(final DeleteRequest request) throws LdapException { Response<Void> response = null; try { final DeleteRequestImpl dri = new DeleteRequestImpl(); if (request.getControls() != null) { dri.addAllControls(config.getControlProcessor().processRequestControls(request.getControls())); } dri.setName(new Dn(request.getDn())); final DeleteResponse dr = connection.delete(dri); throwOperationException(request, dr); response = createResponse(request, null, dr); } catch (LdapOperationException e) { processLdapOperationException(e); } catch (org.apache.directory.api.ldap.model.exception.LdapException e) { processLdapException(e); } return response; }
@Override public Response<Void> delete(final DeleteRequest request) throws LdapException { Response<Void> response = null; LdapContext ctx = null; try { try { ctx = initializeContext(request); ctx.destroySubcontext(new LdapName(request.getDn())); 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; }
/** * Creates a new delete request. * * @param dn to delete */ public DeleteRequest(final String dn) { setDn(dn); }
/** * Executes a {@link DeleteOperation} for the supplied entry. * * @param request merge request * @param entry to delete from the LDAP * * @return response of the delete operation * * @throws LdapException if an error occurs executing the deleting operation */ protected Response<Void> delete(final MergeRequest request, final LdapEntry entry) throws LdapException { Response<Void> response; final DeleteOperation delete = new DeleteOperation(getConnection()); response = delete.execute(new DeleteRequest(entry.getDn())); logger.info("delete entry {} for request {}", entry, request); return response; } }
@Override public Response<Void> delete(final DeleteRequest request) throws LdapException { Response<Void> response = null; LdapContext ctx = null; try { try { ctx = initializeContext(request); ctx.destroySubcontext(new LdapName(request.getDn())); 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; }
/** * Creates a new delete request. * * @param dn to delete */ public DeleteRequest(final String dn) { setDn(dn); }
@Override protected DeleteRequest createReferralRequest(final DeleteRequest request, final LdapURL url) { final DeleteRequest referralRequest = new DeleteRequest(); referralRequest.setControls(request.getControls()); referralRequest.setIntermediateResponseHandlers(request.getIntermediateResponseHandlers()); referralRequest.setReferralHandler( new DeleteReferralHandler(getReferralLimit(), getReferralDepth() + 1, getReferralConnectionFactory())); if (!url.getEntry().isDefaultBaseDn()) { referralRequest.setDn(url.getEntry().getBaseDn()); } else { referralRequest.setDn(request.getDn()); } return referralRequest; }
/** * Executes the ldap delete operation. * * @param cf connection factory. * @param entryDns to delete * * @return status code * * @throws Exception on any LDAP search error */ protected int delete(final ConnectionFactory cf, final String[] entryDns) throws Exception { final Connection conn = cf.getConnection(); conn.open(); for (String dn : entryDns) { final DeleteOperation op = new DeleteOperation(conn); op.execute(new DeleteRequest(dn)); System.out.println(String.format("Deleted entry: %s", dn)); } conn.close(); return 0; }
@Override public String toString() { return String.format( "[%s@%d::deleteDn=%s, controls=%s, referralHandler=%s, " + "intermediateResponseHandlers=%s]", getClass().getName(), hashCode(), deleteDn, Arrays.toString(getControls()), getReferralHandler(), Arrays.toString(getIntermediateResponseHandlers())); } }
@Override public Response<Void> delete(final DeleteRequest request) throws LdapException { Response<Void> response = null; LdapContext ctx = null; try { try { ctx = initializeContext(request); ctx.destroySubcontext(new LdapName(request.getDn())); 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; }
/** * Creates a new delete request. * * @param dn to delete */ public DeleteRequest(final String dn) { setDn(dn); }
@Override protected DeleteRequest createReferralRequest(final DeleteRequest request, final LdapURL url) { final DeleteRequest referralRequest = new DeleteRequest(); referralRequest.setControls(request.getControls()); referralRequest.setIntermediateResponseHandlers(request.getIntermediateResponseHandlers()); referralRequest.setReferralHandler( new DeleteReferralHandler(getReferralLimit(), getReferralDepth() + 1, getReferralConnectionFactory())); if (!url.getEntry().isDefaultBaseDn()) { referralRequest.setDn(url.getEntry().getBaseDn()); } else { referralRequest.setDn(request.getDn()); } return referralRequest; }
/** * Executes a {@link DeleteOperation} for the supplied entry. * * @param request merge request * @param entry to delete from the LDAP * * @return response of the delete operation * * @throws LdapException if an error occurs executing the deleting operation */ protected Response<Void> delete(final MergeRequest request, final LdapEntry entry) throws LdapException { final Response<Void> response; final DeleteOperation delete = new DeleteOperation(getConnection()); response = delete.execute(new DeleteRequest(entry.getDn())); logger.info("delete entry {} for request {}", entry, request); return response; } }
@Override public String toString() { return String.format( "[%s@%d::deleteDn=%s, controls=%s, referralHandler=%s, " + "intermediateResponseHandlers=%s]", getClass().getName(), hashCode(), deleteDn, Arrays.toString(getControls()), getReferralHandler(), Arrays.toString(getIntermediateResponseHandlers())); } }
/** * Executes the ldap delete operation. * * @param cf connection factory. * @param entryDns to delete * * @return status code * * @throws Exception on any LDAP search error */ protected int delete(final ConnectionFactory cf, final String[] entryDns) throws Exception { final Connection conn = cf.getConnection(); conn.open(); for (String dn : entryDns) { final DeleteOperation op = new DeleteOperation(conn); op.execute(new DeleteRequest(dn)); System.out.println(String.format("Deleted entry: %s", dn)); } conn.close(); return 0; }
/** * Executes a {@link DeleteOperation} for the supplied entry. * * @param request merge request * @param entry to delete from the LDAP * * @return response of the delete operation * * @throws LdapException if an error occurs executing the deleting operation */ protected Response<Void> delete(final MergeRequest request, final LdapEntry entry) throws LdapException { final Response<Void> response; final DeleteOperation delete = new DeleteOperation(getConnection()); response = delete.execute(new DeleteRequest(entry.getDn())); logger.info("delete entry {} for request {}", entry, request); return response; } }