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;
018
019import static org.opends.messages.ProtocolMessages.*;
020import static org.opends.server.util.ServerConstants.*;
021
022import java.io.IOException;
023
024import org.forgerock.i18n.LocalizableMessage;
025import org.forgerock.opendj.io.ASN1Writer;
026import org.forgerock.opendj.ldap.ByteString;
027import org.forgerock.opendj.ldap.ResultCode;
028import org.opends.server.types.Control;
029import org.opends.server.types.DirectoryException;
030
031/**
032 * This class implements the Sun-defined account usable request control.  The
033 * OID for this control is 1.3.6.1.4.1.42.2.27.9.5.8, and it does not have a
034 * value.
035 */
036public class AccountUsableRequestControl
037       extends Control
038{
039  /** ControlDecoder implementation to decode this control from a ByteString. */
040  private static final class Decoder
041      implements ControlDecoder<AccountUsableRequestControl>
042  {
043    @Override
044    public AccountUsableRequestControl decode(boolean isCritical,
045                                              ByteString value)
046           throws DirectoryException
047    {
048      if (value != null)
049      {
050        LocalizableMessage message = ERR_ACCTUSABLEREQ_CONTROL_HAS_VALUE.get();
051        throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message);
052      }
053
054
055      return new AccountUsableRequestControl(isCritical);
056    }
057
058    @Override
059    public String getOID()
060    {
061      return OID_ACCOUNT_USABLE_CONTROL;
062    }
063
064  }
065
066  /** The Control Decoder that can be used to decode this control. */
067  public static final ControlDecoder<AccountUsableRequestControl> DECODER =
068    new Decoder();
069
070  /** Creates a new instance of the account usable request control with the default settings. */
071  public AccountUsableRequestControl()
072  {
073    this(false);
074  }
075
076  /**
077   * Creates a new instance of the account usable request control with the
078   * default settings.
079   *
080   * @param  isCritical  Indicates whether this control should be
081   *                     considered critical in processing the
082   *                     request.
083   */
084  public AccountUsableRequestControl(boolean isCritical)
085  {
086    super(OID_ACCOUNT_USABLE_CONTROL, isCritical);
087  }
088
089  @Override
090  protected void writeValue(ASN1Writer writer) throws IOException {
091    // No value element.
092  }
093
094  @Override
095  public void toString(StringBuilder buffer)
096  {
097    buffer.append("AccountUsableRequestControl()");
098  }
099}
100