Search in sources :

Example 1 with SetSubtreeAccessibilityExtendedRequest

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()));
    }
}
Also used : Control(com.unboundid.ldap.sdk.Control) RealAttributesOnlyRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.RealAttributesOnlyRequestControl) OperationPurposeRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl) SuppressReferentialIntegrityUpdatesRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.SuppressReferentialIntegrityUpdatesRequestControl) SoftDeletedEntryAccessRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.SoftDeletedEntryAccessRequestControl) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) ReturnConflictEntriesRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.ReturnConflictEntriesRequestControl) DraftLDUPSubentriesRequestControl(com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) SetSubtreeAccessibilityExtendedRequest(com.unboundid.ldap.sdk.unboundidds.extensions.SetSubtreeAccessibilityExtendedRequest) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ASN1OctetString(com.unboundid.asn1.ASN1OctetString)

Example 2 with SetSubtreeAccessibilityExtendedRequest

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);
}
Also used : SetSubtreeAccessibilityExtendedRequest(com.unboundid.ldap.sdk.unboundidds.extensions.SetSubtreeAccessibilityExtendedRequest) NoticeOfDisconnectionExtendedResult(com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

Example 3 with SetSubtreeAccessibilityExtendedRequest

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();
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) SetSubtreeAccessibilityExtendedRequest(com.unboundid.ldap.sdk.unboundidds.extensions.SetSubtreeAccessibilityExtendedRequest) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) GetSubtreeAccessibilityExtendedResult(com.unboundid.ldap.sdk.unboundidds.extensions.GetSubtreeAccessibilityExtendedResult) SubtreeAccessibilityState(com.unboundid.ldap.sdk.unboundidds.extensions.SubtreeAccessibilityState) NotNull(com.unboundid.util.NotNull)

Aggregations

SetSubtreeAccessibilityExtendedRequest (com.unboundid.ldap.sdk.unboundidds.extensions.SetSubtreeAccessibilityExtendedRequest)3 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 Control (com.unboundid.ldap.sdk.Control)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 DraftLDUPSubentriesRequestControl (com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl)1 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)1 NoticeOfDisconnectionExtendedResult (com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult)1 OperationPurposeRequestControl (com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl)1 RealAttributesOnlyRequestControl (com.unboundid.ldap.sdk.unboundidds.controls.RealAttributesOnlyRequestControl)1 ReturnConflictEntriesRequestControl (com.unboundid.ldap.sdk.unboundidds.controls.ReturnConflictEntriesRequestControl)1 SoftDeletedEntryAccessRequestControl (com.unboundid.ldap.sdk.unboundidds.controls.SoftDeletedEntryAccessRequestControl)1 SuppressReferentialIntegrityUpdatesRequestControl (com.unboundid.ldap.sdk.unboundidds.controls.SuppressReferentialIntegrityUpdatesRequestControl)1 GetSubtreeAccessibilityExtendedResult (com.unboundid.ldap.sdk.unboundidds.extensions.GetSubtreeAccessibilityExtendedResult)1 SubtreeAccessibilityState (com.unboundid.ldap.sdk.unboundidds.extensions.SubtreeAccessibilityState)1 NotNull (com.unboundid.util.NotNull)1