001/*
002 * Copyright 2019 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2019 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.controls;
022
023
024
025import com.unboundid.ldap.sdk.Control;
026import com.unboundid.ldap.sdk.LDAPException;
027import com.unboundid.ldap.sdk.ResultCode;
028import com.unboundid.util.NotMutable;
029import com.unboundid.util.ThreadSafety;
030import com.unboundid.util.ThreadSafetyLevel;
031
032import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
033
034
035
036/**
037 * This class provides a request control that can be included in an add request
038 * to indicate that the server should generate a password for the new account.
039 * If the add operation is processed successfully, then the generated password
040 * will be included in the {@link GeneratePasswordResponseControl} in the add
041 * result.
042 * <BR>
043 * <BLOCKQUOTE>
044 *   <B>NOTE:</B>  This class, and other classes within the
045 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
046 *   supported for use against Ping Identity, UnboundID, and
047 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
048 *   for proprietary functionality or for external specifications that are not
049 *   considered stable or mature enough to be guaranteed to work in an
050 *   interoperable way with other types of LDAP servers.
051 * </BLOCKQUOTE>
052 * <BR>
053 * The OID for this control is 1.3.6.1.4.1.30221.2.5.58, the criticality may be
054 * either {@code true} or {@code false}, and it does not have a value.
055 *
056 * @see  GeneratePasswordResponseControl
057 */
058@NotMutable()
059@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
060public final class GeneratePasswordRequestControl
061       extends Control
062{
063  /**
064   * The OID (1.3.6.1.4.1.30221.2.5.58) for the generate password request
065   * control.
066   */
067  public static final  String GENERATE_PASSWORD_REQUEST_OID =
068       "1.3.6.1.4.1.30221.2.5.58";
069
070
071
072  /**
073   * The serial version UID for this serializable class.
074   */
075  private static final long serialVersionUID = 5302210626500743525L;
076
077
078
079  /**
080   * Creates a new generate password request control.  It will be marked
081   * critical.
082   */
083  public GeneratePasswordRequestControl()
084  {
085    this(true);
086  }
087
088
089
090  /**
091   * Creates a new generate password request control with the specified
092   * criticality.
093   *
094   * @param  isCritical  Indicates whether this control should be marked
095   *                     critical.
096   */
097  public GeneratePasswordRequestControl(final boolean isCritical)
098  {
099    super(GENERATE_PASSWORD_REQUEST_OID, isCritical,  null);
100  }
101
102
103
104  /**
105   * Creates a new generate password request control which is decoded from the
106   * provided generic control.
107   *
108   * @param  control  The generic control to be decoded as a generate password
109   *                  request control.
110   *
111   * @throws  LDAPException  If the provided control cannot be decoded as a
112   *                         generate password request control.
113   */
114  public GeneratePasswordRequestControl(final Control control)
115         throws LDAPException
116  {
117    super(control);
118
119    if (control.hasValue())
120    {
121      throw new LDAPException(ResultCode.DECODING_ERROR,
122           ERR_GENERATE_PASSWORD_REQUEST_HAS_VALUE.get());
123    }
124  }
125
126
127
128  /**
129   * {@inheritDoc}
130   */
131  @Override()
132  public String getControlName()
133  {
134    return INFO_CONTROL_NAME_GENERATE_PASSWORD_REQUEST.get();
135  }
136
137
138
139  /**
140   * {@inheritDoc}
141   */
142  @Override()
143  public void toString(final StringBuilder buffer)
144  {
145    buffer.append("GeneratePasswordRequestControl(isCritical=");
146    buffer.append(isCritical());
147    buffer.append(')');
148  }
149}