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 a control which can be used to
057 * request that the Directory Server include extended information when returning
058 * a subschema subentry.  In the Ping Identity, UnboundID, and
059 * Nokia/Alcatel-Lucent 8661 Directory Server, this will cause the server to
060 * include the X-SCHEMA-FILE extension (which contains the path to the file in
061 * which that schema element is defined) and the X-READ-ONLY extension (which
062 * indicates whether that schema element is read-only and cannot be altered by
063 * external clients).
064 * <BR>
065 * <BLOCKQUOTE>
066 *   <B>NOTE:</B>  This class, and other classes within the
067 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
068 *   supported for use against Ping Identity, UnboundID, and
069 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
070 *   for proprietary functionality or for external specifications that are not
071 *   considered stable or mature enough to be guaranteed to work in an
072 *   interoperable way with other types of LDAP servers.
073 * </BLOCKQUOTE>
074 * <BR>
075 * This control is not based on any public specification, and has been defined
076 * by Ping Identity Corporation  It does not have a value, and may or may not be
077 * critical.  It should only be included in search requests.
078 * <BR><BR>
079 * <H2>Example</H2>
080 * The following example demonstrates the procedure to use for requesting the
081 * Directory Server schema with extended information.  Note that the
082 * {@code LDAPInterface.getSchema} and {@code Schema.getSchema} convenience
083 * methods cannot be used because they do not allow you to include controls in
084 * the request.
085 * <PRE>
086 * String schemaDN = Schema.getSubschemaSubentryDN(connection, "");
087 * SearchRequest searchRequest = new SearchRequest(schemaDN, SearchScope.BASE,
088 *      Filter.createPresenceFilter("objectClass"), "*", "+");
089 * searchRequest.addControl(new ExtendedSchemaInfoRequestControl());
090 * SearchResult searchResult = connection.search(searchRequest);
091 *
092 * Schema schema = null;
093 * if (searchResult.getEntryCount() == 1)
094 * {
095 *   schema = new Schema(searchResult.getSearchEntries().get(0));
096 * }
097 * </PRE>
098 */
099@NotMutable()
100@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
101public final class ExtendedSchemaInfoRequestControl
102       extends Control
103{
104  /**
105   * The OID (1.3.6.1.4.1.30221.2.5.12) for the extended schema info request
106   * control.
107   */
108  @NotNull public static final String EXTENDED_SCHEMA_INFO_REQUEST_OID =
109       "1.3.6.1.4.1.30221.2.5.12";
110
111
112  /**
113   * The serial version UID for this serializable class.
114   */
115  private static final long serialVersionUID = -5668945270252160026L;
116
117
118
119  /**
120   * Creates a new extended schema info request control.  It will not be
121   * marked critical.
122   */
123  public ExtendedSchemaInfoRequestControl()
124  {
125    this(false);
126  }
127
128
129
130  /**
131   * Creates a new extended schema info request control with the specified
132   * criticality.
133   *
134   * @param  isCritical  Indicates whether this control should be marked
135   *                     critical.
136   */
137  public ExtendedSchemaInfoRequestControl(final boolean isCritical)
138  {
139    super(EXTENDED_SCHEMA_INFO_REQUEST_OID, isCritical, null);
140  }
141
142
143
144  /**
145   * Creates a new extended schema info request control which is decoded from
146   * the provided generic control.
147   *
148   * @param  control  The generic control to be decoded as an extended schema
149   *                  info request control.
150   *
151   * @throws  LDAPException  If the provided control cannot be decoded as an
152   *                         extended schema info request control.
153   */
154  public ExtendedSchemaInfoRequestControl(@NotNull 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_EXTENDED_SCHEMA_INFO_REQUEST_HAS_VALUE.get());
163    }
164  }
165
166
167
168  /**
169   * {@inheritDoc}
170   */
171  @Override()
172  @NotNull()
173  public String getControlName()
174  {
175    return INFO_CONTROL_NAME_EXTENDED_SCHEMA_INFO.get();
176  }
177
178
179
180  /**
181   * Retrieves a representation of this extended schema info request control as
182   * a JSON object.  The JSON object uses the following fields (note that since
183   * this control does not have a value, neither the {@code value-base64} nor
184   * {@code value-json} fields may be present):
185   * <UL>
186   *   <LI>
187   *     {@code oid} -- A mandatory string field whose value is the object
188   *     identifier for this control.  For the extended scheam info request
189   *     control, the OID is "1.3.6.1.4.1.30221.2.5.12".
190   *   </LI>
191   *   <LI>
192   *     {@code control-name} -- An optional string field whose value is a
193   *     human-readable name for this control.  This field is only intended for
194   *     descriptive purposes, and when decoding a control, the {@code oid}
195   *     field should be used to identify the type of control.
196   *   </LI>
197   *   <LI>
198   *     {@code criticality} -- A mandatory Boolean field used to indicate
199   *     whether this control is considered critical.
200   *   </LI>
201   * </UL>
202   *
203   * @return  A JSON object that contains a representation of this control.
204   */
205  @Override()
206  @NotNull()
207  public JSONObject toJSONControl()
208  {
209    return new JSONObject(
210         new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID,
211              EXTENDED_SCHEMA_INFO_REQUEST_OID),
212         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME,
213              INFO_CONTROL_NAME_EXTENDED_SCHEMA_INFO.get()),
214         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY,
215              isCritical()));
216  }
217
218
219
220  /**
221   * Attempts to decode the provided object as a JSON representation of an
222   * extended schema info request control.
223   *
224   * @param  controlObject  The JSON object to be decoded.  It must not be
225   *                        {@code null}.
226   * @param  strict         Indicates whether to use strict mode when decoding
227   *                        the provided JSON object.  If this is {@code true},
228   *                        then this method will throw an exception if the
229   *                        provided JSON object contains any unrecognized
230   *                        fields.  If this is {@code false}, then unrecognized
231   *                        fields will be ignored.
232   *
233   * @return  The extended schema info request control that was decoded from the
234   *          provided JSON object.
235   *
236   * @throws  LDAPException  If the provided JSON object cannot be parsed as a
237   *                         valid extended schema info request control.
238   */
239  @NotNull()
240  public static ExtendedSchemaInfoRequestControl decodeJSONControl(
241              @NotNull final JSONObject controlObject,
242              final boolean strict)
243         throws LDAPException
244  {
245    final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper(
246         controlObject, strict, false, false);
247
248    return new ExtendedSchemaInfoRequestControl(
249         jsonControl.getCriticality());
250  }
251
252
253
254  /**
255   * {@inheritDoc}
256   */
257  @Override()
258  public void toString(@NotNull final StringBuilder buffer)
259  {
260    buffer.append("ExtendedSchemaInfoRequestControl(isCritical=");
261    buffer.append(isCritical());
262    buffer.append(')');
263  }
264}