001/*
002 * Copyright 2015-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2015-2024 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-2024 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.ldap.sdk.Control;
041import com.unboundid.ldap.sdk.JSONControlDecodeHelper;
042import com.unboundid.ldap.sdk.LDAPException;
043import com.unboundid.ldap.sdk.ResultCode;
044import com.unboundid.util.NotMutable;
045import com.unboundid.util.NotNull;
046import com.unboundid.util.ThreadSafety;
047import com.unboundid.util.ThreadSafetyLevel;
048import com.unboundid.util.json.JSONField;
049import com.unboundid.util.json.JSONObject;
050
051import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
052
053
054
055/**
056 * This class provides an implementation for a request control that can be
057 * included in an add, modify, or password modify request.  Its presence in one
058 * of those requests will indicate that the server should provide a response
059 * control with information about the password quality requirements that are in
060 * effect for the operation and information about whether the password included
061 * in the request satisfies each of those requirements.
062 * <BR>
063 * <BLOCKQUOTE>
064 *   <B>NOTE:</B>  This class, and other classes within the
065 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
066 *   supported for use against Ping Identity, UnboundID, and
067 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
068 *   for proprietary functionality or for external specifications that are not
069 *   considered stable or mature enough to be guaranteed to work in an
070 *   interoperable way with other types of LDAP servers.
071 * </BLOCKQUOTE>
072 * <BR>
073 * This request control has an OID of 1.3.6.1.4.1.30221.2.5.40, and it is
074 * recommended that the criticality be {@code false}.  It does not have a value.
075 */
076@NotMutable()
077@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
078public final class PasswordValidationDetailsRequestControl
079       extends Control
080{
081 /**
082  * The OID (1.3.6.1.4.1.30221.2.5.40) for the password validation details
083  * request control.
084  */
085 @NotNull public static final String PASSWORD_VALIDATION_DETAILS_REQUEST_OID =
086      "1.3.6.1.4.1.30221.2.5.40";
087
088
089
090 /**
091  * The serial version UID for this serializable class.
092  */
093 private static final long serialVersionUID = -956099348044171899L;
094
095
096
097  /**
098   * Creates a new password validation details request control with
099   * a criticality of {@code false}.
100   */
101  public PasswordValidationDetailsRequestControl()
102  {
103    this(false);
104  }
105
106
107
108  /**
109   * Creates a new password validation details request control with the
110   * specified criticality.
111   *
112   * @param  isCritical  Indicates whether this control should be considered
113   *                     critical.
114   */
115  public PasswordValidationDetailsRequestControl(final boolean isCritical)
116  {
117    super(PASSWORD_VALIDATION_DETAILS_REQUEST_OID, isCritical, null);
118  }
119
120
121
122  /**
123   * Creates a new password validation details request control which is decoded
124   * from the provided generic control.
125   *
126   * @param  control  The generic control to be decoded as a password validation
127   *                  details request control.
128   *
129   * @throws  LDAPException  If the provided control cannot be decoded as a
130   *                         password validation details request control.
131   */
132  public PasswordValidationDetailsRequestControl(
133              @NotNull final Control control)
134         throws LDAPException
135  {
136    super(control);
137
138    if (control.hasValue())
139    {
140      throw new LDAPException(ResultCode.DECODING_ERROR,
141                              ERR_PW_VALIDATION_REQUEST_HAS_VALUE.get());
142    }
143  }
144
145
146
147  /**
148   * {@inheritDoc}
149   */
150  @Override()
151  @NotNull()
152  public String getControlName()
153  {
154    return INFO_CONTROL_NAME_PW_VALIDATION_REQUEST.get();
155  }
156
157
158
159  /**
160   * Retrieves a representation of this password validation details request
161   * control as a JSON object.  The JSON object uses the following fields (note
162   * that since this control does not have a value, neither the
163   * {@code value-base64} nor {@code value-json} fields may be present):
164   * <UL>
165   *   <LI>
166   *     {@code oid} -- A mandatory string field whose value is the object
167   *     identifier for this control.  For the password validation details
168   *     request control, the OID is "1.3.6.1.4.1.30221.2.5.40".
169   *   </LI>
170   *   <LI>
171   *     {@code control-name} -- An optional string field whose value is a
172   *     human-readable name for this control.  This field is only intended for
173   *     descriptive purposes, and when decoding a control, the {@code oid}
174   *     field should be used to identify the type of control.
175   *   </LI>
176   *   <LI>
177   *     {@code criticality} -- A mandatory Boolean field used to indicate
178   *     whether this control is considered critical.
179   *   </LI>
180   * </UL>
181   *
182   * @return  A JSON object that contains a representation of this control.
183   */
184  @Override()
185  @NotNull()
186  public JSONObject toJSONControl()
187  {
188    return new JSONObject(
189         new JSONField(JSONControlDecodeHelper.JSON_FIELD_OID,
190              PASSWORD_VALIDATION_DETAILS_REQUEST_OID),
191         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CONTROL_NAME,
192              INFO_CONTROL_NAME_PW_VALIDATION_REQUEST.get()),
193         new JSONField(JSONControlDecodeHelper.JSON_FIELD_CRITICALITY,
194              isCritical()));
195  }
196
197
198
199  /**
200   * Attempts to decode the provided object as a JSON representation of a
201   * password validation details request control.
202   *
203   * @param  controlObject  The JSON object to be decoded.  It must not be
204   *                        {@code null}.
205   * @param  strict         Indicates whether to use strict mode when decoding
206   *                        the provided JSON object.  If this is {@code true},
207   *                        then this method will throw an exception if the
208   *                        provided JSON object contains any unrecognized
209   *                        fields.  If this is {@code false}, then unrecognized
210   *                        fields will be ignored.
211   *
212   * @return  The password validation details request control that was decoded
213   *          from the provided JSON object.
214   *
215   * @throws  LDAPException  If the provided JSON object cannot be parsed as a
216   *                         valid password validation details request control.
217   */
218  @NotNull()
219  public static PasswordValidationDetailsRequestControl decodeJSONControl(
220              @NotNull final JSONObject controlObject,
221              final boolean strict)
222         throws LDAPException
223  {
224    final JSONControlDecodeHelper jsonControl = new JSONControlDecodeHelper(
225         controlObject, strict, false, false);
226
227    return new PasswordValidationDetailsRequestControl(
228         jsonControl.getCriticality());
229  }
230
231
232
233  /**
234   * {@inheritDoc}
235   */
236  @Override()
237  public void toString(@NotNull final StringBuilder buffer)
238  {
239    buffer.append("PasswordValidationDetailsRequestControl(isCritical=");
240    buffer.append(isCritical());
241    buffer.append(')');
242  }
243}