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.replication;
22
import java.util.StringTokenizer;
24
import java.awt.event.*;
27
import javax.swing.event.*;
28
import netscape.ldap.*;
29
import com.netscape.admin.dirserv.*;
30
import com.netscape.admin.dirserv.panel.*;
31
import com.netscape.management.client.*;
32
import com.netscape.management.client.util.*;
35
* Panel for Directory Server Consumer Replication Setting
40
* @see com.netscape.admin.dirserv.panel.replication
42
public class LegacyConsumerSettingPanel extends BlankPanel {
44
/*==========================================================
46
*==========================================================*/
50
* construction is delayed until selected.
51
* @param parent parent panel
53
public LegacyConsumerSettingPanel(IDSModel model) {
54
super(model, "replication");
55
setTitle(_resource.getString(_section+"-setting","title"));
57
_helpToken = "configuration-replication-legacyconsumersettings-help";
58
_refreshWhenSelect = false;
61
/*==========================================================
63
*==========================================================*/
66
* Actual panel construction
74
LDAPConnection ldc = _model.getServerInfo().getLDAPConnection();
75
_legacyEntry = ldc.read(REPSETTINGS_DN);
76
if (_legacyEntry != null) {
79
} catch (LDAPException lde) {
82
_isLegacyConsumerEnabled = _entryExists;
84
GridBagConstraints gbc = getGBC();
86
_myPanel.setLayout(new GridBagLayout());
87
_myPanel.setBackground(getBackground());
88
_myPanel.setPreferredSize(ReplicationTool.DEFAULT_PANEL_SIZE);
89
_myPanel.setMaximumSize(ReplicationTool.DEFAULT_PANEL_SIZE);
91
//add Description label
92
JTextArea desc = makeMultiLineLabel( 2, 60,
94
_section,"setting-desc") );
95
gbc.anchor = gbc.NORTHWEST;
98
gbc.fill = gbc.HORIZONTAL;
99
_myPanel.add(desc, gbc);
101
gbc.fill = gbc.HORIZONTAL;
102
gbc.gridwidth = gbc.REMAINDER;
103
_myPanel.add(Box.createGlue(),gbc);
106
_cbEnable = makeJCheckBox( _section,
110
_cbEnable.setSelected( _entryExists );
111
_cbEnable.addItemListener(this);
115
_myPanel.add(_cbEnable,gbc);
117
gbc.fill = gbc.HORIZONTAL;
118
gbc.gridwidth = gbc.REMAINDER;
119
_myPanel.add(Box.createGlue(),gbc);
122
ReplicationTool.resetGBC(gbc);
123
gbc.insets = (Insets) ReplicationTool.BOTTOM_INSETS.clone();
124
gbc.anchor = gbc.NORTH;
125
gbc.gridwidth = gbc.REMAINDER;
127
_myPanel.add(createAuth(), gbc);
131
_isInitialized = true;
134
private JPanel createAuth(){
135
//setup Normal Auth panel
136
String title = _resource.getString(_section+"-normalAuth","label");
137
JPanel panel = new GroupPanel(title);
140
_dnLabel = makeJLabel(_resource.getString(_section+"-supplierDN","label"));
141
_dnLabel.setToolTipText(_resource.getString(_section+"-supplierDN","ttip"));
142
_dnLabel.resetKeyboardActions();
144
GridBagConstraints gbc = new GridBagConstraints();
145
ReplicationTool.resetGBC(gbc);
146
gbc.insets = (Insets) ReplicationTool.BOTTOM_INSETS.clone();
147
gbc.anchor = gbc.NORTHEAST;
148
gbc.gridwidth = gbc.RELATIVE;
151
panel.add(_dnLabel, gbc);
153
_dnText= makeJTextField(_section, "supplierDN", _resource);
154
_dnLabel.setLabelFor(_dnText);
155
_saveDN = DSUtil.getAttrValue( _legacyEntry, UPDATEDN_ATTR_NAME );
156
if( _saveDN != null ) {
157
_dnText.setText( _saveDN );
162
gbc.gridwidth = gbc.REMAINDER;
163
gbc.anchor = gbc.NORTHWEST;
164
gbc.fill = gbc.HORIZONTAL;
166
panel.add(_dnText, gbc);
170
_pwdLabel = makeJLabel(_resource.getString(_section+"-SupplierNewPwd","label"));
171
_pwdLabel.setToolTipText(_resource.getString(_section+"-SupplierNewPwd","ttip"));
172
_pwdLabel.resetKeyboardActions();
174
gbc.anchor = gbc.NORTHEAST;
175
gbc.gridwidth = gbc.RELATIVE;
178
panel.add(_pwdLabel, gbc);
180
_pwdText= makeJPasswordField(_section, "SupplierNewPwd",
182
_pwdLabel.setLabelFor(_pwdText);
183
_savePwd = DSUtil.getAttrValue( _legacyEntry, UPDATEDN_PASSWORD_ATTR_NAME);
184
if( _savePwd != null){
185
_pwdText.setText( _savePwd );
188
_pwdText.setText("");
191
gbc.anchor = gbc.NORTHWEST;
192
gbc.gridwidth = gbc.REMAINDER;
193
gbc.fill = gbc.HORIZONTAL;
195
panel.add(_pwdText, gbc);
198
_againLabel= makeJLabel(_resource.getString(_section+"-SupplierNewPwd","again"));
199
_againLabel.resetKeyboardActions();
201
gbc.anchor = gbc.NORTHEAST;
202
gbc.gridwidth = gbc.RELATIVE;
205
panel.add(_againLabel, gbc);
207
_againText= makeJPasswordField(_section, "SupplierNewPwd",
209
_againLabel.setLabelFor(_againText);
210
gbc.anchor = gbc.NORTHWEST;
211
gbc.fill = gbc.HORIZONTAL;
212
gbc.gridwidth = gbc.REMAINDER;
213
// empty passwd is not valid
214
_againText.setText( _savePwd );
215
panel.add(_againText, gbc);
221
* Update on-screen data from Directory.
224
public boolean refresh () {
225
Debug.println("LegacyConsumerPanel.refresh()");
226
/* We re-read the entry from the server */
227
_entryExists = false;
229
LDAPConnection ldc = _model.getServerInfo().getLDAPConnection();
230
_legacyEntry = ldc.read(REPSETTINGS_DN);
231
if (_legacyEntry != null) {
234
} catch (LDAPException lde) {
237
_isLegacyConsumerEnabled = _entryExists;
238
_saveDN = DSUtil.getAttrValue( _legacyEntry, UPDATEDN_ATTR_NAME );
239
_savePwd = DSUtil.getAttrValue( _legacyEntry, UPDATEDN_PASSWORD_ATTR_NAME);
246
* Update on-screen data from Directory.
248
* Note: we overwrite the data that the user may have modified. This is done in order to keep
249
* the coherency between the refresh behaviour of the different panels of the configuration tab.
252
public void refreshFromServer () {
253
Debug.println("LegacyConsumerPanel.refreshFromServer()");
258
public void resetCallback() {
259
/* We re-read the entry from the server */
260
_entryExists = false;
262
LDAPConnection ldc = _model.getServerInfo().getLDAPConnection();
263
_legacyEntry = ldc.read(REPSETTINGS_DN);
264
if (_legacyEntry != null) {
267
} catch (LDAPException lde) {
270
_isLegacyConsumerEnabled = _entryExists;
271
_saveDN = DSUtil.getAttrValue( _legacyEntry, UPDATEDN_ATTR_NAME );
272
_savePwd = DSUtil.getAttrValue( _legacyEntry, UPDATEDN_PASSWORD_ATTR_NAME);
274
if( _saveDN != null){
275
_dnText.setText( _saveDN );
279
_cbEnable.setSelected( _entryExists );
281
_pwdText.setText( _savePwd );
282
_againText.setText( _savePwd );
287
public void okCallback() {
292
LDAPConnection ldc = _model.getServerInfo().getLDAPConnection();
293
/* We read again the entry to check if it exists ...*/
294
_entryExists = false;
296
_legacyEntry = ldc.read(REPSETTINGS_DN);
297
if (_legacyEntry != null) {
300
} catch (LDAPException lde) {
305
String pwd = new String( _pwdText.getPassword() );
309
ldc.delete( REPSETTINGS_DN );
310
_entryExists = false;
313
_pwdText.setText("");
314
_againText.setText("");
315
} catch (LDAPException e) {
316
/* If the entry does not exists, it's already removed, and we don't display any error message */
317
if (e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT) {
318
_entryExists = false;
321
_pwdText.setText("");
322
_againText.setText("");
324
String ldapError = e.errorCodeToString();
325
String ldapMessage = e.getLDAPErrorMessage();
326
if ((ldapMessage != null) &&
327
(ldapMessage.length() > 0)) {
328
ldapError = ldapError + ". "+ldapMessage;
330
String[] args_m = { ldapError };
331
DSUtil.showErrorDialog( _model.getFrame(),
340
} else if (!_entryExists) {
342
LDAPAttributeSet las = new LDAPAttributeSet();
344
// add the more well known attributes and values
345
las.add(new LDAPAttribute("objectclass",
346
REPSETTINGS_OBJECTCLASSES));
347
las.add(new LDAPAttribute("cn",
349
las.add(new LDAPAttribute(UPDATEDN_ATTR_NAME,
351
las.add(new LDAPAttribute(UPDATEDN_PASSWORD_ATTR_NAME,
353
LDAPEntry newEntry = new LDAPEntry(REPSETTINGS_DN, las);
357
} catch(LDAPException e) {
358
String ldapError = e.errorCodeToString();
359
String ldapMessage = e.getLDAPErrorMessage();
360
if ((ldapMessage != null) &&
361
(ldapMessage.length() > 0)) {
362
ldapError = ldapError + ". "+ldapMessage;
364
String[] args_m = { ldapError };
365
DSUtil.showErrorDialog( _model.getFrame(),
373
_legacyEntry = newEntry;
376
LDAPModificationSet attrs = new LDAPModificationSet();
377
attrs.add(LDAPModification.REPLACE,
378
new LDAPAttribute("nsslapd-legacy-updatedn",
380
attrs.add(LDAPModification.REPLACE,
381
new LDAPAttribute("nsslapd-legacy-updatepw",
384
ldc.modify( _legacyEntry.getDN(), attrs );
385
} catch(LDAPException e) {
386
String ldapError = e.errorCodeToString();
387
String ldapMessage = e.getLDAPErrorMessage();
388
if ((ldapMessage != null) &&
389
(ldapMessage.length() > 0)) {
390
ldapError = ldapError + ". "+ldapMessage;
392
String[] args_m = { ldapError };
393
DSUtil.showErrorDialog( _model.getFrame(),
402
_saveDN = _dnText.getText();
403
_savePwd = new String(_pwdText.getPassword());
408
public void changedUpdate(DocumentEvent e) {
412
public void insertUpdate(DocumentEvent e) {
413
if (!_isInitialized) return;
417
public void removeUpdate(DocumentEvent e) {
421
public void itemStateChanged(ItemEvent e) {
422
if(e.getSource().equals(_cbEnable)) {
427
public void actionPerformed(ActionEvent e) {
431
private void checkPwd(){
432
String p1 = new String( _pwdText.getPassword() );
433
String p2 = new String( _againText.getPassword() );
435
// (p1.length() == 0) && ( p2.length() == 0) in case of SSL strong auth
436
// for the rest i think there is a min and of course they must be the same
437
_isPasswdOK = (((p1.length() == 0) && ( p2.length() == 0)) ||
438
(( p1.length() >= _pwdMinLength ) &&
439
( p2.length() >= _pwdMinLength ) &&
440
( p1.compareTo( p2 ) == 0)));
442
_isPwdDirty = !p1.equals(_savePwd);
446
setChangeState( _pwdLabel, CHANGE_STATE_MODIFIED);
447
setChangeState( _againLabel, CHANGE_STATE_MODIFIED);
449
setChangeState( _pwdLabel, CHANGE_STATE_UNMODIFIED);
450
setChangeState( _againLabel, CHANGE_STATE_UNMODIFIED);
453
setChangeState( _pwdLabel, CHANGE_STATE_ERROR);
454
setChangeState( _againLabel, CHANGE_STATE_ERROR);
458
private void checkDN(){
459
_isDNDirty = !DSUtil.equalDNs(_dnText.getText(), _saveDN);
460
_isDNOK = DSUtil.isValidDN( _dnText.getText());
463
setChangeState( _dnLabel, CHANGE_STATE_MODIFIED);
465
setChangeState( _dnLabel, CHANGE_STATE_UNMODIFIED );
468
setChangeState( _dnLabel, CHANGE_STATE_ERROR);
472
private void checkEnable() {
473
_isEnableDirty = (_cbEnable.isSelected() != _entryExists);
474
if (_isEnableDirty) {
475
setChangeState( _cbEnable, CHANGE_STATE_MODIFIED);
477
setChangeState( _cbEnable, CHANGE_STATE_UNMODIFIED );
481
private void checkOkay() {
487
/* if the check box enable is not selected, what we have is always valid */
488
_isValid = _isPasswdOK && _isDNOK || !_cbEnable.isSelected();
489
_isDirty = (_isPwdDirty || _isDNDirty || _isEnableDirty) &&
490
(_isEnableDirty || _cbEnable.isSelected()); /* We don't consider dirty if the user has kept the
491
legacy disabled ... even if the other fields have been
511
private void checkStatus() {
512
_mustDelete = _entryExists && !_cbEnable.isSelected();
513
_isLegacyConsumerEnabled = _cbEnable.isSelected();
516
/*==========================================================
518
*==========================================================*/
519
private void clearPWDFields() {
520
_pwdText.setText("");
521
_againText.setText("");
524
private void checkEnabledField(){
526
_dnLabel.setEnabled( _isLegacyConsumerEnabled );
527
_dnText.setEnabled( _isLegacyConsumerEnabled );
528
_pwdText.setBackground( _dnText.getBackground());
529
_againText.setBackground( _dnText.getBackground());
530
_pwdLabel.setEnabled( _isLegacyConsumerEnabled );
531
_pwdText.setEnabled( _isLegacyConsumerEnabled );
532
_againLabel.setEnabled( _isLegacyConsumerEnabled );
533
_againText.setEnabled( _isLegacyConsumerEnabled );
536
/*==========================================================
538
*==========================================================*/
539
private IDSModel _model;
540
private boolean _entryExists;
541
private boolean _isValid = true;
542
private boolean _isDirty = false;
543
private boolean _isDNDirty = false;
544
private boolean _isDNOK = true;
545
private boolean _isPwdDirty = false;
546
private boolean _isPasswdOK = true;
547
private boolean _isEnableDirty = false;
548
private boolean _mustDelete;
549
private boolean _isLegacyConsumerEnabled;
551
private JTextField _dnText;
552
private JPasswordField _pwdText;
553
private JPasswordField _againText;
554
private JCheckBox _cbEnable = null;
555
private JLabel _dnLabel;
556
private JLabel _againLabel;
557
private JLabel _pwdLabel;
558
private String _savePwd;
559
private String _saveDN;
561
// DSEntryConfirmPassword _againDSEntry;
562
// DSEntryPassword _pwdDSEntry;
563
private LDAPEntry _legacyEntry;
565
//get resource bundle
566
private static ResourceSet _resource =
567
new ResourceSet("com.netscape.admin.dirserv.panel.replication.replication");
568
private static final String _section = "replication-legacyconsumer";
570
private static final int _pwdMinLength = 8;
572
private static final String REPSETTINGS_CN = "legacy consumer";
573
public static final String REPSETTINGS_DN = "cn=" + REPSETTINGS_CN +
574
",cn=replication,cn=config";
575
private static final String[] REPSETTINGS_OBJECTCLASSES =
576
{"top", "extensibleObject"};
577
private static final String UPDATEDN_ATTR_NAME =
578
"nsslapd-legacy-updatedn";
579
private static final String UPDATEDN_PASSWORD_ATTR_NAME =
580
"nsslapd-legacy-updatepw";