001/*
002 * Copyright 2020-2021 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2020-2021 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) 2020-2021 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.controls;
037
038
039
040import com.unboundid.ldap.sdk.Control;
041import com.unboundid.ldap.sdk.LDAPException;
042import com.unboundid.ldap.sdk.ResultCode;
043import com.unboundid.util.NotMutable;
044import com.unboundid.util.NotNull;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048import static com.unboundid.ldap.sdk.controls.ControlMessages.*;
049
050
051
052/**
053 * This class provides an implementation of the LDAP subentries request control
054 * as defined in draft-ietf-ldup-subentry.  It may be included in a search
055 * request to indicate that the entries with the {@code ldapSubentry} object
056 * class should be included in the search results.
057 * <BR><BR>
058 * Entries containing the {@code ldapSubentry} object class are special in that
059 * they are normally excluded from search results, unless the target entry is
060 * requested with a base-level search.  They are used to store operational
061 * information that controls how the server should behave rather than user data.
062 * Because they do not hold user data, it is generally desirable to have them
063 * excluded from search results, but for cases in which a client needs to
064 * retrieve such an entry, then this subentries request control may be included
065 * in the search request.  This control differs from the
066 * {@link RFC3672SubentriesRequestControl} in that it will cause only entries
067 * with the {@code ldapSubEntry} object class to be returned, while the
068 * {@code RFC3672SubentriesRequestControl} may optionally return both regular
069 * entries and subentries.
070 * <BR><BR>
071 * There is no corresponding response control.
072 * <BR><BR>
073 * <H2>Example</H2>
074 * The following example illustrates the use of the subentries request control
075 * to retrieve subentries that may not otherwise be returned.
076 * <PRE>
077 * // First, perform a search to retrieve an entry with a cn of "test subentry"
078 * // but without including the subentries request control.  This should not
079 * // return any matching entries.
080 * SearchRequest searchRequest = new SearchRequest("dc=example,dc=com",
081 *      SearchScope.SUB, Filter.createEqualityFilter("cn", "test subentry"));
082 * SearchResult resultWithoutControl = connection.search(searchRequest);
083 * LDAPTestUtils.assertResultCodeEquals(resultWithoutControl,
084 *      ResultCode.SUCCESS);
085 * LDAPTestUtils.assertEntriesReturnedEquals(resultWithoutControl, 0);
086 *
087 * // Update the search request to add a subentries request control so that
088 * // subentries should be included in search results.  This should cause the
089 * // subentry to be returned.
090 * searchRequest.addControl(new DraftLDUPSubentriesRequestControl());
091 * SearchResult resultWithControl = connection.search(searchRequest);
092 * LDAPTestUtils.assertResultCodeEquals(resultWithControl, ResultCode.SUCCESS);
093 * LDAPTestUtils.assertEntriesReturnedEquals(resultWithControl, 1);
094 * </PRE>
095 *
096 * @see  RFC3672SubentriesRequestControl
097 */
098@NotMutable()
099@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
100public final class DraftLDUPSubentriesRequestControl
101       extends Control
102{
103  /**
104   * The OID (1.3.6.1.4.1.7628.5.101.1) for the LDAP subentries request control.
105   */
106  @NotNull public static final String SUBENTRIES_REQUEST_OID =
107       "1.3.6.1.4.1.7628.5.101.1";
108
109
110
111  /**
112   * The serial version UID for this serializable class.
113   */
114  private static final long serialVersionUID = 4772130172594841481L;
115
116
117
118  /**
119   * Creates a new subentries request control.  it will not be marked critical.
120   */
121  public DraftLDUPSubentriesRequestControl()
122  {
123    this(false);
124  }
125
126
127
128  /**
129   * Creates a new subentries request control with the specified criticality.
130   *
131   * @param  isCritical  Indicates whether this control should be marked
132   *                     critical.
133   */
134  public DraftLDUPSubentriesRequestControl(final boolean isCritical)
135  {
136    super(SUBENTRIES_REQUEST_OID, isCritical, null);
137  }
138
139
140
141  /**
142   * Creates a new subentries request control which is decoded from the provided
143   * generic control.
144   *
145   * @param  control  The generic control to be decoded as a subentries request
146   *                  control.
147   *
148   * @throws  LDAPException  If the provided control cannot be decoded as a
149   *                         subentries request control.
150   */
151  public DraftLDUPSubentriesRequestControl(@NotNull final Control control)
152         throws LDAPException
153  {
154    super(control);
155
156    if (control.hasValue())
157    {
158      throw new LDAPException(ResultCode.DECODING_ERROR,
159                              ERR_SUBENTRIES_HAS_VALUE.get());
160    }
161  }
162
163
164
165  /**
166   * {@inheritDoc}
167   */
168  @Override()
169  @NotNull()
170  public String getControlName()
171  {
172    return INFO_CONTROL_NAME_SUBENTRIES_REQUEST.get();
173  }
174
175
176
177  /**
178   * {@inheritDoc}
179   */
180  @Override()
181  public void toString(@NotNull final StringBuilder buffer)
182  {
183    buffer.append("DraftLDUPSubentriesRequestControl(isCritical=");
184    buffer.append(isCritical());
185    buffer.append(')');
186  }
187}