~ubuntu-branches/ubuntu/wily/389-ds-console/wily-proposed

« back to all changes in this revision

Viewing changes to src/com/netscape/admin/dirserv/panel/AccountLockoutPanel.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-03-15 19:58:37 UTC
  • Revision ID: package-import@ubuntu.com-20120315195837-296zyft51thld8q7
Tags: upstream-1.2.6
ImportĀ upstreamĀ versionĀ 1.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** BEGIN COPYRIGHT BLOCK
 
2
 * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
 
3
 * Copyright (C) 2005 Red Hat, Inc.
 
4
 * All rights reserved.
 
5
 * 
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation version 2 of the License.
 
9
 * 
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 * 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 * END COPYRIGHT BLOCK **/
 
19
 
 
20
package com.netscape.admin.dirserv.panel;
 
21
 
 
22
import java.util.*;
 
23
import java.awt.*;
 
24
import java.awt.event.*;
 
25
import javax.swing.*;
 
26
import javax.swing.border.*;
 
27
import com.netscape.admin.dirserv.*;
 
28
import com.netscape.management.client.*;
 
29
import com.netscape.management.client.util.*;
 
30
import netscape.ldap.*;
 
31
import netscape.ldap.util.*;
 
32
 
 
33
/**
 
34
 * Panel for Directory Server account lockout settings page
 
35
 *
 
36
 * @author  rweltman
 
37
 * @version %I%, %G%
 
38
 * @date        9/15/97
 
39
 * @see     com.netscape.admin.dirserv
 
40
 */
 
