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