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
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.controls;
028 import org.opends.messages.Message;
029
030
031
032 import org.opends.server.protocols.asn1.ASN1OctetString;
033 import org.opends.server.protocols.ldap.LDAPResultCode;
034 import org.opends.server.types.Control;
035 import org.opends.server.types.LDAPException;
036
037 import static org.opends.messages.ProtocolMessages.*;
038 import static org.opends.server.util.ServerConstants.*;
039
040
041
042 /**
043 * This class implements the Netscape password expired control. The value for
044 * this control should be a string that indicates the length of time until the
045 * password expires, but because it is already expired it will always be "0".
046 */
047 public class PasswordExpiredControl
048 extends Control
049 {
050 /**
051 * Creates a new instance of the password expired control with the default
052 * settings.
053 */
054 public PasswordExpiredControl()
055 {
056 super(OID_NS_PASSWORD_EXPIRED, false, new ASN1OctetString("0"));
057 }
058
059
060
061 /**
062 * Creates a new instance of the password expired control with the provided
063 * information.
064 *
065 * @param oid The OID to use for this control.
066 * @param isCritical Indicates whether support for this control should be
067 * considered a critical part of the client processing.
068 */
069 public PasswordExpiredControl(String oid, boolean isCritical)
070 {
071 super(oid, isCritical, new ASN1OctetString("0"));
072 }
073
074
075
076 /**
077 * Creates a new password expired control from the contents of the provided
078 * control.
079 *
080 * @param control The generic control containing the information to use to
081 * create this password expired control.
082 *
083 * @return The password expired control decoded from the provided control.
084 *
085 * @throws LDAPException If this control cannot be decoded as a valid
086 * password expired control.
087 */
088 public static PasswordExpiredControl decodeControl(Control control)
089 throws LDAPException
090 {
091 if (control.hasValue())
092 {
093 String valueStr = control.getValue().stringValue();
094 try
095 {
096 Integer.parseInt(valueStr);
097 }
098 catch (Exception e)
099 {
100 Message message = ERR_PWEXPIRED_CONTROL_INVALID_VALUE.get();
101 throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message);
102 }
103 }
104
105 return new PasswordExpiredControl(control.getOID(), control.isCritical());
106 }
107
108
109
110 /**
111 * Retrieves a string representation of this password expired control.
112 *
113 * @return A string representation of this password expired control.
114 */
115 public String toString()
116 {
117 StringBuilder buffer = new StringBuilder();
118 toString(buffer);
119 return buffer.toString();
120 }
121
122
123
124 /**
125 * Appends a string representation of this password expired control to the
126 * provided buffer.
127 *
128 * @param buffer The buffer to which the information should be appended.
129 */
130 public void toString(StringBuilder buffer)
131 {
132 buffer.append("PasswordExpiredControl()");
133 }
134 }
135