001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.controls;
028import org.forgerock.i18n.LocalizableMessage;
029
030
031
032import org.forgerock.opendj.io.ASN1Writer;
033import org.forgerock.opendj.ldap.ByteString;
034import org.opends.server.types.Control;
035import org.opends.server.types.DirectoryException;
036import org.forgerock.opendj.ldap.ResultCode;
037
038import static org.opends.messages.ProtocolMessages.*;
039import static org.opends.server.util.ServerConstants.*;
040
041import java.io.IOException;
042
043
044/**
045 * This class implements the password policy request control defined in
046 * draft-behera-ldap-password-policy.  It does not have a value.
047 */
048public class PasswordPolicyRequestControl
049       extends Control
050{
051  /**
052   * ControlDecoder implementation to decode this control from a ByteString.
053   */
054  private static final class Decoder
055      implements ControlDecoder<PasswordPolicyRequestControl>
056  {
057    /** {@inheritDoc} */
058    public PasswordPolicyRequestControl decode(boolean isCritical,
059                                               ByteString value)
060        throws DirectoryException
061    {
062      if (value != null)
063      {
064        LocalizableMessage message = ERR_PWPOLICYREQ_CONTROL_HAS_VALUE.get();
065        throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message);
066      }
067
068
069      return new PasswordPolicyRequestControl(isCritical);
070    }
071
072    public String getOID()
073    {
074      return OID_PASSWORD_POLICY_CONTROL;
075    }
076
077  }
078
079  /**
080   * The Control Decoder that can be used to decode this control.
081   */
082  public static final ControlDecoder<PasswordPolicyRequestControl> DECODER =
083    new Decoder();
084
085
086  /**
087   * Creates a new instance of the password policy request control with the
088   * default settings.
089   */
090  public PasswordPolicyRequestControl()
091  {
092    this(false);
093
094  }
095
096
097
098  /**
099   * Creates a new instance of the password policy request control with the
100   * provided information.
101   *
102   * @param  isCritical  Indicates whether support for this control should be
103   *                     considered a critical part of the client processing.
104   */
105  public PasswordPolicyRequestControl(boolean isCritical)
106  {
107    super(OID_PASSWORD_POLICY_CONTROL, isCritical);
108
109  }
110
111
112
113  /**
114   * Writes this control's value to an ASN.1 writer. The value (if any) must be
115   * written as an ASN1OctetString.
116   *
117   * @param writer The ASN.1 output stream to write to.
118   * @throws IOException If a problem occurs while writing to the stream.
119   */
120  @Override
121  public void writeValue(ASN1Writer writer) throws IOException {
122    // No value element.
123  }
124
125
126
127  /**
128   * Appends a string representation of this password policy request control to
129   * the provided buffer.
130   *
131   * @param  buffer  The buffer to which the information should be appended.
132   */
133  @Override
134  public void toString(StringBuilder buffer)
135  {
136    buffer.append("PasswordPolicyRequestControl()");
137  }
138}
139