001/*
002 * Copyright 2007-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-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) 2007-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.experimental;
037
038
039
040import com.unboundid.ldap.sdk.Control;
041import com.unboundid.ldap.sdk.LDAPException;
042import com.unboundid.ldap.sdk.ResultCode;
043import com.unboundid.util.NotMutable;
044import com.unboundid.util.NotNull;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*;
049
050
051
052/**
053 * This class provides an implementation of the password policy request control
054 * as described in draft-behera-ldap-password-policy-10.  It may be used to
055 * request information related to a user's password policy.  In the Ping
056 * Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 Directory Server, this
057 * control may be included with add, bind, compare, modify, and password modify
058 * requests.
059 * <BR><BR>
060 * The corresponding {@link DraftBeheraLDAPPasswordPolicy10ResponseControl} may
061 * include at most one warning from the set of
062 * {@link DraftBeheraLDAPPasswordPolicy10WarningType} values and at most one
063 * error from the set of {@link DraftBeheraLDAPPasswordPolicy10ErrorType}
064 * values.  See the documentation for those classes for more information on the
065 * information that may be included.
066 * <BR><BR>
067 * <H2>Example</H2>
068 * The following example demonstrates the use of the password policy request
069 * control in conjunction with a bind operation:
070 * <PRE>
071 * SimpleBindRequest bindRequest = new SimpleBindRequest(
072 *      "uid=john.doe,ou=People,dc=example,dc=com", "password",
073 *      new DraftBeheraLDAPPasswordPolicy10RequestControl());
074 *
075 * BindResult bindResult;
076 * try
077 * {
078 *   bindResult = connection.bind(bindRequest);
079 * }
080 * catch (LDAPException le)
081 * {
082 *   // The bind failed.  There may be a password policy response control to
083 *   // help tell us why.
084 *   bindResult = new BindResult(le.toLDAPResult());
085 * }
086 *
087 * DraftBeheraLDAPPasswordPolicy10ResponseControl pwpResponse =
088 *      DraftBeheraLDAPPasswordPolicy10ResponseControl.get(bindResult);
089 * if (pwpResponse != null)
090 * {
091 *   DraftBeheraLDAPPasswordPolicy10ErrorType errorType =
092 *        pwpResponse.getErrorType();
093 *   if (errorType != null)
094 *   {
095 *     // There was a password policy error.
096 *   }
097 *
098 *   DraftBeheraLDAPPasswordPolicy10WarningType warningType =
099 *        pwpResponse.getWarningType();
100 *   if (warningType != null)
101 *   {
102 *     // There was a password policy warning.
103 *     int value = pwpResponse.getWarningValue();
104 *     switch (warningType)
105 *     {
106 *       case TIME_BEFORE_EXPIRATION:
107 *         // The warning value is the number of seconds until expiration.
108 *         break;
109 *       case GRACE_LOGINS_REMAINING:
110 *         // The warning value is the number of grace logins remaining.
111 *     }
112 *   }
113 * }
114 * </PRE>
115 */
116@NotMutable()
117@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
118public final class DraftBeheraLDAPPasswordPolicy10RequestControl
119       extends Control
120{
121  /**
122   * The OID (1.3.6.1.4.1.42.2.27.8.5.1) for the password policy request
123   * control.
124   */
125  @NotNull public static final String PASSWORD_POLICY_REQUEST_OID =
126       "1.3.6.1.4.1.42.2.27.8.5.1";
127
128
129
130  /**
131   * The serial version UID for this serializable class.
132   */
133  private static final long serialVersionUID = 6495056761590890150L;
134
135
136
137  /**
138   * Creates a new password policy request control.  The control will not be
139   * marked critical.
140   */
141  public DraftBeheraLDAPPasswordPolicy10RequestControl()
142  {
143    super(PASSWORD_POLICY_REQUEST_OID, false, null);
144  }
145
146
147
148  /**
149   * Creates a new password policy request control.
150   *
151   * @param  isCritical  Indicates whether the control should be marked
152   * critical.
153   */
154  public DraftBeheraLDAPPasswordPolicy10RequestControl(final boolean isCritical)
155  {
156    super(PASSWORD_POLICY_REQUEST_OID, isCritical, null);
157  }
158
159
160
161  /**
162   * Creates a new password policy request control which is decoded from the
163   * provided generic control.
164   *
165   * @param  control  The generic control to be decoded as a password policy
166   *                  request control.
167   *
168   * @throws  LDAPException  If the provided control cannot be decoded as a
169   *                         password policy request control.
170   */
171  public DraftBeheraLDAPPasswordPolicy10RequestControl(
172              @NotNull final Control control)
173         throws LDAPException
174  {
175    super(control);
176
177    if (control.hasValue())
178    {
179      throw new LDAPException(ResultCode.DECODING_ERROR,
180                              ERR_PWP_REQUEST_HAS_VALUE.get());
181    }
182  }
183
184
185
186  /**
187   * {@inheritDoc}
188   */
189  @Override()
190  @NotNull()
191  public String getControlName()
192  {
193    return INFO_CONTROL_NAME_PW_POLICY_REQUEST.get();
194  }
195
196
197
198  /**
199   * {@inheritDoc}
200   */
201  @Override()
202  public void toString(@NotNull final StringBuilder buffer)
203  {
204    buffer.append("PasswordPolicyRequestControl(isCritical=");
205    buffer.append(isCritical());
206    buffer.append(')');
207  }
208}