1
/** BEGIN COPYRIGHT BLOCK
2
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
3
* Copyright (C) 2005 Red Hat, Inc.
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.
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.
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 **/
20
package com.netscape.admin.dirserv.panel;
24
import java.awt.event.*;
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.*;
34
* Panel for Directory Server account lockout settings page
39
* @see com.netscape.admin.dirserv
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;
49
public AccountLockoutPanel(IDSModel model, String dn, int mode) {
50
super(model, "accountlockout");
51
_helpToken = "configuration-browser-accountlockout-help";
52
_refreshWhenSelect = false;
56
_parentdn = new DN(dn).getParent().toString();
58
_containerdn = ( _mode == FINEGRAINED_USER ?
59
("cn=" + CONTAINER_CN + "," + _parentdn) :
60
("cn=" + CONTAINER_CN + "," + _dn) );
62
_policyspecdn = "cn=\"cn=" + USER_SPEC_CN + "," +
63
_dn + "\"," + _containerdn;
65
_costemplatedn = "cn=\"cn=" + COS_TEMPL_CN + "," +
66
_dn + "\"," + _containerdn;
68
_cosspecdn = "cn=" + COS_SPEC_CN + "," + _dn;
70
// Use a DSEntrySet that doesn't complain if entry/attr are non-existant
71
setDSEntrySet(new DSEntrySet(false, true));
79
_myPanel.setLayout(new GridBagLayout());
80
createLockoutArea((Container)_myPanel);
83
_isInitialized = true;
86
public void select(IResourceObject parent, IPage viewInstance) {
87
if (_isInitialized && (_mode == FINEGRAINED_USER || _mode == FINEGRAINED_SUBTREE) ) {
88
_fineGrainedCheckbox = verifyFGCheckbox();
89
_cbLockout.setEnabled( _fineGrainedCheckbox );
93
super.select(parent, viewInstance);
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();
104
protected void createLockoutArea( Container myContainer) {
105
_items = new Vector();
107
// No Lockout checkbox
108
_cbLockout = makeJCheckBox(_section , "lockout", false);
110
JLabel lockoutAfterLabel = makeJLabel(_section, "lockoutafter");
111
_items.addElement( lockoutAfterLabel );
114
_tfLockoutValue = makeNumericalJTextField(_section, "lockoutafter2");
115
lockoutAfterLabel.setLabelFor(_tfLockoutValue);
116
_items.addElement( _tfLockoutValue );
118
JLabel lockoutLabel2 = makeJLabel(_section, "lockoutafter2");
119
_items.addElement( lockoutLabel2 );
121
JLabel resetAfterLabel1 = makeJLabel(_section, "resetafter");
122
_items.addElement( resetAfterLabel1 );
124
_tfResetAfterValue = makeNumericalJTextField(_section, "resetafter");
125
resetAfterLabel1.setLabelFor(_tfResetAfterValue);
126
_items.addElement( _tfResetAfterValue );
128
JLabel resetAfterLabel2 = makeJLabel(_section, "resetafter2");
129
_items.addElement( resetAfterLabel2 );
131
ButtonGroup durationButtonGroup = new ButtonGroup();
132
// Lockout Forever Radio Button
133
_rbLockoutForever = makeJRadioButton(_section, "lockoutforever");
134
durationButtonGroup.add(_rbLockoutForever);
135
_items.addElement( _rbLockoutForever );
137
// Lockout Minutes Radio Button
138
_rbLockoutMinutes = makeJRadioButton(_section, "lockoutduration");
139
durationButtonGroup.add(_rbLockoutMinutes);
140
_items.addElement( _rbLockoutMinutes );
142
_tfLockoutMinutesValue = makeNumericalJTextField(_section,
143
"lockoutduration", null, 8);
144
_items.addElement( _tfLockoutMinutesValue );
146
_lockoutMinutesLabel =
147
makeJLabel(_section, "lockoutduration2");
148
_items.addElement( _lockoutMinutesLabel );
150
DSEntrySet entries = getDSEntrySet();
152
DurationEntryBoolean lockDSEntry = new DurationEntryBoolean(null, _cbLockout);
153
entries.add( _policyspecdn, LOCKOUT_ATTR_NAME,
155
setComponentTable(_cbLockout, lockDSEntry);
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);
163
DSEntryInteger resetDSEntry =
164
new DSEntryInteger(null, _tfResetAfterValue,
166
LOCKOUT_RESET_NUM_MIN_VAL,
167
DSUtil.epochConstraint(LOCKOUT_RESET_NUM_MAX_VAL, MIN_TO_DAY_FACTOR),
169
entries.add( _policyspecdn, LOCKOUT_RESET_NUM_ATTR_NAME,
171
setComponentTable(_tfResetAfterValue, resetDSEntry);
173
LockoutEntryBoolean lo =
174
new LockoutEntryBoolean("off", _rbLockoutMinutes);
175
entries.add( _policyspecdn, LOCKOUT_FOREVER_ATTR_NAME, lo );
176
setComponentTable(_rbLockoutForever, lo);
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),
182
entries.add( _policyspecdn, LOCKOUT_DURATION_NUM_ATTR_NAME,
184
setComponentTable(_tfLockoutMinutesValue, lockoutDSEntry1);
186
// create containers and layouts
187
JPanel lockoutPanel = (JPanel)myContainer;
188
GridBagConstraints gbc = getGBC();
189
gbc.anchor = gbc.WEST;
192
gbc.gridwidth = gbc.REMAINDER;
193
lockoutPanel.add(_cbLockout, gbc);
194
gbc.fill = gbc.HORIZONTAL;
196
// Lockout Area Container
197
JPanel lockoutSubPanel =
198
new GroupPanel( _resource.getString(_section,
200
lockoutSubPanel.setLayout( new GridBagLayout() );
201
lockoutPanel.add(lockoutSubPanel, gbc);
202
_items.addElement( lockoutSubPanel );
204
int between = UIFactory.getComponentSpace();
205
int apart = UIFactory.getSeparatedSpace();
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);
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);
229
_rbLockoutForever.setHorizontalAlignment(SwingConstants.LEFT);
231
lockoutSubPanel.add(_rbLockoutForever, gbc);
232
gbc.fill = gbc.HORIZONTAL;
234
// Lockout Minutes Radio Button Sub Area
235
JPanel minutesSubPanel = new JPanel(
236
new FlowLayout(FlowLayout.LEFT, 0, 0)
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);
249
* handle incoming event
253
public void actionPerformed(ActionEvent e) {
254
if (e.getSource().equals(_cbLockout)) {
257
} else if (e.getSource().equals(_rbLockoutForever) ||
258
e.getSource().equals(_rbLockoutMinutes)) {
263
super.actionPerformed(e); // Always want to pass event to parent
264
// to enable buttons.
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);
277
private void enableDuration (){
278
boolean enable = ( _rbLockoutMinutes.isSelected() && _fineGrainedCheckbox);
280
_tfLockoutMinutesValue.setEnabled (enable);
281
_tfLockoutMinutesValue.repaint ();
283
_lockoutMinutesLabel.setEnabled (enable);
284
_lockoutMinutesLabel.repaint ();
286
class LockoutEntryBoolean extends DSEntryBoolean {
287
LockoutEntryBoolean(String s, AbstractButton c) {
291
String val = getModel(0);
292
if (!val.equals (_trueValue)){
293
_rbLockoutForever.setSelected (true);
294
_rbLockoutMinutes.setSelected (false);
296
_rbLockoutForever.setSelected (false);
297
_rbLockoutMinutes.setSelected (true);
304
class DurationEntryBoolean extends DSEntryBoolean {
305
DurationEntryBoolean(String s, AbstractButton c) {
315
// Flag that tells us if the PWP spec entry exists or not
316
private boolean _spec_exists = false;
318
// Target dn for fine grained password policy
321
// Target dn's parent
322
private String _parentdn;
324
// dn of password policy container for target dn
325
private String _containerdn;
327
// dn of password specification object for target dn
328
private String _policyspecdn;
330
// dn of CoS template, for subtree password policy
331
private String _costemplatedn;
333
// dn of CoS specification, for subtree password policy
334
private String _cosspecdn;
336
// What mode the panel is in: SERVER or FINEGRAINED
339
// Indicates whether fine-grained checkbox checked in PasswordPolicyPanel
340
private boolean _fineGrainedCheckbox = true;
342
private static final int SERVER = 1;
343
private static final int FINEGRAINED_USER = 2;
344
private static final int FINEGRAINED_SUBTREE = 3;
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";
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;
361
private static final String CONFIG_DN = "cn=config";
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;
377
private static final int MIN_TO_SEC_FACTOR = 60;
378
private static final int MIN_TO_DAY_FACTOR = 1440;
380
// name of panel in resource file
381
static final public String _section = "passwordpolicy";
382
static final private ResourceSet _resource = DSUtil._resource;