001/*
002 * Copyright 2009-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-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.controls;
037
038
039
040import com.unboundid.asn1.ASN1OctetString;
041import com.unboundid.ldap.sdk.Control;
042import com.unboundid.util.NotMutable;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
047
048
049
050/**
051 * This class provides an implementation of a Directory Server control that may
052 * be used to indicate that the associated operation is used for performing some
053 * administrative operation within the server rather than one that was requested
054 * by a "normal" client.  The server can use this indication to treat the
055 * operation differently (e.g., exclude it from the processing time histogram,
056 * or to include additional information about the purpose of the operation in
057 * the access log).
058 * <BR>
059 * <BLOCKQUOTE>
060 *   <B>NOTE:</B>  This class, and other classes within the
061 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
062 *   supported for use against Ping Identity, UnboundID, and
063 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
064 *   for proprietary functionality or for external specifications that are not
065 *   considered stable or mature enough to be guaranteed to work in an
066 *   interoperable way with other types of LDAP servers.
067 * </BLOCKQUOTE>
068 * <BR>
069 * This request control has an OID of 1.3.6.1.4.1.30221.2.5.11 and a criticality
070 * of false.  It may optionally have a value that is simply the bytes that
071 * comprise the message to include in the control.
072 */
073@NotMutable()
074@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
075public final class AdministrativeOperationRequestControl
076       extends Control
077{
078  /**
079   * The OID (1.3.6.1.4.1.30221.2.5.11) for the administrative operation request
080   * control.
081   */
082  public static final String ADMINISTRATIVE_OPERATION_REQUEST_OID =
083       "1.3.6.1.4.1.30221.2.5.11";
084
085
086
087  /**
088   * The serial version UID for this serializable class.
089   */
090  private static final long serialVersionUID = 4958642483402677725L;
091
092
093
094  // The informational message to include in the control, if defined.
095  private final String message;
096
097
098
099  /**
100   * Creates a new administrative operation request control with no message.
101   */
102  public AdministrativeOperationRequestControl()
103  {
104    this((String) null);
105  }
106
107
108
109  /**
110   * Creates a new administrative operation request control with the provided
111   * informational message.
112   *
113   * @param  message  A message with additional information about the purpose of
114   *                  the associated operation.  It may be {@code null} if no
115   *                  additional message should be provided.
116   */
117  public AdministrativeOperationRequestControl(final String message)
118  {
119    super(ADMINISTRATIVE_OPERATION_REQUEST_OID, false, encodeValue(message));
120
121    this.message = message;
122  }
123
124
125
126  /**
127   * Creates a new administrative operation request control decoded from the
128   * provided generic control.
129   *
130   * @param  control  The generic control to be decoded as an administrative
131   *                  operation request control.
132   */
133  public AdministrativeOperationRequestControl(final Control control)
134  {
135    super(control);
136
137    if (control.hasValue())
138    {
139      message = control.getValue().stringValue();
140    }
141    else
142    {
143      message = null;
144    }
145  }
146
147
148
149  /**
150   * Generates an appropriately-encoded value for this control with the provided
151   * message.
152   *
153   * @param  message  A message with additional information about the purpose of
154   *                  the associated operation.  It may be {@code null} if no
155   *                  additional message should be provided.
156   *
157   * @return  An appropriately-encoded value for this control, or {@code null}
158   *          if no value is needed.
159   */
160  private static ASN1OctetString encodeValue(final String message)
161  {
162    if (message == null)
163    {
164      return null;
165    }
166    else
167    {
168      return new ASN1OctetString(message);
169    }
170  }
171
172
173
174  /**
175   * Retrieves the informational message for this control, if defined.
176   *
177   * @return  The informational message for this control, or {@code null} if
178   *          none was provided.
179   */
180  public String getMessage()
181  {
182    return message;
183  }
184
185
186
187  /**
188   * {@inheritDoc}
189   */
190  @Override()
191  public String getControlName()
192  {
193    return INFO_CONTROL_NAME_ADMINISTRATIVE_OPERATION_REQUEST.get();
194  }
195
196
197
198  /**
199   * {@inheritDoc}
200   */
201  @Override()
202  public void toString(final StringBuilder buffer)
203  {
204    buffer.append("AdministrativeOperationRequestControl(");
205
206    if (message != null)
207    {
208      buffer.append("message='");
209      buffer.append(message);
210      buffer.append('\'');
211    }
212
213    buffer.append(')');
214  }
215}