001/*
002 * Copyright 2007-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-2020 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) 2007-2020 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.experimental;
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.ThreadSafety;
045import com.unboundid.util.ThreadSafetyLevel;
046
047import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*;
048
049
050
051/**
052 * This class provides an implementation of the LDAP no-op control as defined in
053 * draft-zeilenga-ldap-noop-12.  This control may be included in an add, delete,
054 * modify, or modify DN request to indicate that the server should validate the
055 * request but not actually make any changes to the data.  It allows the client
056 * to verify that the operation would likely succeed (including schema
057 * validation, access control checks, and other processing) without making any
058 * changes to the server data.
059 * <BR><BR>
060 * Note that an operation which includes the no-op control will never have a
061 * {@link ResultCode#SUCCESS} result.  Instead, if the operation would likely
062 * have completed successfully if the no-op control had not been included, then
063 * the server will include a response with the {@link ResultCode#NO_OPERATION}
064 * result.  If the operation would not have been successful, then the result
065 * code in the response will be the appropriate result code for that failure.
066 * Note that if the response from the server includes the
067 * {@link ResultCode#NO_OPERATION} result, then the LDAP SDK will not throw an
068 * exception but will instead return the response in an
069 * {@link com.unboundid.ldap.sdk.LDAPResult} object.  There is no corresponding
070 * response control.
071 * <BR><BR>
072 * Note that at the time this control was written, the latest version of the
073 * specification may be found in draft-zeilenga-ldap-noop-11.  This version of
074 * the document does not explicitly specify either the OID that should be used
075 * for the control, or the result code that should be used for the associated
076 * operation if all other processing is completed successfully but no changes
077 * are made as a result of this control.  Until such time as these are defined,
078 * this implementation uses the OID temporarily assigned for its use by the
079 * OpenLDAP Foundation, which is used by at least the OpenLDAP, OpenDS, and the
080 * Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 Directory Server
081 * implementations.
082 * <BR><BR>
083 * <H2>Example</H2>
084 * The following example demonstrates the process for attempting to perform a
085 * modify operation including the LDAP no-op control so that the change is not
086 * actually applied:
087 * <PRE>
088 * ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com",
089 *      new Modification(ModificationType.REPLACE, "description",
090 *           "new value"));
091 * modifyRequest.addControl(new DraftZeilengaLDAPNoOp12RequestControl());
092 *
093 * try
094 * {
095 *   LDAPResult result = connection.modify(modifyRequest);
096 *   if (result.getResultCode() == ResultCode.NO_OPERATION)
097 *   {
098 *     // The modification would likely have succeeded if the no-op control
099 *     // hadn't been included in the request.
100 *   }
101 *   else
102 *   {
103 *     // The modification would likely have failed if the no-op control
104 *     // hadn't been included in the request.
105 *   }
106 * }
107 * catch (LDAPException le)
108 * {
109 *   // The modification failed even with the no-op control in the request.
110 * }
111 * </PRE>
112 */
113@NotMutable()
114@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
115public final class DraftZeilengaLDAPNoOp12RequestControl
116       extends Control
117{
118  /**
119   * The OID (1.3.6.1.4.1.4203.1.10.2) for the LDAP no-op request control.
120   */
121  public static final String NO_OP_REQUEST_OID =
122       "1.3.6.1.4.1.4203.1.10.2";
123
124
125
126  /**
127   * The serial version UID for this serializable class.
128   */
129  private static final long serialVersionUID = -7435407787971958294L;
130
131
132
133  /**
134   * Creates a new no-op request control.  It will be marked critical, as
135   * required by the control specification.
136   */
137  public DraftZeilengaLDAPNoOp12RequestControl()
138  {
139    super(NO_OP_REQUEST_OID, true, null);
140  }
141
142
143
144  /**
145   * Creates a new no-op request control which is decoded from the provided
146   * generic control.
147   *
148   * @param  control  The generic control to be decoded as a no-op request
149   *                  control.
150   *
151   * @throws  LDAPException  If the provided control cannot be decoded as a
152   *                         no-op request control.
153   */
154  public DraftZeilengaLDAPNoOp12RequestControl(final Control control)
155         throws LDAPException
156  {
157    super(control);
158
159    if (control.hasValue())
160    {
161      throw new LDAPException(ResultCode.DECODING_ERROR,
162                              ERR_NOOP_REQUEST_HAS_VALUE.get());
163    }
164  }
165
166
167
168  /**
169   * {@inheritDoc}
170   */
171  @Override()
172  public String getControlName()
173  {
174    return INFO_CONTROL_NAME_NOOP_REQUEST.get();
175  }
176
177
178
179  /**
180   * {@inheritDoc}
181   */
182  @Override()
183  public void toString(final StringBuilder buffer)
184  {
185    buffer.append("NoOpRequestControl(isCritical=");
186    buffer.append(isCritical());
187    buffer.append(')');
188  }
189}