41
public class AccountLockoutPanel extends BlankPanel {
 
42
    public AccountLockoutPanel(IDSModel model) {
 
43
        super(model, "accountlockout");
 
44
                _helpToken = "configuration-database-accountlockout-help";
 
45
                _refreshWhenSelect = false;
 
46
                _policyspecdn = CONFIG_DN;
 
47
    }
 
48
 
 
49
    public AccountLockoutPanel(IDSModel model, String dn, int mode) {
 
50
                super(model, "accountlockout");
 
51
                _helpToken = "configuration-browser-accountlockout-help";
 
52
                _refreshWhenSelect = false;
 
53
 
 
54
                _dn = dn;
 
55
                _mode = mode;
 
56
                _parentdn = new DN(dn).getParent().toString();
 
57
 
 
58
                _containerdn = ( _mode == FINEGRAINED_USER ?
 
59
                                                        ("cn=" + CONTAINER_CN + "," + _parentdn) :
 
60
                                                        ("cn=" + CONTAINER_CN + "," + _dn) );
 
61
 
 
62
                _policyspecdn = "cn=\"cn=" + USER_SPEC_CN + "," +
 
63
                                                _dn + "\"," + _containerdn;
 
64
 
 
65
                _costemplatedn = "cn=\"cn=" + COS_TEMPL_CN + "," +
 
66
                                                _dn + "\"," + _containerdn;
 
67
 
 
68
                _cosspecdn = "cn=" + COS_SPEC_CN + "," + _dn;
 
69
 
 
70
                // Use a DSEntrySet that doesn't complain if entry/attr are non-existant
 
71
                setDSEntrySet(new DSEntrySet(false, true));
 
72
        }
 
73
 
 
74
    public void init() {
 
75
 
 
76
                if (_isInitialized) {
 
77
                        return;
 
78
                }
 
79
        _myPanel.setLayout(new GridBagLayout());
 
80
        createLockoutArea((Container)_myPanel);
 
81
 
 
82
                addBottomGlue();                
 
83
                _isInitialized = true;
 
84
        }
 
85
 
 
86
        public void select(IResourceObject parent, IPage viewInstance) {
 
87
                if (_isInitialized && (_mode == FINEGRAINED_USER || _mode == FINEGRAINED_SUBTREE) ) {
 
88
                        _fineGrainedCheckbox = verifyFGCheckbox();
 
89
                        _cbLockout.setEnabled( _fineGrainedCheckbox );
 
90
                        enableLockout();
 
91
                        enableDuration();
 
92
                } 
 
93
                super.select(parent, viewInstance);
 
94
        } 
 
95
 
 
96
        private boolean verifyFGCheckbox() {
 
97
                boolean enabled = false;
 
98
                DSTabbedPanel tabContainer = (DSTabbedPanel)getTabbedPanel();
 
99
                PasswordPolicyPanel passwordPanel = (PasswordPolicyPanel)tabContainer._tabbedPane.getComponentAt(0);
 
100
                enabled = passwordPanel.getFGCheckboxStatus();
 
101
                return enabled;
 
102
        } 
 
103
 
 
104
    protected void createLockoutArea( Container myContainer) {
 
105
                _items = new Vector();
 
106
 
 
107
        // No Lockout checkbox
 
108
                _cbLockout = makeJCheckBox(_section , "lockout", false);
 
109
 
 
110
        JLabel lockoutAfterLabel = makeJLabel(_section, "lockoutafter");
 
111
                _items.addElement( lockoutAfterLabel );
 
112
 
 
113
        // Lockout value
 
114
        _tfLockoutValue = makeNumericalJTextField(_section, "lockoutafter2");
 
115
                lockoutAfterLabel.setLabelFor(_tfLockoutValue);
 
116
                _items.addElement( _tfLockoutValue );
 
117
 
 
118
        JLabel lockoutLabel2 = makeJLabel(_section, "lockoutafter2");
 
119
                _items.addElement( lockoutLabel2 );
 
120
 
 
121
        JLabel resetAfterLabel1 = makeJLabel(_section, "resetafter");
 
122
                _items.addElement( resetAfterLabel1 );          
 
123
 
 
124
        _tfResetAfterValue = makeNumericalJTextField(_section, "resetafter");
 
125
                resetAfterLabel1.setLabelFor(_tfResetAfterValue);
 
126
                _items.addElement( _tfResetAfterValue );
 
127
 
 
128
        JLabel resetAfterLabel2 = makeJLabel(_section, "resetafter2");
 
129
                _items.addElement( resetAfterLabel2 );
 
130
 
 
131
        ButtonGroup durationButtonGroup = new ButtonGroup();
 
132
        // Lockout Forever Radio Button
 
133
        _rbLockoutForever = makeJRadioButton(_section, "lockoutforever");
 
134
        durationButtonGroup.add(_rbLockoutForever);
 
135
                _items.addElement( _rbLockoutForever );
 
136
 
 
137
        // Lockout Minutes Radio Button
 
138
        _rbLockoutMinutes = makeJRadioButton(_section, "lockoutduration");
 
139
        durationButtonGroup.add(_rbLockoutMinutes);
 
140
                _items.addElement( _rbLockoutMinutes );
 
141
 
 
142
        _tfLockoutMinutesValue = makeNumericalJTextField(_section,
 
143
                                                "lockoutduration", null, 8);
 
144
                _items.addElement( _tfLockoutMinutesValue );
 
145
 
 
146
        _lockoutMinutesLabel = 
 
147
                        makeJLabel(_section, "lockoutduration2");
 
148
                _items.addElement( _lockoutMinutesLabel );
 
149
 
 
150
        DSEntrySet entries = getDSEntrySet();
 
151
 
 
152
                DurationEntryBoolean lockDSEntry = new DurationEntryBoolean(null, _cbLockout);
 
153
                entries.add( _policyspecdn, LOCKOUT_ATTR_NAME,
 
154
                            lockDSEntry);
 
155
                setComponentTable(_cbLockout, lockDSEntry);
 
156
 
 
157
        DSEntryInteger lockoutDSEntry =
 
158
                        new DSEntryInteger(null, _tfLockoutValue,
 
159
            lockoutAfterLabel, LOCKOUT_NUM_MIN_VAL, LOCKOUT_NUM_MAX_VAL, 1);
 
160
        entries.add( _policyspecdn, LOCKOUT_NUM_ATTR_NAME, lockoutDSEntry );
 
161
        setComponentTable(_tfLockoutValue, lockoutDSEntry);
 
162
 
 
163
        DSEntryInteger resetDSEntry =
 
164
                        new DSEntryInteger(null, _tfResetAfterValue,
 
165
                                                           resetAfterLabel1,
 
166
                                                           LOCKOUT_RESET_NUM_MIN_VAL,
 
167
                                                           DSUtil.epochConstraint(LOCKOUT_RESET_NUM_MAX_VAL, MIN_TO_DAY_FACTOR), 
 
168
                               MIN_TO_SEC_FACTOR);
 
169
        entries.add( _policyspecdn, LOCKOUT_RESET_NUM_ATTR_NAME,
 
170
            resetDSEntry );
 
171
        setComponentTable(_tfResetAfterValue, resetDSEntry);
 
172
 
 
173
                LockoutEntryBoolean lo =
 
174
                        new LockoutEntryBoolean("off", _rbLockoutMinutes);
 
175
        entries.add( _policyspecdn, LOCKOUT_FOREVER_ATTR_NAME, lo );
 
176
                setComponentTable(_rbLockoutForever, lo);
 
177
 
 
178
        DSEntryInteger lockoutDSEntry1 = new DSEntryInteger(null,
 
179
            _tfLockoutMinutesValue, _lockoutMinutesLabel,  
 
180
            LOCKOUT_DURATION_NUM_MIN_VAL, DSUtil.epochConstraint(LOCKOUT_DURATION_NUM_MAX_VAL, MIN_TO_DAY_FACTOR), 
 
181
            MIN_TO_SEC_FACTOR);
 
182
        entries.add( _policyspecdn, LOCKOUT_DURATION_NUM_ATTR_NAME,
 
183
            lockoutDSEntry1 );
 
184
        setComponentTable(_tfLockoutMinutesValue, lockoutDSEntry1);
 
185
 
 
186
        // create containers and layouts
 
187
        JPanel lockoutPanel = (JPanel)myContainer;
 
188
        GridBagConstraints gbc = getGBC();
 
189
        gbc.anchor = gbc.WEST;
 
190
        gbc.fill = gbc.NONE;
 
191
        gbc.weightx = 1.0;
 
192
                gbc.gridwidth = gbc.REMAINDER;
 
193
        lockoutPanel.add(_cbLockout, gbc);
 
194
        gbc.fill = gbc.HORIZONTAL;
 
195
 
 
196
        // Lockout Area Container
 
197
        JPanel lockoutSubPanel =
 
198
                        new GroupPanel( _resource.getString(_section,
 
199
                                                                                                "lockout-title"));
 
200
                lockoutSubPanel.setLayout( new GridBagLayout() );
 
201
        lockoutPanel.add(lockoutSubPanel, gbc);
 
202
                _items.addElement( lockoutSubPanel );
 
203
 
 
204
                int between = UIFactory.getComponentSpace();
 
205
                int apart = UIFactory.getSeparatedSpace();
 
206
 
 
207
        // Lockout Radio Button Sub Area
 
208
        JPanel lockoutSubSubPanel =
 
209
            new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
 
210
        lockoutSubPanel.add(lockoutSubSubPanel, gbc);
 
211
        lockoutSubSubPanel.add(lockoutAfterLabel);
 
212
        lockoutSubSubPanel.add(Box.createHorizontalStrut(between));
 
213
        lockoutSubSubPanel.add(_tfLockoutValue);
 
214
        lockoutSubSubPanel.add(Box.createHorizontalStrut(between));
 
215
        lockoutSubSubPanel.add(lockoutLabel2);
 
216
 
 
217
        // Reset Failure Count Sub Area
 
218
        JPanel resetAfterPanel =
 
219
                        new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
 
220
        lockoutSubPanel.add(resetAfterPanel, gbc);
 
221
        resetAfterLabel1.setHorizontalAlignment(SwingConstants.LEFT);
 
222
        resetAfterPanel.add(resetAfterLabel1);
 
223
        resetAfterPanel.add(Box.createHorizontalStrut(between));
 
224
        resetAfterPanel.add(_tfResetAfterValue);
 
225
        resetAfterPanel.add(Box.createHorizontalStrut(between));
 
226
        resetAfterLabel2.setHorizontalAlignment(SwingConstants.LEFT);
 
227
        resetAfterPanel.add(resetAfterLabel2);
 
228
 
 
229
        _rbLockoutForever.setHorizontalAlignment(SwingConstants.LEFT);
 
230
        gbc.fill = gbc.NONE;
 
231
        lockoutSubPanel.add(_rbLockoutForever, gbc);
 
232
        gbc.fill = gbc.HORIZONTAL;
 
233
 
 
234
        // Lockout Minutes Radio Button Sub Area
 
235
        JPanel minutesSubPanel = new JPanel(
 
236
            new FlowLayout(FlowLayout.LEFT, 0, 0)
 
237
        );
 
238
                gbc.insets.bottom = UIFactory.getComponentSpace();
 
239
        lockoutSubPanel.add(minutesSubPanel, gbc);
 
240
        _rbLockoutMinutes.setHorizontalAlignment(SwingConstants.LEFT);
 
241
        minutesSubPanel.add(_rbLockoutMinutes);
 
242
        minutesSubPanel.add(Box.createHorizontalStrut(apart));
 
243
        minutesSubPanel.add(_tfLockoutMinutesValue);
 
244
        minutesSubPanel.add(Box.createHorizontalStrut(between));
 
245
        minutesSubPanel.add(_lockoutMinutesLabel);
 
246
    }
 
247
 
 
248
    /**
 
249
     *  handle incoming event
 
250
     *
 
251
     * @param e event
 
252
     */
 
253
    public void actionPerformed(ActionEvent e) {
 
254
        if (e.getSource().equals(_cbLockout)) {
 
255
                        enableLockout();
 
256
                        enableDuration();
 
257
        } else if (e.getSource().equals(_rbLockoutForever) || 
 
258
                   e.getSource().equals(_rbLockoutMinutes)) {
 
259
            enableDuration ();
 
260
        }
 
261
    
 
262
 
 
263
                super.actionPerformed(e);  // Always want to pass event to parent
 
264
                                           // to enable buttons.
 
265
    }
 
266
 
 
267
    private void enableLockout() {
 
268
                boolean enable = ( _cbLockout.isSelected() && _fineGrainedCheckbox);
 
269
                Enumeration e = _items.elements();
 
270
                while( e.hasMoreElements() ) {
 
271
                        JComponent comp = (JComponent)e.nextElement();
 
272
                        comp.setEnabled(enable);
 
273
                        comp.repaint();
 
274
                }
 
275
    }
 
276
 
 
277
    private void enableDuration (){
 
278
        boolean enable = ( _rbLockoutMinutes.isSelected() && _fineGrainedCheckbox);
 
279
 
 
280
        _tfLockoutMinutesValue.setEnabled (enable);
 
281
        _tfLockoutMinutesValue.repaint ();
 
282
    
 
283
        _lockoutMinutesLabel.setEnabled (enable);
 
284
        _lockoutMinutesLabel.repaint ();
 
285
    }
 
286
        class LockoutEntryBoolean extends DSEntryBoolean {
 
287
                LockoutEntryBoolean(String s, AbstractButton c) {
 
288
                        super( s, c );
 
289
                }
 
290
            public void show() {
 
291
                        String val = getModel(0);
 
292
                    if (!val.equals (_trueValue)){
 
293
                _rbLockoutForever.setSelected (true);
 
294
                _rbLockoutMinutes.setSelected (false);
 
295
            } else{
 
296
                _rbLockoutForever.setSelected (false);
 
297
                _rbLockoutMinutes.setSelected (true);
 
298
            }
 
299
 
 
300
            viewInitialized ();
 
301
                        enableLockout();
 
302
                }
 
303
        }
 
304
    class DurationEntryBoolean extends DSEntryBoolean {
 
305
        DurationEntryBoolean(String s, AbstractButton c) {
 
306
                        super( s, c );
 
307
                }
 
308
            public void show() {
 
309
                        super.show();
 
310
                        enableDuration();
 
311
                }
 
312
 
 
313
    }
 
314
 
 
315
        // Flag that tells us if the PWP spec entry exists or not
 
316
        private boolean _spec_exists = false;
 
317
 
 
318
        // Target dn for fine grained password policy
 
319
        private String _dn;
 
320
 
 
321
        // Target dn's parent
 
322
        private String _parentdn;
 
323
 
 
324
        // dn of password policy container for target dn
 
325
        private String _containerdn;
 
326
 
 
327
        // dn of password specification object for target dn
 
328
        private String _policyspecdn;
 
329
 
 
330
        // dn of CoS template, for subtree password policy
 
331
        private String _costemplatedn;
 
332
 
 
333
        // dn of CoS specification, for subtree password policy
 
334
        private String _cosspecdn;
 
335
 
 
336
        // What mode the panel is in: SERVER or FINEGRAINED
 
337
        private int _mode;
 
338
 
 
339
        // Indicates whether fine-grained checkbox checked in PasswordPolicyPanel
 
340
        private boolean _fineGrainedCheckbox = true;
 
341
 
 
342
        private static final int SERVER = 1;
 
343
        private static final int FINEGRAINED_USER = 2;
 
344
        private static final int FINEGRAINED_SUBTREE = 3;
 
345
 
 
346
        private static final String CONTAINER_CN = "nsPwPolicyContainer";
 
347
        private static final String COS_SPEC_CN = "nsPwPolicy_CoS";
 
348
        private static final String USER_SPEC_CN = "nsPwPolicyEntry";
 
349
        private static final String COS_TEMPL_CN = "nsPwTemplateEntry";
 
350
        private static final String PWPSUBENTRY_ATTR_NAME = "pwdpolicysubentry";
 
351
 
 
352
    private JCheckBox       _cbLockout;
 
353
    private JTextField      _tfLockoutValue;
 
354
    private JTextField      _tfResetAfterValue;
 
355
    private JRadioButton    _rbLockoutForever;
 
356
    private JRadioButton    _rbLockoutMinutes;
 
357
    private JTextField      _tfLockoutMinutesValue;
 
358
    private Vector          _items;
 
359
    private JLabel          _lockoutMinutesLabel;
 
360
 
 
361
    private static final String CONFIG_DN = "cn=config";
 
362
 
 
363
    private static final String LOCKOUT_ATTR_NAME = "passwordLockout";
 
364
    private static final String LOCKOUT_NUM_ATTR_NAME = "passwordMaxFailure";
 
365
    private static final int LOCKOUT_NUM_MIN_VAL = 1;
 
366
    private static final int LOCKOUT_NUM_MAX_VAL = 32767;
 
367
    private static final String LOCKOUT_RESET_NUM_ATTR_NAME = 
 
368
                                          "passwordResetFailureCount";
 
369
    private static final int LOCKOUT_RESET_NUM_MIN_VAL = 1;
 
370
    private static final int LOCKOUT_RESET_NUM_MAX_VAL = 35791394; 
 
371
    private static final String LOCKOUT_FOREVER_ATTR_NAME = "passwordUnlock";
 
372
    private static final String LOCKOUT_DURATION_NUM_ATTR_NAME =
 
373
                                          "passwordLockoutDuration";
 
374
    private static final int LOCKOUT_DURATION_NUM_MIN_VAL = 1;
 
375
    private static final int LOCKOUT_DURATION_NUM_MAX_VAL = 35791394;
 
376
 
 
377
    private static final int MIN_TO_SEC_FACTOR = 60;     
 
378
    private static final int MIN_TO_DAY_FACTOR = 1440;
 
379
        
 
380
    // name of panel in resource file
 
381
    static final public String _section = "passwordpolicy";
 
382
        static final private ResourceSet _resource = DSUtil._resource;
 
383
}
 
384