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