use of com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl in project ldapsdk by pingidentity.
the class MoveSubtree method doToolProcessing.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public ResultCode doToolProcessing() {
final List<String> baseDNs;
if (baseDN.isPresent()) {
final List<DN> dnList = baseDN.getValues();
baseDNs = new ArrayList<>(dnList.size());
for (final DN dn : dnList) {
baseDNs.add(dn.toString());
}
} else {
try {
baseDNs = baseDNFile.getNonBlankFileLines();
} catch (final Exception e) {
Debug.debugException(e);
err(ERR_MOVE_SUBTREE_ERROR_READING_BASE_DN_FILE.get(baseDNFile.getValue().getAbsolutePath(), StaticUtils.getExceptionMessage(e)));
return ResultCode.LOCAL_ERROR;
}
if (baseDNs.isEmpty()) {
err(ERR_MOVE_SUBTREE_BASE_DN_FILE_EMPTY.get(baseDNFile.getValue().getAbsolutePath()));
return ResultCode.PARAM_ERROR;
}
}
LDAPConnection sourceConnection = null;
LDAPConnection targetConnection = null;
try {
try {
sourceConnection = getConnection(0);
} catch (final LDAPException le) {
Debug.debugException(le);
err(ERR_MOVE_SUBTREE_CANNOT_CONNECT_TO_SOURCE.get(StaticUtils.getExceptionMessage(le)));
return le.getResultCode();
}
try {
targetConnection = getConnection(1);
} catch (final LDAPException le) {
Debug.debugException(le);
err(ERR_MOVE_SUBTREE_CANNOT_CONNECT_TO_TARGET.get(StaticUtils.getExceptionMessage(le)));
return le.getResultCode();
}
sourceConnection.setConnectionName(INFO_MOVE_SUBTREE_CONNECTION_NAME_SOURCE.get());
targetConnection.setConnectionName(INFO_MOVE_SUBTREE_CONNECTION_NAME_TARGET.get());
// port for both source and target servers.
if (sourceConnection.getConnectedAddress().equals(targetConnection.getConnectedAddress()) && (sourceConnection.getConnectedPort() == targetConnection.getConnectedPort())) {
err(ERR_MOVE_SUBTREE_SAME_SOURCE_AND_TARGET_SERVERS.get());
return ResultCode.PARAM_ERROR;
}
// Next, retrieve the root DSE over each connection. Use it to verify
// that both the startupUUID values are different as a check to ensure
// that the source and target servers are different (this will be a
// best-effort attempt, so if either startupUUID can't be retrieved, then
// assume they're different servers). Also check to see whether the
// source server supports the suppress referential integrity updates
// control.
boolean suppressReferentialIntegrityUpdates = false;
try {
final RootDSE sourceRootDSE = sourceConnection.getRootDSE();
final RootDSE targetRootDSE = targetConnection.getRootDSE();
if ((sourceRootDSE != null) && (targetRootDSE != null)) {
final String sourceStartupUUID = sourceRootDSE.getAttributeValue(ATTR_STARTUP_UUID);
final String targetStartupUUID = targetRootDSE.getAttributeValue(ATTR_STARTUP_UUID);
if ((sourceStartupUUID != null) && sourceStartupUUID.equals(targetStartupUUID)) {
err(ERR_MOVE_SUBTREE_SAME_SOURCE_AND_TARGET_SERVERS.get());
return ResultCode.PARAM_ERROR;
}
}
if (sourceRootDSE != null) {
suppressReferentialIntegrityUpdates = sourceRootDSE.supportsControl(SuppressReferentialIntegrityUpdatesRequestControl.SUPPRESS_REFINT_REQUEST_OID);
}
} catch (final Exception e) {
Debug.debugException(e);
}
boolean first = true;
ResultCode resultCode = ResultCode.SUCCESS;
for (final String dn : baseDNs) {
if (first) {
first = false;
} else {
out();
}
final OperationPurposeRequestControl operationPurpose;
if (purpose.isPresent()) {
operationPurpose = new OperationPurposeRequestControl(getToolName(), getToolVersion(), 20, purpose.getValue());
} else {
operationPurpose = null;
}
final MoveSubtreeResult result = moveSubtreeWithRestrictedAccessibility(this, sourceConnection, targetConnection, dn, sizeLimit.getValue(), operationPurpose, suppressReferentialIntegrityUpdates, (verbose.isPresent() ? this : null));
if (result.getResultCode() == ResultCode.SUCCESS) {
wrapOut(0, 79, INFO_MOVE_SUBTREE_RESULT_SUCCESSFUL.get(result.getEntriesAddedToTarget(), dn));
} else {
if (resultCode == ResultCode.SUCCESS) {
resultCode = result.getResultCode();
}
wrapErr(0, 79, ERR_MOVE_SUBTREE_RESULT_UNSUCCESSFUL.get());
if (result.getErrorMessage() != null) {
wrapErr(0, 79, ERR_MOVE_SUBTREE_ERROR_MESSAGE.get(result.getErrorMessage()));
}
if (result.getAdminActionRequired() != null) {
wrapErr(0, 79, ERR_MOVE_SUBTREE_ADMIN_ACTION.get(result.getAdminActionRequired()));
}
}
}
return resultCode;
} finally {
if (sourceConnection != null) {
sourceConnection.close();
}
if (targetConnection != null) {
targetConnection.close();
}
}
}
use of com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl in project ldapsdk by pingidentity.
the class LDAPDelete method getDeleteControls.
/**
* Retrieves the set of controls that should be included in delete requests.
*
* @return The set of controls that should be included in delete requests.
*/
@NotNull()
private List<Control> getDeleteControls() {
final List<Control> controlList = new ArrayList<>(10);
if (deleteControl.isPresent()) {
controlList.addAll(deleteControl.getValues());
}
controlList.addAll(routeToBackendSetRequestControls);
if (serverSideSubtreeDelete.isPresent()) {
controlList.add(new SubtreeDeleteRequestControl(true));
}
if (softDelete.isPresent()) {
controlList.add(new SoftDeleteRequestControl(true, true));
}
if (hardDelete.isPresent() && (!clientSideSubtreeDelete.isPresent())) {
controlList.add(new HardDeleteRequestControl(true));
}
if (proxyAs.isPresent()) {
controlList.add(new ProxiedAuthorizationV2RequestControl(proxyAs.getValue()));
}
if (proxyV1As.isPresent()) {
controlList.add(new ProxiedAuthorizationV1RequestControl(proxyV1As.getValue().toString()));
}
if (manageDsaIT.isPresent() && (!clientSideSubtreeDelete.isPresent())) {
controlList.add(new ManageDsaITRequestControl(true));
}
if (assertionFilter.isPresent()) {
controlList.add(new AssertionRequestControl(assertionFilter.getValue(), true));
}
if (preReadAttribute.isPresent()) {
controlList.add(new PreReadRequestControl(true, preReadAttribute.getValues().toArray(StaticUtils.NO_STRINGS)));
}
if (noOperation.isPresent()) {
controlList.add(new NoOpRequestControl());
}
if (getBackendSetID.isPresent()) {
controlList.add(new GetBackendSetIDRequestControl(true));
}
if (getServerID.isPresent()) {
controlList.add(new GetServerIDRequestControl(true));
}
if (routeToServer.isPresent()) {
controlList.add(new RouteToServerRequestControl(true, routeToServer.getValue(), false, false, false));
}
if (useAssuredReplication.isPresent()) {
AssuredReplicationLocalLevel localLevel = null;
if (assuredReplicationLocalLevel.isPresent()) {
final String level = assuredReplicationLocalLevel.getValue();
if (level.equalsIgnoreCase("none")) {
localLevel = AssuredReplicationLocalLevel.NONE;
} else if (level.equalsIgnoreCase("received-any-server")) {
localLevel = AssuredReplicationLocalLevel.RECEIVED_ANY_SERVER;
} else if (level.equalsIgnoreCase("processed-all-servers")) {
localLevel = AssuredReplicationLocalLevel.PROCESSED_ALL_SERVERS;
}
}
AssuredReplicationRemoteLevel remoteLevel = null;
if (assuredReplicationRemoteLevel.isPresent()) {
final String level = assuredReplicationRemoteLevel.getValue();
if (level.equalsIgnoreCase("none")) {
remoteLevel = AssuredReplicationRemoteLevel.NONE;
} else if (level.equalsIgnoreCase("received-any-remote-location")) {
remoteLevel = AssuredReplicationRemoteLevel.RECEIVED_ANY_REMOTE_LOCATION;
} else if (level.equalsIgnoreCase("received-all-remote-locations")) {
remoteLevel = AssuredReplicationRemoteLevel.RECEIVED_ALL_REMOTE_LOCATIONS;
} else if (level.equalsIgnoreCase("processed-all-remote-servers")) {
remoteLevel = AssuredReplicationRemoteLevel.PROCESSED_ALL_REMOTE_SERVERS;
}
}
Long timeoutMillis = null;
if (assuredReplicationTimeout.isPresent()) {
timeoutMillis = assuredReplicationTimeout.getValue(TimeUnit.MILLISECONDS);
}
final AssuredReplicationRequestControl c = new AssuredReplicationRequestControl(true, localLevel, localLevel, remoteLevel, remoteLevel, timeoutMillis, false);
controlList.add(c);
}
if (replicationRepair.isPresent()) {
controlList.add(new ReplicationRepairRequestControl());
}
if (suppressReferentialIntegrityUpdates.isPresent()) {
controlList.add(new SuppressReferentialIntegrityUpdatesRequestControl(true));
}
if (operationPurpose.isPresent()) {
controlList.add(new OperationPurposeRequestControl(true, "ldapdelete", Version.NUMERIC_VERSION_STRING, LDAPDelete.class.getName() + ".getDeleteControls", operationPurpose.getValue()));
}
return Collections.unmodifiableList(controlList);
}
use of com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl in project ldapsdk by pingidentity.
the class LDAPModify method createRequestControls.
/**
* Populates lists of request controls that should be included in requests
* of various types.
*
* @param addControls The list of controls to include in add requests.
* @param deleteControls The list of controls to include in delete
* requests.
* @param modifyControls The list of controls to include in modify
* requests.
* @param modifyDNControls The list of controls to include in modify DN
* requests.
* @param searchControls The list of controls to include in search
* requests.
*
* @throws LDAPException If a problem is encountered while creating any of
* the requested controls.
*/
private void createRequestControls(@NotNull final List<Control> addControls, @NotNull final List<Control> deleteControls, @NotNull final List<Control> modifyControls, @NotNull final List<Control> modifyDNControls, @NotNull final List<Control> searchControls) throws LDAPException {
if (addControl.isPresent()) {
addControls.addAll(addControl.getValues());
}
if (deleteControl.isPresent()) {
deleteControls.addAll(deleteControl.getValues());
}
if (modifyControl.isPresent()) {
modifyControls.addAll(modifyControl.getValues());
}
if (modifyDNControl.isPresent()) {
modifyDNControls.addAll(modifyDNControl.getValues());
}
if (operationControl.isPresent()) {
addControls.addAll(operationControl.getValues());
deleteControls.addAll(operationControl.getValues());
modifyControls.addAll(operationControl.getValues());
modifyDNControls.addAll(operationControl.getValues());
}
addControls.addAll(routeToBackendSetRequestControls);
deleteControls.addAll(routeToBackendSetRequestControls);
modifyControls.addAll(routeToBackendSetRequestControls);
modifyDNControls.addAll(routeToBackendSetRequestControls);
if (noOperation.isPresent()) {
final NoOpRequestControl c = new NoOpRequestControl();
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (generatePassword.isPresent()) {
addControls.add(new GeneratePasswordRequestControl());
}
if (getBackendSetID.isPresent()) {
final GetBackendSetIDRequestControl c = new GetBackendSetIDRequestControl(false);
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (getServerID.isPresent()) {
final GetServerIDRequestControl c = new GetServerIDRequestControl(false);
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (ignoreNoUserModification.isPresent()) {
addControls.add(new IgnoreNoUserModificationRequestControl(false));
modifyControls.add(new IgnoreNoUserModificationRequestControl(false));
}
if (nameWithEntryUUID.isPresent()) {
addControls.add(new NameWithEntryUUIDRequestControl(true));
}
if (permissiveModify.isPresent()) {
modifyControls.add(new PermissiveModifyRequestControl(false));
}
if (routeToServer.isPresent()) {
final RouteToServerRequestControl c = new RouteToServerRequestControl(false, routeToServer.getValue(), false, false, false);
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (suppressReferentialIntegrityUpdates.isPresent()) {
final SuppressReferentialIntegrityUpdatesRequestControl c = new SuppressReferentialIntegrityUpdatesRequestControl(true);
deleteControls.add(c);
modifyDNControls.add(c);
}
if (suppressOperationalAttributeUpdates.isPresent()) {
final EnumSet<SuppressType> suppressTypes = EnumSet.noneOf(SuppressType.class);
for (final String s : suppressOperationalAttributeUpdates.getValues()) {
if (s.equalsIgnoreCase("last-access-time")) {
suppressTypes.add(SuppressType.LAST_ACCESS_TIME);
} else if (s.equalsIgnoreCase("last-login-time")) {
suppressTypes.add(SuppressType.LAST_LOGIN_TIME);
} else if (s.equalsIgnoreCase("last-login-ip")) {
suppressTypes.add(SuppressType.LAST_LOGIN_IP);
} else if (s.equalsIgnoreCase("lastmod")) {
suppressTypes.add(SuppressType.LASTMOD);
}
}
final SuppressOperationalAttributeUpdateRequestControl c = new SuppressOperationalAttributeUpdateRequestControl(suppressTypes);
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (usePasswordPolicyControl.isPresent()) {
final PasswordPolicyRequestControl c = new PasswordPolicyRequestControl();
addControls.add(c);
modifyControls.add(c);
}
if (assuredReplication.isPresent()) {
AssuredReplicationLocalLevel localLevel = null;
if (assuredReplicationLocalLevel.isPresent()) {
final String level = assuredReplicationLocalLevel.getValue();
if (level.equalsIgnoreCase("none")) {
localLevel = AssuredReplicationLocalLevel.NONE;
} else if (level.equalsIgnoreCase("received-any-server")) {
localLevel = AssuredReplicationLocalLevel.RECEIVED_ANY_SERVER;
} else if (level.equalsIgnoreCase("processed-all-servers")) {
localLevel = AssuredReplicationLocalLevel.PROCESSED_ALL_SERVERS;
}
}
AssuredReplicationRemoteLevel remoteLevel = null;
if (assuredReplicationRemoteLevel.isPresent()) {
final String level = assuredReplicationRemoteLevel.getValue();
if (level.equalsIgnoreCase("none")) {
remoteLevel = AssuredReplicationRemoteLevel.NONE;
} else if (level.equalsIgnoreCase("received-any-remote-location")) {
remoteLevel = AssuredReplicationRemoteLevel.RECEIVED_ANY_REMOTE_LOCATION;
} else if (level.equalsIgnoreCase("received-all-remote-locations")) {
remoteLevel = AssuredReplicationRemoteLevel.RECEIVED_ALL_REMOTE_LOCATIONS;
} else if (level.equalsIgnoreCase("processed-all-remote-servers")) {
remoteLevel = AssuredReplicationRemoteLevel.PROCESSED_ALL_REMOTE_SERVERS;
}
}
Long timeoutMillis = null;
if (assuredReplicationTimeout.isPresent()) {
timeoutMillis = assuredReplicationTimeout.getValue(TimeUnit.MILLISECONDS);
}
final AssuredReplicationRequestControl c = new AssuredReplicationRequestControl(true, localLevel, localLevel, remoteLevel, remoteLevel, timeoutMillis, false);
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (hardDelete.isPresent() && (!clientSideSubtreeDelete.isPresent())) {
deleteControls.add(new HardDeleteRequestControl(true));
}
if (replicationRepair.isPresent()) {
final ReplicationRepairRequestControl c = new ReplicationRepairRequestControl();
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (softDelete.isPresent()) {
deleteControls.add(new SoftDeleteRequestControl(true, true));
}
if (serverSideSubtreeDelete.isPresent()) {
deleteControls.add(new SubtreeDeleteRequestControl());
}
if (assertionFilter.isPresent()) {
final AssertionRequestControl c = new AssertionRequestControl(assertionFilter.getValue(), true);
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (operationPurpose.isPresent()) {
final OperationPurposeRequestControl c = new OperationPurposeRequestControl(false, "ldapmodify", Version.NUMERIC_VERSION_STRING, LDAPModify.class.getName() + ".createRequestControls", operationPurpose.getValue());
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (manageDsaIT.isPresent()) {
final ManageDsaITRequestControl c = new ManageDsaITRequestControl(true);
addControls.add(c);
if (!clientSideSubtreeDelete.isPresent()) {
deleteControls.add(c);
}
modifyControls.add(c);
modifyDNControls.add(c);
}
if (passwordUpdateBehavior.isPresent()) {
final PasswordUpdateBehaviorRequestControl c = createPasswordUpdateBehaviorRequestControl(passwordUpdateBehavior.getIdentifierString(), passwordUpdateBehavior.getValues());
addControls.add(c);
modifyControls.add(c);
}
if (preReadAttribute.isPresent()) {
final ArrayList<String> attrList = new ArrayList<>(10);
for (final String value : preReadAttribute.getValues()) {
final StringTokenizer tokenizer = new StringTokenizer(value, ", ");
while (tokenizer.hasMoreTokens()) {
attrList.add(tokenizer.nextToken());
}
}
final String[] attrArray = attrList.toArray(StaticUtils.NO_STRINGS);
final PreReadRequestControl c = new PreReadRequestControl(attrArray);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (postReadAttribute.isPresent()) {
final ArrayList<String> attrList = new ArrayList<>(10);
for (final String value : postReadAttribute.getValues()) {
final StringTokenizer tokenizer = new StringTokenizer(value, ", ");
while (tokenizer.hasMoreTokens()) {
attrList.add(tokenizer.nextToken());
}
}
final String[] attrArray = attrList.toArray(StaticUtils.NO_STRINGS);
final PostReadRequestControl c = new PostReadRequestControl(attrArray);
addControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
if (proxyAs.isPresent() && (!useTransaction.isPresent()) && (!multiUpdateErrorBehavior.isPresent())) {
final ProxiedAuthorizationV2RequestControl c = new ProxiedAuthorizationV2RequestControl(proxyAs.getValue());
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
searchControls.add(c);
}
if (proxyV1As.isPresent() && (!useTransaction.isPresent()) && (!multiUpdateErrorBehavior.isPresent())) {
final ProxiedAuthorizationV1RequestControl c = new ProxiedAuthorizationV1RequestControl(proxyV1As.getValue());
addControls.add(c);
deleteControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
searchControls.add(c);
}
if (uniquenessAttribute.isPresent() || uniquenessFilter.isPresent()) {
final UniquenessRequestControlProperties uniquenessProperties;
if (uniquenessAttribute.isPresent()) {
uniquenessProperties = new UniquenessRequestControlProperties(uniquenessAttribute.getValues());
if (uniquenessFilter.isPresent()) {
uniquenessProperties.setFilter(uniquenessFilter.getValue());
}
} else {
uniquenessProperties = new UniquenessRequestControlProperties(uniquenessFilter.getValue());
}
if (uniquenessBaseDN.isPresent()) {
uniquenessProperties.setBaseDN(uniquenessBaseDN.getStringValue());
}
if (uniquenessMultipleAttributeBehavior.isPresent()) {
final String value = uniquenessMultipleAttributeBehavior.getValue().toLowerCase();
switch(value) {
case "unique-within-each-attribute":
uniquenessProperties.setMultipleAttributeBehavior(UniquenessMultipleAttributeBehavior.UNIQUE_WITHIN_EACH_ATTRIBUTE);
break;
case "unique-across-all-attributes-including-in-same-entry":
uniquenessProperties.setMultipleAttributeBehavior(UniquenessMultipleAttributeBehavior.UNIQUE_ACROSS_ALL_ATTRIBUTES_INCLUDING_IN_SAME_ENTRY);
break;
case "unique-across-all-attributes-except-in-same-entry":
uniquenessProperties.setMultipleAttributeBehavior(UniquenessMultipleAttributeBehavior.UNIQUE_ACROSS_ALL_ATTRIBUTES_EXCEPT_IN_SAME_ENTRY);
break;
case "unique-in-combination":
uniquenessProperties.setMultipleAttributeBehavior(UniquenessMultipleAttributeBehavior.UNIQUE_IN_COMBINATION);
break;
}
}
if (uniquenessPreCommitValidationLevel.isPresent()) {
final String value = uniquenessPreCommitValidationLevel.getValue().toLowerCase();
switch(value) {
case "none":
uniquenessProperties.setPreCommitValidationLevel(UniquenessValidationLevel.NONE);
break;
case "all-subtree-views":
uniquenessProperties.setPreCommitValidationLevel(UniquenessValidationLevel.ALL_SUBTREE_VIEWS);
break;
case "all-backend-sets":
uniquenessProperties.setPreCommitValidationLevel(UniquenessValidationLevel.ALL_BACKEND_SETS);
break;
case "all-available-backend-servers":
uniquenessProperties.setPreCommitValidationLevel(UniquenessValidationLevel.ALL_AVAILABLE_BACKEND_SERVERS);
break;
}
}
if (uniquenessPostCommitValidationLevel.isPresent()) {
final String value = uniquenessPostCommitValidationLevel.getValue().toLowerCase();
switch(value) {
case "none":
uniquenessProperties.setPostCommitValidationLevel(UniquenessValidationLevel.NONE);
break;
case "all-subtree-views":
uniquenessProperties.setPostCommitValidationLevel(UniquenessValidationLevel.ALL_SUBTREE_VIEWS);
break;
case "all-backend-sets":
uniquenessProperties.setPostCommitValidationLevel(UniquenessValidationLevel.ALL_BACKEND_SETS);
break;
case "all-available-backend-servers":
uniquenessProperties.setPostCommitValidationLevel(UniquenessValidationLevel.ALL_AVAILABLE_BACKEND_SERVERS);
break;
}
}
final UniquenessRequestControl c = new UniquenessRequestControl(true, null, uniquenessProperties);
addControls.add(c);
modifyControls.add(c);
modifyDNControls.add(c);
}
}
Aggregations