001/*
002 * Copyright 2008-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2022 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2008-2022 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.controls;
037
038
039
040import com.unboundid.ldap.sdk.Control;
041import com.unboundid.ldap.sdk.LDAPException;
042import com.unboundid.ldap.sdk.ResultCode;
043import com.unboundid.util.NotMutable;
044import com.unboundid.util.NotNull;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
049
050
051
052/**
053 * This class provides an implementation of the LDAP no-op control as defined in
054 * draft-zeilenga-ldap-noop.  This control may be included in an add, delete,
055 * modify, or modify DN request to indicate that the server should validate the
056 * request but not actually make any changes to the data.  It allows the client
057 * to verify that the operation would likely succeed (including schema
058 * validation, access control checks, and other processing) without making any
059 * changes to the server data.
060 * <BR>
061 * <BLOCKQUOTE>
062 *   <B>NOTE:</B>  This class, and other classes within the
063 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
064 *   supported for use against Ping Identity, UnboundID, and
065 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
066 *   for proprietary functionality or for external specifications that are not
067 *   considered stable or mature enough to be guaranteed to work in an
068 *   interoperable way with other types of LDAP servers.
069 * </BLOCKQUOTE>
070 * <BR>
071 * Note that an operation which includes the no-op control will never have a
072 * {@link ResultCode#SUCCESS} result.  Instead, if the operation would likely
073 * have completed successfully if the no-op control had not been included, then
074 * the server will include a response with the {@link ResultCode#NO_OPERATION}
075 * result.  If the operation would not have been successful, then the result
076 * code in the response will be the appropriate result code for that failure.
077 * Note that if the response from the server includes the
078 * {@link ResultCode#NO_OPERATION} result, then the LDAP SDK will not throw an
079 * exception but will instead return the response in an
080 * {@link com.unboundid.ldap.sdk.LDAPResult} object.  There is no corresponding
081 * response control.
082 * <BR><BR>
083 * Note that at the time this control was written, the latest version of the
084 * specification may be found in draft-zeilenga-ldap-noop-11.  This version of
085 * the document does not explicitly specify either the OID that should be used
086 * for the control, or the result code that should be used for the associated
087 * operation if all other processing is completed successfully but no changes
088 * are made as a result of this control.  Until such time as these are defined,
089 * this implementation uses the OID temporarily assigned for its use by the
090 * OpenLDAP Foundation, which is used by at least the OpenLDAP, OpenDS, and the
091 * Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 Directory Server
092 * implementations.
093 * <BR><BR>
094 * This control has an OID of 1.3.6.1.4.1.4203.1.10.2 and a criticality of true.
095 * It does not have a value.
096 * <BR><BR>
097 * <H2>Example</H2>
098 * The following example demonstrates the process for attempting to perform a
099 * modify operation including the LDAP no-op control so that the change is not
100 * actually applied:
101 * <PRE>
102 * ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com",
103 *      new Modification(ModificationType.REPLACE, "description",
104 *           "new value"));
105 * modifyRequest.addControl(new NoOpRequestControl());
106 *
107 * try
108 * {
109 *   LDAPResult result = connection.modify(modifyRequest);
110 *   if (result.getResultCode() == ResultCode.NO_OPERATION)
111 *   {
112 *     // The modify would likely have succeeded.
113 *   }
114 *   else
115 *   {
116 *     // The modify would likely have failed.
117 *   }
118 * }
119 * catch (LDAPException le)
120 * {
121 *   // The modify attempt failed even with the no-op control.
122 * }
123 * </PRE>
124 */
125@NotMutable()
126@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
127public final class NoOpRequestControl
128       extends Control
129{
130  /**
131   * The OID (1.3.6.1.4.1.4203.1.10.2) for the LDAP no-op request control.
132   */
133  @NotNull public static final String NO_OP_REQUEST_OID =
134       "1.3.6.1.4.1.4203.1.10.2";
135
136
137
138  /**
139   * The serial version UID for this serializable class.
140   */
141  private static final long serialVersionUID = -7435407787971958294L;
142
143
144
145  /**
146   * Creates a new no-op request control.  It will be marked critical, as
147   * required by the control specification.
148   */
149  public NoOpRequestControl()
150  {
151    super(NO_OP_REQUEST_OID, true, null);
152  }
153
154
155
156  /**
157   * Creates a new no-op request control which is decoded from the provided
158   * generic control.
159   *
160   * @param  control  The generic control to be decoded as a no-op request
161   *                  control.
162   *
163   * @throws  LDAPException  If the provided control cannot be decoded as a
164   *                         no-op request control.
165   */
166  public NoOpRequestControl(@NotNull final Control control)
167         throws LDAPException
168  {
169    super(control);
170
171    if (control.hasValue())
172    {
173      throw new LDAPException(ResultCode.DECODING_ERROR,
174                              ERR_NOOP_REQUEST_HAS_VALUE.get());
175    }
176  }
177
178
179
180  /**
181   * {@inheritDoc}
182   */
183  @Override()
184  @NotNull()
185  public String getControlName()
186  {
187    return INFO_CONTROL_NAME_NOOP_REQUEST.get();
188  }
189
190
191
192  /**
193   * {@inheritDoc}
194   */
195  @Override()
196  public void toString(@NotNull final StringBuilder buffer)
197  {
198    buffer.append("NoOpRequestControl(isCritical=");
199    buffer.append(isCritical());
200    buffer.append(')');
201  }
202}