Search in sources :

Example 1 with UndeleteRequestControl

use of com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl in project ldapsdk by pingidentity.

the class LDAPModify method doAdd.

/**
 * Performs the appropriate processing for an LDIF add change record.
 *
 * @param  changeRecord         The LDIF add change record to process.
 * @param  controls             The set of controls to include in the request.
 * @param  pool                 The connection pool to use to communicate with
 *                              the directory server.
 * @param  multiUpdateRequests  The list to which the request should be added
 *                              if it is to be processed as part of a
 *                              multi-update operation.  It may be
 *                              {@code null} if the operation should not be
 *                              processed via the multi-update operation.
 * @param  rejectWriter         The LDIF writer to use for recording
 *                              information about rejected changes.  It may be
 *                              {@code null} if no reject writer is
 *                              configured.
 *
 * @return  The result code obtained from processing.
 *
 * @throws  LDAPException  If the operation did not complete successfully
 *                         and processing should not continue.
 */
@NotNull()
private ResultCode doAdd(@NotNull final LDIFAddChangeRecord changeRecord, @NotNull final List<Control> controls, @NotNull final LDAPConnectionPool pool, @Nullable final List<LDAPRequest> multiUpdateRequests, @Nullable final LDIFWriter rejectWriter) throws LDAPException {
    // Create the add request to process.
    final AddRequest addRequest = changeRecord.toAddRequest(true);
    for (final Control c : controls) {
        addRequest.addControl(c);
    }
    // control.
    if (allowUndelete.isPresent() && addRequest.hasAttribute(ATTR_UNDELETE_FROM_DN)) {
        addRequest.addControl(new UndeleteRequestControl());
    }
    // details request control if appropriate.
    if (passwordValidationDetails.isPresent()) {
        final Entry entryToAdd = addRequest.toEntry();
        if ((!entryToAdd.getAttributesWithOptions(ATTR_USER_PASSWORD, null).isEmpty()) || (!entryToAdd.getAttributesWithOptions(ATTR_AUTH_PASSWORD, null).isEmpty())) {
            addRequest.addControl(new PasswordValidationDetailsRequestControl());
        }
    }
    // just add the request to the list and return without doing anything else.
    if (multiUpdateErrorBehavior.isPresent()) {
        multiUpdateRequests.add(addRequest);
        commentToOut(INFO_LDAPMODIFY_ADD_ADDED_TO_MULTI_UPDATE.get(addRequest.getDN()));
        return ResultCode.SUCCESS;
    }
    // If the --dryRun argument was provided, then we'll stop here.
    if (dryRun.isPresent()) {
        commentToOut(INFO_LDAPMODIFY_DRY_RUN_ADD.get(addRequest.getDN(), dryRun.getIdentifierString()));
        return ResultCode.SUCCESS;
    }
    // Process the add operation and get the result.
    commentToOut(INFO_LDAPMODIFY_ADDING_ENTRY.get(addRequest.getDN()));
    if (verbose.isPresent()) {
        for (final String ldifLine : addRequest.toLDIFChangeRecord().toLDIF(WRAP_COLUMN)) {
            out(ldifLine);
        }
        out();
    }
    LDAPResult addResult;
    try {
        addResult = pool.add(addRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        addResult = le.toLDAPResult();
    }
    // Display information about the result.
    displayResult(addResult, useTransaction.isPresent());
    // should end all processing, then throw an exception.
    switch(addResult.getResultCode().intValue()) {
        case ResultCode.SUCCESS_INT_VALUE:
        case ResultCode.NO_OPERATION_INT_VALUE:
            break;
        case ResultCode.ASSERTION_FAILED_INT_VALUE:
            writeRejectedChange(rejectWriter, INFO_LDAPMODIFY_ASSERTION_FAILED.get(addRequest.getDN(), String.valueOf(assertionFilter.getValue())), addRequest.toLDIFChangeRecord(), addResult);
            throw new LDAPException(addResult);
        default:
            writeRejectedChange(rejectWriter, null, addRequest.toLDIFChangeRecord(), addResult);
            if (useTransaction.isPresent() || (!continueOnError.isPresent())) {
                throw new LDAPException(addResult);
            }
            break;
    }
    return addResult.getResultCode();
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) RouteToServerRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.RouteToServerRequestControl) SubtreeDeleteRequestControl(com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl) SimplePagedResultsControl(com.unboundid.ldap.sdk.controls.SimplePagedResultsControl) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) AssuredReplicationRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.AssuredReplicationRequestControl) PostReadRequestControl(com.unboundid.ldap.sdk.controls.PostReadRequestControl) SuppressOperationalAttributeUpdateRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.SuppressOperationalAttributeUpdateRequestControl) NameWithEntryUUIDRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.NameWithEntryUUIDRequestControl) ReplicationRepairRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.ReplicationRepairRequestControl) ProxiedAuthorizationV1RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV1RequestControl) OperationPurposeRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl) PasswordUpdateBehaviorRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.PasswordUpdateBehaviorRequestControl) UndeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl) GetRecentLoginHistoryRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.GetRecentLoginHistoryRequestControl) PermissiveModifyRequestControl(com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) GetUserResourceLimitsRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.GetUserResourceLimitsRequestControl) HardDeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.HardDeleteRequestControl) IgnoreNoUserModificationRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.IgnoreNoUserModificationRequestControl) GetBackendSetIDRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.GetBackendSetIDRequestControl) GetAuthorizationEntryRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.GetAuthorizationEntryRequestControl) PurgePasswordRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.PurgePasswordRequestControl) ProxiedAuthorizationV2RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl) SoftDeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.SoftDeleteRequestControl) RetirePasswordRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.RetirePasswordRequestControl) GetServerIDRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.GetServerIDRequestControl) NoOpRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.NoOpRequestControl) PasswordPolicyRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.PasswordPolicyRequestControl) SuppressReferentialIntegrityUpdatesRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.SuppressReferentialIntegrityUpdatesRequestControl) AssertionRequestControl(com.unboundid.ldap.sdk.controls.AssertionRequestControl) RouteToBackendSetRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.RouteToBackendSetRequestControl) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) PasswordValidationDetailsRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.PasswordValidationDetailsRequestControl) UniquenessRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.UniquenessRequestControl) GeneratePasswordRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.GeneratePasswordRequestControl) PreReadRequestControl(com.unboundid.ldap.sdk.controls.PreReadRequestControl) Entry(com.unboundid.ldap.sdk.Entry) LDAPException(com.unboundid.ldap.sdk.LDAPException) UndeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) PasswordValidationDetailsRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.PasswordValidationDetailsRequestControl) NotNull(com.unboundid.util.NotNull)

