001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.controls;
018import org.forgerock.i18n.LocalizableMessage;
019
020
021
022import org.forgerock.opendj.io.ASN1Writer;
023import org.forgerock.opendj.ldap.ByteString;
024import org.opends.server.types.Control;
025import org.opends.server.types.DirectoryException;
026import org.forgerock.opendj.ldap.ResultCode;
027
028import static org.opends.messages.ProtocolMessages.*;
029import static org.opends.server.util.ServerConstants.*;
030
031import java.io.IOException;
032
033
034/**
035 * This class implements the password policy request control defined in
036 * draft-behera-ldap-password-policy.  It does not have a value.
037 */
038public class PasswordPolicyRequestControl
039       extends Control
040{
041  /** ControlDecoder implementation to decode this control from a ByteString. */
042  private static final class Decoder
043      implements ControlDecoder<PasswordPolicyRequestControl>
044  {
045    @Override
046    public PasswordPolicyRequestControl decode(boolean isCritical,
047                                               ByteString value)
048        throws DirectoryException
049    {
050      if (value != null)
051      {
052        LocalizableMessage message = ERR_PWPOLICYREQ_CONTROL_HAS_VALUE.get();
053        throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message);
054      }
055
056
057      return new PasswordPolicyRequestControl(isCritical);
058    }
059
060    @Override
061    public String getOID()
062    {
063      return OID_PASSWORD_POLICY_CONTROL;
064    }
065
066  }
067
068  /** The Control Decoder that can be used to decode this control. */
069  public static final ControlDecoder<PasswordPolicyRequestControl> DECODER =
070    new Decoder();
071
072
073  /** Creates a new instance of the password policy request control with the default settings. */
074  public PasswordPolicyRequestControl()
075  {
076    this(false);
077
078  }
079
080
081
082  /**
083   * Creates a new instance of the password policy request control with the
084   * provided information.
085   *
086   * @param  isCritical  Indicates whether support for this control should be
087   *                     considered a critical part of the client processing.
088   */
089  public PasswordPolicyRequestControl(boolean isCritical)
090  {
091    super(OID_PASSWORD_POLICY_CONTROL, isCritical);
092
093  }
094
095  @Override
096  public void writeValue(ASN1Writer writer) throws IOException {
097    // No value element.
098  }
099
100  @Override
101  public void toString(StringBuilder buffer)
102  {
103    buffer.append("PasswordPolicyRequestControl()");
104  }
105}
106