001/*
002 * Copyright 2015-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2015-2024 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) 2015-2024 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.JSONControlDecodeHelper;
042import com.unboundid.ldap.sdk.LDAPException;
043import com.unboundid.ldap.sdk.ResultCode;
044import com.unboundid.util.NotMutable;
045import com.unboundid.util.NotNull;
046import com.unboundid.util.ThreadSafety;
047import com.unboundid.util.ThreadSafetyLevel;
048import com.unboundid.util.json.JSONField;
049import com.unboundid.util.json.JSONObject;
050
051import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
052
053
054
055/**
056 * This class provides an implementation of the name with entryUUID request
057 * control.  It may be included in an add request to indicate that the server
058 * should replace the provided RDN with the server-generated entryUUID value.
059 * It will also cause the server to include a
060 * {@link com.unboundid.ldap.sdk.controls.PostReadResponseControl} in
061 * the add result to make the generated DN available to the client.  If the
062 * request already includes a
063 * {@link com.unboundid.ldap.sdk.controls.PostReadRequestControl}, then the
064 * attributes included in the post-read response control will be generated from
065 * that request control.  Otherwise, the server will behave as if the request
066 * had included a post-read request control requesting only the entryUUID
067 * attribute.
068 * <BR>
069 * <BLOCKQUOTE>
070 *   <B>NOTE:</B>  This class, and other classes within the
071 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
072 *   supported for use against Ping Identity, UnboundID, and
073 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
074 *   for proprietary functionality or for external specifications that are not
075 *   considered stable or mature enough to be guaranteed to work in an
076 *   interoperable way with other types of LDAP servers.
077 * </BLOCKQUOTE>
078 * <BR>
079 * This control has an OID of "1.3.6.1.4.1.30221.2.5.44".  It is recommended
080 * that it be used with a criticality of {@code true}.  It does not take a
081 * value.
082 */
083@NotMutable()
084@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
085public final class NameWithEntryUUIDRequestControl
086       extends Control
087{
088  /**
089   * The OID (1.3.6.1.4.1.30221.2.5.44) for the name with entryUUID request
090   * control.
091   */
092  @NotNull public static final String NAME_WITH_ENTRY_UUID_REQUEST_OID =
093       "1.3.6.1.4.1.30221.2.5.44";
094
095
096
097  /**
098   * The serial version UID for this serializable class.
099   */
100  private static final long serialVersionUID = -1083494935823253033L;
101
102
103
104  /**
105   * Creates a new name with entryUUID request control.  It will be marked
106   * critical.
107   */
108  public NameWithEntryUUIDRequestControl()
109  {
110    this(true);
111  }
112
113
114
115  /**
116   * Creates a new name with entryUUID request control with the specified
117   * criticality.
118   *
119   * @param  isCritical  Indicates whether this control should be marked
120   *                     critical.
121   */
122  public NameWithEntryUUIDRequestControl(final boolean isCritical)
123  {
124    super(NAME_WITH_ENTRY_UUID_REQUEST_OID, isCritical, null);
125  }
126
127
128
129  /**
130   * Creates a new name with entryUUID request control which is decoded from the
131   * provided generic control.
132   *
133   * @param  control  The generic control to be decoded as a name with entryUUID
134   *                  request control.
135   *
136   * @throws LDAPException  If the provided control cannot be decoded as a name
137   *                         with entryUUID request control.
138   */
139  public NameWithEntryUUIDRequestControl(@NotNull final Control control)
140       throws LDAPException
141  {
142    super(control);
143
144    if (control.hasValue())
145    {
146      throw new LDAPException(ResultCode.DECODING_ERROR,
147           ERR_NAME_WITH_ENTRY_UUID_REQUEST_HAS_VALUE.get());
148    }
149  }
150
151
152
153  /**
154   * {@inheritDoc}
155   */
156  @Override()
157  @NotNull()
158  public String getControlName()
159  {
160    return INFO_CONTROL_NAME_WITH_ENTRY_UUID_REQUEST.get();
161  }
162
163
164
165  /**
166   * Retrieves a representation of this name with entryUUID request control as a
167   * JSON object.  The JSON object uses the following fields (note that since
168   * this control does not have a value, neither the {@code value-base64} nor
169   * {@code value-json} fields may be present):
170   * <UL>
171   *   <LI>
172   *     {@code oid} -- A mandatory string field whose value is the object
173   *     identifier for this control.  For the name with entryUUID request
174   *     control, the OID is "1.3.6.1.4.1.30221.2.5.44".
175   *   </LI>
176   *   <LI>
177   *     {@code control-name} -- An optional string field whose value is a
178   *     human-readable name for this control.  This field is only intended for
179   *     descriptive purposes, and when decoding a control, the {@code oid}
180   *     field should be used to identify the type of control.
181   *   </LI>
182   *   <LI>
183   *     {@code criticality} -- A mandatory Boolean field used to indicate
184   *     whether this control is considered critical.
185   *   </LI>
186   * </UL>
187   *
188   * @return  A JSON object that contains a representation of this control.
189   */
190  @Override()
191  @NotNull()
192  public JSONObject toJSONControl()
193  {
194    return new JSONObject(
195         new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID,
196              NAME_WITH_ENTRY_UUID_REQUEST_OID),
197         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME,
198              INFO_CONTROL_NAME_WITH_ENTRY_UUID_REQUEST.get()),
199         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY,
200              isCritical()));
201  }
202
203
204
205  /**
206   * Attempts to decode the provided object as a JSON representation of a name
207   * with entryUUID request control.
208   *
209   * @param  controlObject  The JSON object to be decoded.  It must not be
210   *                        {@code null}.
211   * @param  strict         Indicates whether to use strict mode when decoding
212   *                        the provided JSON object.  If this is {@code true},
213   *                        then this method will throw an exception if the
214   *                        provided JSON object contains any unrecognized
215   *                        fields.  If this is {@code false}, then unrecognized
216   *                        fields will be ignored.
217   *
218   * @return  The name with entryUUID request control that was decoded from
219   *          the provided JSON object.
220   *
221   * @throws  LDAPException  If the provided JSON object cannot be parsed as a
222   *                         valid name with entryUUID request control.
223   */
224  @NotNull()
225  public static NameWithEntryUUIDRequestControl decodeJSONControl(
226              @NotNull final JSONObject controlObject,
227              final boolean strict)
228         throws LDAPException
229  {
230    final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper(
231         controlObject, strict, false, false);
232
233    return new NameWithEntryUUIDRequestControl(
234         jsonControl.getCriticality());
235  }
236
237
238
239  /**
240   * {@inheritDoc}
241   */
242  @Override()
243  public void toString(@NotNull final StringBuilder buffer)
244  {
245    buffer.append("NameWithEntryUUIDRequestControl(isCritical=");
246    buffer.append(isCritical());
247    buffer.append(')');
248  }
249}