Example 2 with UndeleteRequestControl

use of com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl in project ldapsdk by pingidentity.

the class ParallelUpdateOperationThread method run.

/**
 * Operates in a loop, retrieving changes from the operation queue and
 * processing them.
 */
@Override()
public void run() {
    LDIFChangeRecord r = opQueue.getChangeRecord();
    // Various controls that might be present on the requests.
    final Control undeleteRequestControl = new UndeleteRequestControl();
    while (r != null) {
        if (rateLimiter != null) {
            rateLimiter.await();
        }
        DN parsedDN = null;
        DN parsedNewDN = null;
        final long startTime = System.currentTimeMillis();
        try {
            parsedDN = r.getParsedDN();
            if (r instanceof LDIFAddChangeRecord) {
                final AddRequest addRequest = ((LDIFAddChangeRecord) r).toAddRequest();
                addRequest.addControls(addControls);
                if (allowUndelete && addRequest.hasAttribute(ATTR_UNDELETE_FROM_DN)) {
                    addRequest.addControl(undeleteRequestControl);
                }
                connectionPool.add(addRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else if (r instanceof LDIFDeleteChangeRecord) {
                final DeleteRequest deleteRequest = ((LDIFDeleteChangeRecord) r).toDeleteRequest();
                deleteRequest.addControls(deleteControls);
                connectionPool.delete(deleteRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else if (r instanceof LDIFModifyChangeRecord) {
                final ModifyRequest modifyRequest = ((LDIFModifyChangeRecord) r).toModifyRequest();
                modifyRequest.addControls(modifyControls);
                connectionPool.modify(modifyRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else if (r instanceof LDIFModifyDNChangeRecord) {
                final LDIFModifyDNChangeRecord modifyDNChangeRecord = (LDIFModifyDNChangeRecord) r;
                parsedNewDN = modifyDNChangeRecord.getNewDN();
                final ModifyDNRequest modifyDNRequest = modifyDNChangeRecord.toModifyDNRequest();
                modifyDNRequest.addControls(modifyDNControls);
                connectionPool.modifyDN(modifyDNRequest);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            } else {
                // This should never happen.
                r.processChange(connectionPool);
                parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
            }
        } catch (final LDAPException e) {
            Debug.debugException(e);
            parallelUpdate.opFailed(r, e, (System.currentTimeMillis() - startTime));
        }
        if (parsedNewDN == null) {
            r = opQueue.getChangeRecord(parsedDN);
        } else {
            r = opQueue.getChangeRecord(parsedDN, parsedNewDN);
        }
    }
}
Also used : LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) DN(com.unboundid.ldap.sdk.DN) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) AddRequest(com.unboundid.ldap.sdk.AddRequest) ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) Control(com.unboundid.ldap.sdk.Control) UndeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) UndeleteRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest)

Aggregations

AddRequest (com.unboundid.ldap.sdk.AddRequest)2 Control (com.unboundid.ldap.sdk.Control)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 DN (com.unboundid.ldap.sdk.DN)1 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)1 Entry (com.unboundid.ldap.sdk.Entry)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)1 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)1 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)1 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)1 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)1 PermissiveModifyRequestControl (com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl)1 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)1 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)1 ProxiedAuthorizationV1RequestControl (com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV1RequestControl)1 ProxiedAuthorizationV2RequestControl (com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl)1 SimplePagedResultsControl (com.unboundid.ldap.sdk.controls.SimplePagedResultsControl)1 SubtreeDeleteRequestControl (com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl)1