com.unboundid.ldap.sdk.unboundidds.extensions.GetPasswordQualityRequirementsExtendedRequest Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of unboundid-ldapsdk-commercial-edition Show documentation
                Show all versions of unboundid-ldapsdk-commercial-edition Show documentation
      The UnboundID LDAP SDK for Java is a fast, comprehensive, and easy-to-use
      Java API for communicating with LDAP directory servers and performing
      related tasks like reading and writing LDIF, encoding and decoding data
      using base64 and ASN.1 BER, and performing secure communication.  This
      package contains the Commercial Edition of the LDAP SDK, which includes
      all of the general-purpose functionality contained in the Standard
      Edition, plus additional functionality specific to UnboundID server
      products.
    
                
            /*
 * Copyright 2015-2016 UnboundID Corp.
 * All Rights Reserved.
 */
/*
 * Copyright (C) 2015-2016 UnboundID Corp.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (GPLv2 only)
 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see .
 */
package com.unboundid.ldap.sdk.unboundidds.extensions;
import com.unboundid.asn1.ASN1Element;
import com.unboundid.asn1.ASN1OctetString;
import com.unboundid.asn1.ASN1Null;
import com.unboundid.asn1.ASN1Sequence;
import com.unboundid.ldap.sdk.Control;
import com.unboundid.ldap.sdk.ExtendedRequest;
import com.unboundid.ldap.sdk.ExtendedResult;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.util.Debug;
import com.unboundid.util.NotMutable;
import com.unboundid.util.StaticUtils;
import com.unboundid.util.ThreadSafety;
import com.unboundid.util.ThreadSafetyLevel;
import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
/**
 * 
 *   NOTE:  This class is part of the Commercial Edition of the UnboundID
 *   LDAP SDK for Java.  It is not available for use in applications that
 *   include only the Standard Edition of the LDAP SDK, and is not supported for
 *   use in conjunction with non-UnboundID products.
 * 
 * This class provides an implementation of an extended request that may be used
 * to retrieve the set of password quality requirements that the Directory
 * Server will impose for a specified operation, which may include adding a new
 * user (including a password), a user changing his/her own password (a self
 * change), or one user changing the password for another user (an
 * administrative reset).
 * 
 * This extended request has an OID of 1.3.6.1.4.1.30221.2.6.43 and a value with
 * the following encoding:
 * 
 *   GetPasswordQualityRequirementsRequestValue ::= SEQUENCE {
 *        target     CHOICE {
 *             addWithDefaultPasswordPolicy           [0] NULL,
 *             addWithSpecifiedPasswordPolicy         [1] LDAPDN,
 *             selfChangeForAuthorizationIdentity     [2] NULL,
 *             selfChangeForSpecifiedUser             [3] LDAPDN,
 *             administrativeResetForUser             [4] LDAPDN,
 *             ... },
 *        ... }
 * 
 */
