001/*
002 * Copyright 2008-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-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) 2008-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 an LDAP control that can be used to
057 * request that the Directory Server ignore the NO-USER-MODIFICATION flag for
058 * attribute types.  It may be included in an add request to allow the client to
059 * include attributes which are not normally allowed to be externally specified
060 * (e.g., entryUUID, creatorsName, modifiersName, etc.).  This control does not
061 * have a value, and there is no corresponding response control.
062 * <BR>
063 * <BLOCKQUOTE>
064 *   <B>NOTE:</B>  This class, and other classes within the
065 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
066 *   supported for use against Ping Identity, UnboundID, and
067 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
068 *   for proprietary functionality or for external specifications that are not
069 *   considered stable or mature enough to be guaranteed to work in an
070 *   interoperable way with other types of LDAP servers.
071 * </BLOCKQUOTE>
072 * <BR>
073 * <H2>Example</H2>
074 * The following example demonstrates the process for attempting to perform an
075 * add operation including the ignore NO-USER-MODIFICATION control so that an
076 * entry can be added which already includes the creatorsName and
077 * createTimestamp attributes:
078 * <PRE>
079 * AddRequest addRequest = new AddRequest("dc=example,dc=com",
080 *      new Attribute("objectClass", "top", "domain"),
081 *      new Attribute("dc", "example"),
082 *      new Attribute("creatorsName", "cn=Admin User DN"),
083 *      new Attribute("createTimestamp", "20080101000000Z"));
084 * addRequest.addControl(new IgnoreNoUserModificationRequestControl());
085 *
086 * try
087 * {
088 *   LDAPResult result = connection.add(addRequest);
089 *   // The entry was added successfully.
090 * }
091 * catch (LDAPException le)
092 * {
093 *   // The attempt to add the entry failed.
094 * }
095 * </PRE>
096 */
097@NotMutable()
098@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
099public final class IgnoreNoUserModificationRequestControl
100       extends Control
101{
102  /**
103   * The OID (1.3.6.1.4.1.30221.2.5.5) for the ignore NO-USER-MODIFICATION
104   * request control.
105   */
106  @NotNull public static final String IGNORE_NO_USER_MODIFICATION_REQUEST_OID =
107       "1.3.6.1.4.1.30221.2.5.5";
108
109
110
111  /**
112   * The serial version UID for this serializable class.
113   */
114  private static final long serialVersionUID = 2622432059171073555L;
115
116
117
118  /**
119   * Creates a new ignore NO-USER-MODIFICATION request control.  It will be
120   * marked critical.
121   */
122  public IgnoreNoUserModificationRequestControl()
123  {
124    this(true);
125  }
126
127
128
129  /**
130   * Creates a new ignore NO-USER-MODIFICATION request control with the given
131   * criticality.
132   *
133   * @param  isCritical  Indicates whether the control should be considered
134   *                     critical.
135   */
136  public IgnoreNoUserModificationRequestControl(final boolean isCritical)
137  {
138    super(IGNORE_NO_USER_MODIFICATION_REQUEST_OID, isCritical, null);
139  }
140
141
142
143  /**
144   * Creates a new ignore NO-USER-MODIFICATION request control which is decoded
145   * from the provided generic control.
146   *
147   * @param  control  The generic control to be decoded as an ignore
148   *                  NO-USER-MODIFICATION request control.
149   *
150   * @throws  LDAPException  If the provided control cannot be decoded as an
151   *                         ignore NO-USER-MODIFICATION request control.
152   */
153  public IgnoreNoUserModificationRequestControl(@NotNull final Control control)
154         throws LDAPException
155  {
156    super(control);
157
158    if (control.hasValue())
159    {
160      throw new LDAPException(ResultCode.DECODING_ERROR,
161                              ERR_IGNORENUM_REQUEST_HAS_VALUE.get());
162    }
163  }
164
165
166
167  /**
168   * {@inheritDoc}
169   */
170  @Override()
171  @NotNull()
172  public String getControlName()
173  {
174    return INFO_CONTROL_NAME_IGNORE_NO_USER_MODIFICATION_REQUEST.get();
175  }
176
177
178
179  /**
180   * Retrieves a representation of this ignore NO-USER-MODIFICATION request
181   * control as a JSON object.  The JSON object uses the following fields (note
182   * that since this control does not have a value, neither the
183   * {@code value-base64} nor {@code value-json} fields may be present):
184   * <UL>
185   *   <LI>
186   *     {@code oid} -- A mandatory string field whose value is the object
187   *     identifier for this control.  For the ignore NO-USER-MODIFICATION
188   *     request control, the OID is "1.3.6.1.4.1.30221.2.5.5".
189   *   </LI>
190   *   <LI>
191   *     {@code control-name} -- An optional string field whose value is a
192   *     human-readable name for this control.  This field is only intended for
193   *     descriptive purposes, and when decoding a control, the {@code oid}
194   *     field should be used to identify the type of control.
195   *   </LI>
196   *   <LI>
197   *     {@code criticality} -- A mandatory Boolean field used to indicate
198   *     whether this control is considered critical.
199   *   </LI>
200   * </UL>
201   *
202   * @return  A JSON object that contains a representation of this control.
203   */
204  @Override()
205  @NotNull()
206  public JSONObject toJSONControl()
207  {
208    return new JSONObject(
209         new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID,
210              IGNORE_NO_USER_MODIFICATION_REQUEST_OID),
211         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME,
212              INFO_CONTROL_NAME_IGNORE_NO_USER_MODIFICATION_REQUEST.get()),
213         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY,
214              isCritical()));
215  }
216
217
218
219  /**
220   * Attempts to decode the provided object as a JSON representation of an
221   * ignore NO-USER-MODIFICATION request control.
222   *
223   * @param  controlObject  The JSON object to be decoded.  It must not be
224   *                        {@code null}.
225   * @param  strict         Indicates whether to use strict mode when decoding
226   *                        the provided JSON object.  If this is {@code true},
227   *                        then this method will throw an exception if the
228   *                        provided JSON object contains any unrecognized
229   *                        fields.  If this is {@code false}, then unrecognized
230   *                        fields will be ignored.
231   *
232   * @return  The ignore NO-USER-MODIFICATION request control that was decoded
233   *          from the provided JSON object.
234   *
235   * @throws  LDAPException  If the provided JSON object cannot be parsed as a
236   *                         valid ignore NO-USER-MODIFICATION request control.
237   */
238  @NotNull()
239  public static IgnoreNoUserModificationRequestControl decodeJSONControl(
240              @NotNull final JSONObject controlObject,
241              final boolean strict)
242         throws LDAPException
243  {
244    final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper(
245         controlObject, strict, false, false);
246
247    return new IgnoreNoUserModificationRequestControl(
248         jsonControl.getCriticality());
249  }
250
251
252
253  /**
254   * {@inheritDoc}
255   */
256  @Override()
257  public void toString(@NotNull final StringBuilder buffer)
258  {
259    buffer.append("IgnoreNoUserModificationRequestControl(isCritical=");
260    buffer.append(isCritical());
261    buffer.append(')');
262  }
263}