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