| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * ***** BEGIN LICENSE BLOCK ***** |
| 4 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 5 | * |
| 6 | * The contents of this file are subject to the Mozilla Public License Version |
| 7 | * 1.1 (the "License"); you may not use this file except in compliance with |
| 8 | * the License. You may obtain a copy of the License at |
| 9 | * http://www.mozilla.org/MPL/ |
| 10 | * |
| 11 | * Software distributed under the License is distributed on an "AS IS" basis, |
| 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 | * for the specific language governing rights and limitations under the |
| 14 | * License. |
| 15 | * |
| 16 | * The Original Code is mozilla.org code. |
| 17 | * |
| 18 | * The Initial Developer of the Original Code is |
| 19 | * Netscape Communications Corporation. |
| 20 | * Portions created by the Initial Developer are Copyright (C) 1999 |
| 21 | * the Initial Developer. All Rights Reserved. |
| 22 | * |
| 23 | * Contributor(s): |
| 24 | * |
| 25 | * Alternatively, the contents of this file may be used under the terms of |
| 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
| 29 | * of those above. If you wish to allow use of your version of this file only |
| 30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
| 31 | * use your version of this file under the terms of the MPL, indicate your |
| 32 | * decision by deleting the provisions above and replace them with the notice |
| 33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
| 34 | * the provisions above, a recipient may use your version of this file under |
| 35 | * the terms of any one of the MPL, the GPL or the LGPL. |
| 36 | * |
| 37 | * ***** END LICENSE BLOCK ***** */ |
| 38 | package org.ietf.ldap.controls; |
| 39 | |
| 40 | import org.ietf.ldap.LDAPControl; |
| 41 | import org.ietf.ldap.LDAPException; |
| 42 | |
| 43 | /** |
| 44 | * Represents an LDAP v3 server control that may be returned if a |
| 45 | * password has expired, and password policy is enabled on the server. |
| 46 | * The OID for this control is 2.16.840.1.113730.3.4.4. |
| 47 | * <P> |
| 48 | * |
| 49 | * @version 1.0 |
| 50 | * @see org.ietf.ldap.LDAPControl |
| 51 | */ |
| 52 | public class LDAPPasswordExpiredControl extends LDAPStringControl { |
| 53 | public final static String EXPIRED = "2.16.840.1.113730.3.4.4"; |
| 54 | |
| 55 | /** |
| 56 | * Contructs an <CODE>LDAPPasswordExpiredControl</CODE> object. |
| 57 | * This constructor is used by <CODE>LDAPControl.register</CODE> to |
| 58 | * instantiate password expired controls. |
| 59 | * <P> |
| 60 | * To retrieve the message from the server, call <CODE>getMessage</CODE>. |
| 61 | * @param oid this parameter must be equal to |
| 62 | * <CODE>LDAPPasswordExpiredControl.EXPIRED</CODE> |
| 63 | * or an <CODE>LDAPException</CODE> is thrown |
| 64 | * @param critical <code>true</code> if this control is critical |
| 65 | * @param value the value associated with this control |
| 66 | * @exception org.ietf.ldap.LDAPException If oid is not |
| 67 | * <CODE>LDAPPasswordExpiredControl.EXPIRED</CODE>. |
| 68 | * @see org.ietf.ldap.LDAPControl#register |
| 69 | */ |
| 70 | public LDAPPasswordExpiredControl( String oid, boolean critical, |
| 71 | byte[] value ) throws LDAPException { |
| 72 | super( EXPIRED, critical, value ); |
| 73 | if ( !oid.equals( EXPIRED )) { |
| 74 | throw new LDAPException( "oid must be LDAPPasswordExpiredControl." + |
| 75 | "PWEXPIRED", LDAPException.PARAM_ERROR); |
| 76 | } |
| 77 | |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @param controls an array of <CODE>LDAPControl</CODE> objects, |
| 82 | * representing the controls returned by the server |
| 83 | * after a search. To get these controls, use the |
| 84 | * <CODE>getResponseControls</CODE> method of the |
| 85 | * <CODE>LDAPConnection</CODE> class. |
| 86 | * @return an error message string, or null if none is in the control. |
| 87 | * @see org.ietf.ldap.LDAPConnection#getResponseControls |
| 88 | * @deprecated LDAPPasswordExpiredControl controls are now automatically |
| 89 | * instantiated. |
| 90 | */ |
| 91 | public static String parseResponse( LDAPControl[] controls ) { |
| 92 | return LDAPStringControl.parseResponse( controls, EXPIRED ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Gets the message returned by the server with this control. |
| 97 | * @return the message returned by the server. |
| 98 | */ |
| 99 | public String getMessage() { |
| 100 | return m_msg; |
| 101 | } |
| 102 | |
| 103 | public String toString() { |
| 104 | StringBuffer sb = new StringBuffer("{PasswordExpiredCtrl:"); |
| 105 | |
| 106 | sb.append(" isCritical="); |
| 107 | sb.append(isCritical()); |
| 108 | |
| 109 | sb.append(" msg="); |
| 110 | sb.append(m_msg); |
| 111 | |
| 112 | sb.append("}"); |
| 113 | |
| 114 | return sb.toString(); |
| 115 | } |
| 116 | |
| 117 | } |
| 118 | |
| 119 | |
| 120 | |
| 121 |