@NotMutable()
@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
public final class GetPasswordQualityRequirementsExtendedRequest
       extends ExtendedRequest
{
  /**
   * The OID (1.3.6.1.4.1.30221.2.6.43) for the get password quality
   * requirements extended request.
   */
  public static final String OID_GET_PASSWORD_QUALITY_REQUIREMENTS_REQUEST =
       "1.3.6.1.4.1.30221.2.6.43";
  /**
   * The serial version UID for this serializable class.
   */
  private static final long serialVersionUID = -3652010872400265557L;
  // The target type for this get password quality requirements extended
  // request.
  private final GetPasswordQualityRequirementsTargetType targetType;
  // The target DN for this get password quality requirements extended request.
  private final String targetDN;
  /**
   * Creates a new get password quality requirements extended request with the
   * provided information.
   *
   * @param  targetType  The target type for this request.  It must not be
   *                     {@code null}.
   * @param  targetDN    The target DN for this request.  It may be {@code null}
   *                     if no target DN is required for the specified target
   *                     type.
   * @param  controls    The set of controls to include in the request.  It may
   *                     be {@code null} or empty if no controls should be
   *                     included.
   */
  private GetPasswordQualityRequirementsExtendedRequest(
               final GetPasswordQualityRequirementsTargetType targetType,
               final String targetDN,
               final Control... controls)
  {
    super(OID_GET_PASSWORD_QUALITY_REQUIREMENTS_REQUEST,
         encodeValue(targetType, targetDN), controls);
    this.targetType = targetType;
    this.targetDN   = targetDN;
  }
  /**
   * Creates a new get password quality requirements extended request decoded
   * from the provided generic extended request.
   *
   * @param  r  The extended request to decode as a get password quality
   *            requirements request.
   *
   * @throws  LDAPException  If a problem is encountered while attempting to
   *                         decoded the provided extended request as a
   *                         get password quality requirements request.
   */
  public GetPasswordQualityRequirementsExtendedRequest(final ExtendedRequest r)
         throws LDAPException
  {
    super(r);
    final ASN1OctetString value = r.getValue();
    if (value == null)
    {
      throw new LDAPException(ResultCode.DECODING_ERROR,
           ERR_GET_PW_QUALITY_REQS_REQUEST_NO_VALUE.get());
    }
    try
    {
      final ASN1Element[] elements =
           ASN1Sequence.decodeAsSequence(value.getValue()).elements();
      targetType = GetPasswordQualityRequirementsTargetType.forBERType(
           elements[0].getType());
      if (targetType == null)
      {
        throw new LDAPException(ResultCode.DECODING_ERROR,
             ERR_GET_PW_QUALITY_REQS_REQUEST_UNKNOWN_TARGET_TYPE.get(
                  StaticUtils.toHex(elements[0].getType())));
      }
      switch (targetType)
      {
        case ADD_WITH_SPECIFIED_PASSWORD_POLICY:
        case SELF_CHANGE_FOR_SPECIFIED_USER:
        case ADMINISTRATIVE_RESET_FOR_SPECIFIED_USER:
          targetDN = ASN1OctetString.decodeAsOctetString(
               elements[0]).stringValue();
          break;
        case ADD_WITH_DEFAULT_PASSWORD_POLICY:
        case SELF_CHANGE_FOR_AUTHORIZATION_IDENTITY:
        default:
          targetDN = null;
          break;
      }
    }
    catch (final LDAPException le)
    {
      Debug.debugException(le);
      throw le;
    }
    catch (final Exception e)
    {
      Debug.debugException(e);
      throw new LDAPException(ResultCode.DECODING_ERROR,
           ERR_GET_PW_QUALITY_REQS_REQUEST_CANNOT_DECODE.get(
                StaticUtils.getExceptionMessage(e)),
           e);
    }
  }
  /**
   * Encodes the provided information into an ASN.1 octet string suitable for
   * use as the value of this extended request.
   *
   * @param  targetType  The target type for this request.  It must not be
   *                     {@code null}.
   * @param  targetDN    The target DN for this request.  It may be {@code null}
   *                     if no target DN is required for the specified target
   *                     type.
   *
   * @return  The ASN.1 octet string containing the encoded request value.
   */
  private static ASN1OctetString encodeValue(
                      final GetPasswordQualityRequirementsTargetType targetType,
                      final String targetDN)
  {
    final ASN1Element targetElement;
    switch (targetType)
    {
      case ADD_WITH_SPECIFIED_PASSWORD_POLICY:
      case SELF_CHANGE_FOR_SPECIFIED_USER:
      case ADMINISTRATIVE_RESET_FOR_SPECIFIED_USER:
        targetElement = new ASN1OctetString(targetType.getBERType(), targetDN);
        break;
      case ADD_WITH_DEFAULT_PASSWORD_POLICY:
      case SELF_CHANGE_FOR_AUTHORIZATION_IDENTITY:
      default:
        targetElement = new ASN1Null(targetType.getBERType());
        break;
    }
    final ASN1Sequence valueSequence = new ASN1Sequence(
         targetElement);
    return new ASN1OctetString(valueSequence.encode());
  }
  /**
   * Creates a new get password quality requirements extended request that will
   * retrieve the password requirements for an add operation governed by the
   * server's default password policy.
   *
   * @param  controls  The set of controls to include in the request.  It may be
   *                   {@code null} or empty if no controls should be included
   *                   in the request.
   *
   * @return  A new get password quality requirements extended request that will
   *          retrieve the password requirements for an add operation governed
   *          by the server's default password policy.
   */
  public static GetPasswordQualityRequirementsExtendedRequest
                     createAddWithDefaultPasswordPolicyRequest(
                          final Control... controls)
  {
    return new GetPasswordQualityRequirementsExtendedRequest(
         GetPasswordQualityRequirementsTargetType.
              ADD_WITH_DEFAULT_PASSWORD_POLICY,
         null, controls);
  }
  /**
   * Creates a new get password quality requirements extended request that will
   * retrieve the password requirements for an add operation governed by the
   * specified password policy.
   *
   * @param  policyDN  The DN of the entry that defines the password policy from
   *                   which to determine the password quality requirements.
   * @param  controls  The set of controls to include in the request.  It may be
   *                   {@code null} or empty if no controls should be included
   *                   in the request.
   *
   * @return  A new get password quality requirements extended request that will
   *          retrieve the password requirements for an add operation governed
   *          by the specified password policy.
   */
  public static GetPasswordQualityRequirementsExtendedRequest
                     createAddWithSpecifiedPasswordPolicyRequest(
                          final String policyDN, final Control... controls)
  {
    return new GetPasswordQualityRequirementsExtendedRequest(
         GetPasswordQualityRequirementsTargetType.
              ADD_WITH_SPECIFIED_PASSWORD_POLICY,
         policyDN, controls);
  }
  /**
   * Creates a new get password quality requirements extended request that will
   * retrieve the password requirements for a self change requested with the
   * same authorization identity as this extended request.
   *
   * @param  controls  The set of controls to include in the request.  It may be
   *                   {@code null} or empty if no controls should be included
   *                   in the request.
   *
   * @return  A new get password quality requirements extended request that will
   *          retrieve the password requirements for a self change requested
   *          with the same authorization identity as this extended request.
   */
  public static GetPasswordQualityRequirementsExtendedRequest
                     createSelfChangeWithSameAuthorizationIdentityRequest(
                          final Control... controls)
  {
    return new GetPasswordQualityRequirementsExtendedRequest(
         GetPasswordQualityRequirementsTargetType.
              SELF_CHANGE_FOR_AUTHORIZATION_IDENTITY,
         null, controls);
  }
  /**
   * Creates a new get password quality requirements extended request that will
   * retrieve the password requirements for a self change requested by the
   * specified user.
   *
   * @param  userDN    The DN of the user for whom to retrieve the self change
   *                   password requirements.
   * @param  controls  The set of controls to include in the request.  It may be
   *                   {@code null} or empty if no controls should be included
   *                   in the request.
   *
   * @return  A new get password quality requirements extended request that will
   *          retrieve the password requirements for a self change requested by
   *          the specified user.
   */
  public static GetPasswordQualityRequirementsExtendedRequest
                     createSelfChangeForSpecifiedUserRequest(
                          final String userDN, final Control... controls)
  {
    return new GetPasswordQualityRequirementsExtendedRequest(
         GetPasswordQualityRequirementsTargetType.
              SELF_CHANGE_FOR_SPECIFIED_USER,
         userDN, controls);
  }
  /**
   * Creates a new get password quality requirements extended request that will
   * retrieve the password requirements for an administrative reset targeting
   * the specified user.
   *
   * @param  userDN    The DN of the user for whom to retrieve the
   *                   administrative reset password requirements.
   * @param  controls  The set of controls to include in the request.  It may be
   *                   {@code null} or empty if no controls should be included
   *                   in the request.
   *
   * @return  A new get password quality requirements extended request that will
   *          retrieve the password requirements for an administrative reset
   *          targeting the specified user.
   */
  public static GetPasswordQualityRequirementsExtendedRequest
                     createAdministrativeResetForSpecifiedUserRequest(
                          final String userDN, final Control... controls)
  {
    return new GetPasswordQualityRequirementsExtendedRequest(
         GetPasswordQualityRequirementsTargetType.
              ADMINISTRATIVE_RESET_FOR_SPECIFIED_USER,
         userDN, controls);
  }
  /**
   * Retrieves the target type for this get password quality requirements
   * request.
   *
   * @return  The target type for this get password quality requirements
   *          request.
   */
  public GetPasswordQualityRequirementsTargetType getTargetType()
  {
    return targetType;
  }
  /**
   * Retrieves the target DN for this get password quality requirements request.
   * For a request with a target type of
   * {@code ADD_WITH_SPECIFIED_PASSWORD_POLICY}, this will be the DN of the
   * password policy from which to obtain the password quality requirements.
   * For a request with a target type of either
   * {@code SELF_CHANGE_FOR_SPECIFIED_USER} or
   * {@code ADMINISTRATIVE_RESET_FOR_SPECIFIED_USER}, this will be the DN of the
   * user for which to obtain the password quality requirements.  For a request
   * with a target type of either {@code ADD_WITH_DEFAULT_PASSWORD_POLICY} or
   * {@code SELF_CHANGE_FOR_AUTHORIZATION_IDENTITY}, no target DN is required
   * and the value returned will be {@code null}.
   *
   * @return  The target DN for this get password quality requirements request.
   */
  public String getTargetDN()
  {
    return targetDN;
  }
  /**
   * {@inheritDoc}
   */
  @Override()
  public GetPasswordQualityRequirementsExtendedResult process(
              final LDAPConnection connection, final int depth)
         throws LDAPException
  {
    final ExtendedResult result = super.process(connection, depth);
    return new GetPasswordQualityRequirementsExtendedResult(result);
  }
  /**
   * {@inheritDoc}
   */
  @Override()
  public GetPasswordQualityRequirementsExtendedRequest duplicate()
  {
    return duplicate(getControls());
  }
  /**
   * {@inheritDoc}
   */
  @Override()
  public GetPasswordQualityRequirementsExtendedRequest duplicate(
              final Control[] controls)
  {
    final GetPasswordQualityRequirementsExtendedRequest r =
         new GetPasswordQualityRequirementsExtendedRequest(targetType,
              targetDN, controls);
    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
    return r;
  }
  /**
   * {@inheritDoc}
   */
  @Override()
  public String getExtendedRequestName()
  {
    return INFO_EXTENDED_REQUEST_NAME_GET_PW_QUALITY_REQS.get();
  }
  /**
   * {@inheritDoc}
   */
  @Override()
  public void toString(final StringBuilder buffer)
  {
    buffer.append("GetPasswordQualityRequirementsExtendedRequest(targetType=");
    buffer.append(targetType.name());
    if (targetDN != null)
    {
      buffer.append(", targetDN='");
      buffer.append(targetDN);
      buffer.append('\'');
    }
    final Control[] controls = getControls();
    if (controls.length > 0)
    {
      buffer.append(", controls={");
      for (int i=0; i < controls.length; i++)
      {
        if (i > 0)
        {
          buffer.append(", ");
        }
        buffer.append(controls[i]);
      }
      buffer.append('}');
    }
    buffer.append(')');
  }
}
     © 2015 - 2025 Weber Informatics LLC | Privacy Policy