001/*
002 * Copyright 2008-2019 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2019 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 an LDAP control that can be used to
038 * request that the Directory Server ignore the NO-USER-MODIFICATION flag for
039 * attribute types.  It may be included in an add request to allow the client to
040 * include attributes which are not normally allowed to be externally specified
041 * (e.g., entryUUID, creatorsName, modifiersName, etc.).  This control does not
042 * have a value, and there is no corresponding response control.
043 * <BR>
044 * <BLOCKQUOTE>
045 *   <B>NOTE:</B>  This class, and other classes within the
046 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
047 *   supported for use against Ping Identity, UnboundID, and
048 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
049 *   for proprietary functionality or for external specifications that are not
050 *   considered stable or mature enough to be guaranteed to work in an
051 *   interoperable way with other types of LDAP servers.
052 * </BLOCKQUOTE>
053 * <BR>
054 * <H2>Example</H2>
055 * The following example demonstrates the process for attempting to perform an
056 * add operation including the ignore NO-USER-MODIFICATION control so that an
057 * entry can be added which already includes the creatorsName and
058 * createTimestamp attributes:
059 * <PRE>
060 * AddRequest addRequest = new AddRequest("dc=example,dc=com",
061 *      new Attribute("objectClass", "top", "domain"),
062 *      new Attribute("dc", "example"),
063 *      new Attribute("creatorsName", "cn=Admin User DN"),
064 *      new Attribute("createTimestamp", "20080101000000Z"));
065 * addRequest.addControl(new IgnoreNoUserModificationRequestControl());
066 *
067 * try
068 * {
069 *   LDAPResult result = connection.add(addRequest);
070 *   // The entry was added successfully.
071 * }
072 * catch (LDAPException le)
073 * {
074 *   // The attempt to add the entry failed.
075 * }
076 * </PRE>
077 */
078@NotMutable()
079@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
080public final class IgnoreNoUserModificationRequestControl
081       extends Control
082{
083  /**
084   * The OID (1.3.6.1.4.1.30221.2.5.5) for the ignore NO-USER-MODIFICATION
085   * request control.
086   */
087  public static final String IGNORE_NO_USER_MODIFICATION_REQUEST_OID =
088       "1.3.6.1.4.1.30221.2.5.5";
089
090
091
092  /**
093   * The serial version UID for this serializable class.
094   */
095  private static final long serialVersionUID = 2622432059171073555L;
096
097
098
099  /**
100   * Creates a new ignore NO-USER-MODIFICATION request control.  It will be
101   * marked critical.
102   */
103  public IgnoreNoUserModificationRequestControl()
104  {
105    this(true);
106  }
107
108
109
110  /**
111   * Creates a new ignore NO-USER-MODIFICATION request control with the given
112   * criticality.
113   *
114   * @param  isCritical  Indicates whether the control should be considered
115   *                     critical.
116   */
117  public IgnoreNoUserModificationRequestControl(final boolean isCritical)
118  {
119    super(IGNORE_NO_USER_MODIFICATION_REQUEST_OID, isCritical, null);
120  }
121
122
123
124  /**
125   * Creates a new ignore NO-USER-MODIFICATION request control which is decoded
126   * from the provided generic control.
127   *
128   * @param  control  The generic control to be decoded as an ignore
129   *                  NO-USER-MODIFICATION request control.
130   *
131   * @throws  LDAPException  If the provided control cannot be decoded as an
132   *                         ignore NO-USER-MODIFICATION request control.
133   */
134  public IgnoreNoUserModificationRequestControl(final Control control)
135         throws LDAPException
136  {
137    super(control);
138
139    if (control.hasValue())
140    {
141      throw new LDAPException(ResultCode.DECODING_ERROR,
142                              ERR_IGNORENUM_REQUEST_HAS_VALUE.get());
143    }
144  }
145
146
147
148  /**
149   * {@inheritDoc}
150   */
151  @Override()
152  public String getControlName()
153  {
154    return INFO_CONTROL_NAME_IGNORE_NO_USER_MODIFICATION_REQUEST.get();
155  }
156
157
158
159  /**
160   * {@inheritDoc}
161   */
162  @Override()
163  public void toString(final StringBuilder buffer)
164  {
165    buffer.append("IgnoreNoUserModificationRequestControl(isCritical=");
166    buffer.append(isCritical());
167    buffer.append(')');
168  }
169}