use of com.unboundid.ldap.sdk.unboundidds.extensions.SetSubtreeAccessibilityExtendedRequest in project ldapsdk by pingidentity.
the class MoveSubtree method setAccessibility.
/**
* Updates subtree accessibility in a server.
*
* @param connection The connection to the server in which the
* accessibility state should be applied.
* @param isSource Indicates whether the connection is to the source
* or target server.
* @param baseDN The base DN for the subtree to move.
* @param state The accessibility state to apply.
* @param bypassDN The DN of a user that will be allowed to bypass
* accessibility restrictions. It may be
* {@code null} if none is needed.
* @param opPurposeControl An optional operation purpose request control
* that may be included in the request.
*
* @throws LDAPException If a problem is encountered while attempting to set
* the accessibility state for the subtree.
*/
private static void setAccessibility(@NotNull final LDAPConnection connection, final boolean isSource, @NotNull final String baseDN, @NotNull final SubtreeAccessibilityState state, @Nullable final String bypassDN, @Nullable final OperationPurposeRequestControl opPurposeControl) throws LDAPException {
final String connectionName = isSource ? INFO_MOVE_SUBTREE_CONNECTION_NAME_SOURCE.get() : INFO_MOVE_SUBTREE_CONNECTION_NAME_TARGET.get();
final Control[] controls;
if (opPurposeControl == null) {
controls = StaticUtils.NO_CONTROLS;
} else {
controls = new Control[] { opPurposeControl };
}
final SetSubtreeAccessibilityExtendedRequest request;
switch(state) {
case ACCESSIBLE:
request = SetSubtreeAccessibilityExtendedRequest.createSetAccessibleRequest(baseDN, controls);
break;
case READ_ONLY_BIND_ALLOWED:
request = SetSubtreeAccessibilityExtendedRequest.createSetReadOnlyRequest(baseDN, true, bypassDN, controls);
break;
case READ_ONLY_BIND_DENIED:
request = SetSubtreeAccessibilityExtendedRequest.createSetReadOnlyRequest(baseDN, false, bypassDN, controls);
break;
case HIDDEN:
request = SetSubtreeAccessibilityExtendedRequest.createSetHiddenRequest(baseDN, bypassDN, controls);
break;
default:
throw new LDAPException(ResultCode.PARAM_ERROR, ERR_MOVE_SUBTREE_UNSUPPORTED_ACCESSIBILITY_STATE.get(state.getStateName(), baseDN, connectionName));
}
LDAPResult result;
try {
result = connection.processExtendedOperation(request);
} catch (final LDAPException le) {
Debug.debugException(le);
result = le.toLDAPResult();
}
if (result.getResultCode() != ResultCode.SUCCESS) {
throw new LDAPException(result.getResultCode(), ERR_MOVE_SUBTREE_ERROR_SETTING_ACCESSIBILITY.get(state.getStateName(), baseDN, connectionName, result.getDiagnosticMessage()));
}
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.SetSubtreeAccessibilityExtendedRequest in project ldapsdk by pingidentity.
the class MoveSubtreeTestCase method setState.
/**
* Applies the specified subtree accessibility state in Directory Server.
*
* @param conn The connection to use to communicate with the Directory
* Server.
* @param baseDN The base DN for which to set the accessibility state.
* @param state The accessibility state to apply.
*
* @throws Exception If an unexpected problem occurs.
*/
private static void setState(final LDAPConnection conn, final String baseDN, final SubtreeAccessibilityState state) throws Exception {
final SetSubtreeAccessibilityExtendedRequest request;
switch(state) {
case ACCESSIBLE:
request = SetSubtreeAccessibilityExtendedRequest.createSetAccessibleRequest(baseDN);
break;
case HIDDEN:
request = SetSubtreeAccessibilityExtendedRequest.createSetHiddenRequest(baseDN, getTestBindDN());
break;
case READ_ONLY_BIND_ALLOWED:
request = SetSubtreeAccessibilityExtendedRequest.createSetReadOnlyRequest(baseDN, true, getTestBindDN());
break;
case READ_ONLY_BIND_DENIED:
request = SetSubtreeAccessibilityExtendedRequest.createSetReadOnlyRequest(baseDN, false, getTestBindDN());
break;
default:
throw new AssertionError("Unsupported accessibility state: " + state.name());
}
final ExtendedResult result = conn.processExtendedOperation(request);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.SetSubtreeAccessibilityExtendedRequest in project ldapsdk by pingidentity.
the class SubtreeAccessibility method doSet.
/**
* Does the work necessary to update a subtree accessibility restriction
* defined in the server.
*
* @param connection The connection to use to communicate with the server.
*
* @return A result code with information about the result of operation
* processing.
*/
@NotNull()
private ResultCode doSet(@NotNull final LDAPConnection connection) {
final SubtreeAccessibilityState state = SubtreeAccessibilityState.forName(accessibilityState.getValue());
if (state == null) {
// This should never happen.
err("Unsupported subtree accessibility state ", accessibilityState.getValue());
return ResultCode.PARAM_ERROR;
}
final SetSubtreeAccessibilityExtendedRequest request;
switch(state) {
case ACCESSIBLE:
request = SetSubtreeAccessibilityExtendedRequest.createSetAccessibleRequest(baseDN.getStringValue());
break;
case READ_ONLY_BIND_ALLOWED:
request = SetSubtreeAccessibilityExtendedRequest.createSetReadOnlyRequest(baseDN.getStringValue(), true, bypassUserDN.getStringValue());
break;
case READ_ONLY_BIND_DENIED:
request = SetSubtreeAccessibilityExtendedRequest.createSetReadOnlyRequest(baseDN.getStringValue(), false, bypassUserDN.getStringValue());
break;
case HIDDEN:
request = SetSubtreeAccessibilityExtendedRequest.createSetHiddenRequest(baseDN.getStringValue(), bypassUserDN.getStringValue());
break;
default:
// This should never happen.
err("Unsupported subtree accessibility state ", state.getStateName());
return ResultCode.PARAM_ERROR;
}
final ExtendedResult result;
try {
result = connection.processExtendedOperation(request);
} catch (final LDAPException le) {
Debug.debugException(le);
err("An error occurred while attempting to invoke the set subtree " + "accessibility request: ", StaticUtils.getExceptionMessage(le));
return le.getResultCode();
}
if (result.getResultCode() == ResultCode.SUCCESS) {
out("Successfully set an accessibility state of ", state.getStateName(), " for subtree ", baseDN.getStringValue());
} else {
out("Unable to set an accessibility state of ", state.getStateName(), " for subtree ", baseDN.getStringValue(), ": ", result.getDiagnosticMessage());
}
return result.getResultCode();
}
Aggregations