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