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-2015 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 /** 042 * ControlDecoder implementation to decode this control from a ByteString. 043 */ 044 private static final class Decoder 045 implements ControlDecoder<PasswordPolicyRequestControl> 046 { 047 /** {@inheritDoc} */ 048 public PasswordPolicyRequestControl decode(boolean isCritical, 049 ByteString value) 050 throws DirectoryException 051 { 052 if (value != null) 053 { 054 LocalizableMessage message = ERR_PWPOLICYREQ_CONTROL_HAS_VALUE.get(); 055 throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message); 056 } 057 058 059 return new PasswordPolicyRequestControl(isCritical); 060 } 061 062 public String getOID() 063 { 064 return OID_PASSWORD_POLICY_CONTROL; 065 } 066 067 } 068 069 /** 070 * The Control Decoder that can be used to decode this control. 071 */ 072 public static final ControlDecoder<PasswordPolicyRequestControl> DECODER = 073 new Decoder(); 074 075 076 /** 077 * Creates a new instance of the password policy request control with the 078 * default settings. 079 */ 080 public PasswordPolicyRequestControl() 081 { 082 this(false); 083 084 } 085 086 087 088 /** 089 * Creates a new instance of the password policy request control with the 090 * provided information. 091 * 092 * @param isCritical Indicates whether support for this control should be 093 * considered a critical part of the client processing. 094 */ 095 public PasswordPolicyRequestControl(boolean isCritical) 096 { 097 super(OID_PASSWORD_POLICY_CONTROL, isCritical); 098 099 } 100 101 102 103 /** 104 * Writes this control's value to an ASN.1 writer. The value (if any) must be 105 * written as an ASN1OctetString. 106 * 107 * @param writer The ASN.1 output stream to write to. 108 * @throws IOException If a problem occurs while writing to the stream. 109 */ 110 @Override 111 public void writeValue(ASN1Writer writer) throws IOException { 112 // No value element. 113 } 114 115 116 117 /** 118 * Appends a string representation of this password policy request control to 119 * the provided buffer. 120 * 121 * @param buffer The buffer to which the information should be appended. 122 */ 123 @Override 124 public void toString(StringBuilder buffer) 125 { 126 buffer.append("PasswordPolicyRequestControl()"); 127 } 128} 129