Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/controls/LDAPPasswordExpiringControl.java

raw symbols SCIP
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 is about to expire, and password policy is enabled on the server.
46 * The OID for this control is 2.16.840.1.113730.3.4.5.
47 * <P>
48 *
49 * @version 1.0
50 * @see org.ietf.ldap.LDAPControl
51 */
52 public class LDAPPasswordExpiringControl extends LDAPStringControl {
53 public final static String EXPIRING = "2.16.840.1.113730.3.4.5";
54
55 /**
56 * Contructs an <CODE>LDAPPasswordExpiringControl</CODE> object.
57 * This constructor is used by <CODE>LDAPControl.register</CODE> to
58 * instantiate password expiring controls.
59 * <P>
60 * To retrieve the number of seconds until this password expires,
61 * call <CODE>getSecondsToExpiration</CODE>.
62 * @param oid this parameter must be
63 * <CODE>LDAPPasswordExpiringControl.EXPIRING</CODE>
64 * or an <CODE>LDAPException</CODE> is thrown
65 * @param critical <code>true</code> if this control is critical
66 * @param value the value associated with this control
67 * @exception org.ietf.ldap.LDAPException If oid is not
68 * <CODE>LDAPPasswordExpiringControl.EXPIRING.</CODE>
69 * @see org.ietf.ldap.LDAPControl#register
70 */
71 public LDAPPasswordExpiringControl( String oid, boolean critical,
72 byte[] value ) throws LDAPException {
73 super( EXPIRING, critical, value );
74 if ( !oid.equals( EXPIRING )) {
75 throw new LDAPException( "oid must be LDAPPasswordExpiringControl" +
76 ".EXPIRING", LDAPException.PARAM_ERROR );
77 }
78 }
79
80 /**
81 * Gets the number of seconds until the password expires returned by the
82 * server.
83 * @return int the number of seconds until the password expires.
84 * @exception java.lang.NumberFormatException If the server returned an
85 * undecipherable message. In this case, use <CODE>getMessage</CODE> to
86 * retrieve the message as a string.
87 */
88 public int getSecondsToExpiration() {
89 return Integer.parseInt( m_msg );
90 }
91
92 /**
93 * Gets the value associated with this control parsed as a string.
94 * @return the value associated with this control parsed as a string.
95 */
96 public String getMessage() {
97 return m_msg;
98 }
99
100 /**
101 * @param controls an array of <CODE>LDAPControl</CODE> objects,
102 * representing the controls returned by the server.
103 * after a search. To get these controls, use the
104 * <CODE>getResponseControls</CODE> method of the
105 * <CODE>LDAPConnection</CODE> class.
106 * @return an error message string, or null if none is in the control.
107 * @see org.ietf.ldap.LDAPConnection#getResponseControls
108 * @deprecated LDAPPasswordExpiringControl controls are now automatically
109 * instantiated.
110 */
111 public static String parseResponse( LDAPControl[] controls ) {
112 return LDAPStringControl.parseResponse( controls, EXPIRING );
113 }
114
115 public String toString() {
116 StringBuffer sb = new StringBuffer("{PasswordExpiringCtrl:");
117
118 sb.append(" isCritical=");
119 sb.append(isCritical());
120
121 sb.append(" msg=");
122 sb.append(m_msg);
123
124 sb.append("}");
125
126 return sb.toString();
127 }
128
129 }