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