001/*
002 * Copyright 2015-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2015-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) 2015-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.unboundidds;
037
038
039
040import com.unboundid.ldap.sdk.Entry;
041import com.unboundid.ldap.sdk.LDAPException;
042import com.unboundid.ldap.sdk.LDAPInterface;
043import com.unboundid.ldap.sdk.RootDSE;
044import com.unboundid.util.NotMutable;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048
049
050/**
051 * This class provides an enhanced implementation of the {@link RootDSE} class
052 * that provides access to additional attributes that may be included in the
053 * root DSE of a Ping Identity, UnboundID, or Nokia/Alcatel-Lucent 8661 server.
054 * <BR>
055 * <BLOCKQUOTE>
056 *   <B>NOTE:</B>  This class, and other classes within the
057 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
058 *   supported for use against Ping Identity, UnboundID, and
059 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
060 *   for proprietary functionality or for external specifications that are not
061 *   considered stable or mature enough to be guaranteed to work in an
062 *   interoperable way with other types of LDAP servers.
063 * </BLOCKQUOTE>
064 */
065@NotMutable()
066@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
067public final class UnboundIDRootDSE
068       extends RootDSE
069{
070  /**
071   * The name of the attribute that provides a digest of the base configuration
072   * for the software version the server is currently running.
073   */
074  public static final String ATTR_BASELINE_CONFIG_DIGEST =
075       "baselineConfigurationDigest";
076
077
078
079  /**
080   * The name of the attribute that provides a digest of the configuration model
081   * for the software version the server is currently running.
082   */
083  public static final String ATTR_CONFIG_MODEL_DIGEST =
084       "configurationModelDigest";
085
086
087
088  /**
089   * The name of the attribute that provides a the unique instance name for the
090   * server instance.
091   */
092  public static final String ATTR_INSTANCE_NAME = "ds-instance-name";
093
094
095
096  /**
097   * The name of the attribute that includes the DNs of the private naming
098   * contexts defined in the server.  These are base DNs that provide some
099   * content in the UnboundID server, but do not house user-provided data that
100   * is expected to be accessed by normal clients.
101   */
102  public static final String ATTR_PRIVATE_NAMING_CONTEXTS =
103       "ds-private-naming-contexts";
104
105
106
107  /**
108   * The name of the attribute that includes unique identifier generated at
109   * server startup, and can be used to determine whether an instance has been
110   * restarted.
111   */
112  public static final String ATTR_STARTUP_UUID = "startupUUID";
113
114
115
116  /**
117   * The name of the attribute that includes the one-time password delivery
118   * mechanisms supported for use in the server.
119   */
120  public static final String ATTR_SUPPORTED_OTP_DELIVERY_MECHANISM =
121       "ds-supported-otp-delivery-mechanism";
122
123
124
125  /**
126   * The set of request attributes to use when attempting to retrieve the server
127   * root DSE.  It will attempt to retrieve all operational attributes if the
128   * server supports that capability, but will also attempt to retrieve specific
129   * attributes by name in case it does not.
130   */
131  private static final String[] REQUEST_ATTRS;
132  static
133  {
134    final String[] superAttrs = RootDSE.REQUEST_ATTRS;
135    REQUEST_ATTRS = new String[superAttrs.length + 6];
136    System.arraycopy(superAttrs, 0, REQUEST_ATTRS, 0, superAttrs.length);
137
138    int i = superAttrs.length;
139    REQUEST_ATTRS[i++] = ATTR_BASELINE_CONFIG_DIGEST;
140    REQUEST_ATTRS[i++] = ATTR_CONFIG_MODEL_DIGEST;
141    REQUEST_ATTRS[i++] = ATTR_INSTANCE_NAME;
142    REQUEST_ATTRS[i++] = ATTR_PRIVATE_NAMING_CONTEXTS;
143    REQUEST_ATTRS[i++] = ATTR_STARTUP_UUID;
144    REQUEST_ATTRS[i++] = ATTR_SUPPORTED_OTP_DELIVERY_MECHANISM;
145  }
146
147
148
149  /**
150   * The serial version UID for this serializable class.
151   */
152  private static final long serialVersionUID = 2555047334281707615L;
153
154
155
156  /**
157   * Creates a new UnboundID root DSE object from the information in the
158   * provided entry.
159   *
160   * @param  rootDSEEntry  The entry to use to create this UnboundID root DSE
161   *                       object.  It must not be {@code null}.
162   */
163  public UnboundIDRootDSE(final Entry rootDSEEntry)
164  {
165    super(rootDSEEntry);
166  }
167
168
169
170  /**
171   * Retrieves the root DSE from an UnboundID server using the provided
172   * connection.
173   *
174   * @param  connection  The connection to use to retrieve the server root DSE.
175   *
176   * @return The UnboundID server root DSE, or {@code null} if it is not
177   *          available (e.g., the client does not have permission to read the
178   *          entry).
179   *
180   * @throws LDAPException  If a problem occurs while attempting to retrieve
181   *                         the server root DSE.
182   */
183  public static UnboundIDRootDSE getRootDSE(final LDAPInterface connection)
184       throws LDAPException
185  {
186    final Entry rootDSEEntry = connection.getEntry("", REQUEST_ATTRS);
187    if (rootDSEEntry == null)
188    {
189      return null;
190    }
191
192    return new UnboundIDRootDSE(rootDSEEntry);
193  }
194
195
196
197  /**
198   * Retrieves a digest of the baseline configuration for the software version
199   * the server is currently running.
200   *
201   * @return The server's baseline configuration digest, or {@code null} if
202   *          that information is not available.
203   */
204  public String getBaselineConfigurationDigest()
205  {
206    return getAttributeValue(ATTR_BASELINE_CONFIG_DIGEST);
207  }
208
209
210
211  /**
212   * Retrieves a digest of the configuration model for the software version the
213   * server is currently running.
214   *
215   * @return The server's configuration model digest, or {@code null} if that
216   *          information is not available.
217   */
218  public String getConfigurationModelDigest()
219  {
220    return getAttributeValue(ATTR_CONFIG_MODEL_DIGEST);
221  }
222
223
224
225  /**
226   * Retrieves the unique name assigned to the server instance.
227   *
228   * @return The unique name assigned to the server instance, or {@code null}
229   *          if that information is not available.
230   */
231  public String getInstanceName()
232  {
233    return getAttributeValue(ATTR_INSTANCE_NAME);
234  }
235
236
237
238  /**
239   * Retrieves the DNs of the private naming contexts, which identify base DNs
240   * for content in the server that is not intended to be accessed by normal
241   * clients but instead provides some alternate function like administration
242   * or monitoring.
243   *
244   * @return The DNs of the private naming contexts, or {@code null} if that
245   *          information is not available.
246   */
247  public String[] getPrivateNamingContexts()
248  {
249    return getAttributeValues(ATTR_PRIVATE_NAMING_CONTEXTS);
250  }
251
252
253
254  /**
255   * Retrieves a unique identifier that the server generated at startup and can
256   * be used to determine whether a server has been restarted.
257   *
258   * @return The server's startup UUID, or {@code null} if that information is
259   *          not available.
260   */
261  public String getStartupUUID()
262  {
263    return getAttributeValue(ATTR_STARTUP_UUID);
264  }
265
266
267
268  /**
269   * Retrieves the names of the supported one-time password delivery mechanisms.
270   *
271   * @return The names of the supported one-time password delivery mechanisms,
272   *          or {@code null} if that information is not available.
273   */
274  public String[] getSupportedOTPDeliveryMechanisms()
275  {
276    return getAttributeValues(ATTR_SUPPORTED_OTP_DELIVERY_MECHANISM);
277  }
278
279
280
281  /**
282   * Indicates whether the directory server indicates that it supports the
283   * specified one-time password delivery mechanism.
284   *
285   * @param  mechanismName  The name of the delivery mechanism for which to make
286   *                        the determination.  It must not be {@code null}.
287   *
288   * @return  {@code true} if the server indicates that it supports the
289   *          specified one-time password delivery mechanism, or {@code false}
290   *          if it does not.
291   */
292  public boolean supportsOTPDeliveryMechanism(final String mechanismName)
293  {
294    return hasAttributeValue(ATTR_SUPPORTED_OTP_DELIVERY_MECHANISM,
295         mechanismName);
296  }
297}