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;
23
import java.awt.event.*;
26
import javax.swing.border.*;
27
import javax.swing.event.*;
28
import javax.swing.text.*;
29
import com.netscape.management.client.util.*;
30
import com.netscape.admin.dirserv.*;
31
import com.netscape.admin.dirserv.task.ListDB;
32
import com.netscape.admin.dirserv.panel.MappingUtils;
33
import com.netscape.management.nmclf.*;
34
import netscape.ldap.*;
35
import netscape.ldap.util.*;
36
import com.netscape.management.nmclf.SuiConstants;
40
* Panel for Directory Server resource page
43
* @see com.netscape.admin.dirserv
45
public class ModSaslMappingPanel extends BlankPanel implements SuiConstants {
47
public ModSaslMappingPanel(IDSModel model, String name, String regEx, String baseDn, String filter) {
48
super( model, _section);
49
setTitle( DSUtil._resource.getString( _section, "title"));
53
baseDnString = baseDn;
54
filterString = filter;
57
SetHelpToken("configuration-system-sasl-mod-dbox-help");
62
_myPanel.setLayout( new GridBagLayout() );
63
GridBagConstraints gbc = getGBC();
66
createTypeArea( _myPanel );
67
AbstractDialog dlg = getAbstractDialog();
69
dlg.setOKButtonEnabled( false );
77
protected void createTypeArea( JPanel grid ) {
79
JPanel Mapanel = _myPanel;
80
GridBagConstraints Magbc = new GridBagConstraints() ;
85
Magbc.gridwidth = Magbc.REMAINDER;
89
Magbc.fill = Magbc.BOTH;
90
Magbc.anchor = Magbc.CENTER;
91
Magbc.insets = new Insets(0, DIFFERENT_COMPONENT_SPACE,
93
DIFFERENT_COMPONENT_SPACE);
98
_newSaslMapNameLabel = makeJLabel( _section, "name" );
99
_newSaslMapNameLabel.resetKeyboardActions();
102
Magbc.fill = Magbc.NONE;
103
Magbc.anchor = Magbc.EAST;
105
Mapanel.add( _newSaslMapNameLabel, Magbc );
107
_newSaslMapNameText = makeJTextField( _section, "name" );
108
_newSaslMapNameText.setText(nameString);
109
_newSaslMapNameText.setEditable(false);
110
_newSaslMapNameLabel.setLabelFor(_newSaslMapNameText);
113
Magbc.anchor = Magbc.WEST;
114
Magbc.gridwidth = Magbc.REMAINDER;
115
Magbc.fill = Magbc.HORIZONTAL;
116
Mapanel.add( _newSaslMapNameText, Magbc );
118
_newSaslRegExLabel = makeJLabel( _section, "regex" );
119
_newSaslRegExLabel.resetKeyboardActions();
123
Magbc.fill = Magbc.NONE;
124
Magbc.anchor = Magbc.EAST;
126
Mapanel.add( _newSaslRegExLabel, Magbc );
128
_newSaslRegExText = makeJTextField( _section, "regex" );
129
_newSaslRegExText.setText(regExString);
130
_newSaslRegExLabel.setLabelFor(_newSaslRegExText);
133
Magbc.anchor = Magbc.WEST;
134
Magbc.gridwidth = Magbc.REMAINDER;
135
Magbc.fill = Magbc.HORIZONTAL;
136
Mapanel.add( _newSaslRegExText, Magbc );
138
_newSaslBaseDnLabel = makeJLabel( _section, "basedn" );
139
_newSaslBaseDnLabel.resetKeyboardActions();
143
Magbc.fill = Magbc.NONE;
144
Magbc.anchor = Magbc.EAST;
146
Mapanel.add( _newSaslBaseDnLabel, Magbc );
148
_newSaslBaseDnText = makeJTextField( _section, "basedn" );
149
_newSaslBaseDnText.setText(baseDnString);
150
_newSaslBaseDnLabel.setLabelFor(_newSaslBaseDnText);
153
Magbc.anchor = Magbc.WEST;
154
Magbc.gridwidth = Magbc.REMAINDER;
155
Magbc.fill = Magbc.HORIZONTAL;
156
Mapanel.add( _newSaslBaseDnText, Magbc );
158
_newSaslFilterLabel = makeJLabel( _section, "filter" );
159
_newSaslFilterLabel.resetKeyboardActions();
163
Magbc.fill = Magbc.NONE;
164
Magbc.anchor = Magbc.EAST;
166
Mapanel.add( _newSaslFilterLabel, Magbc );
168
_newSaslFilterText = makeJTextField( _section, "filter" );
169
_newSaslFilterText.setText(filterString);
170
_newSaslFilterLabel.setLabelFor(_newSaslFilterText);
173
Magbc.anchor = Magbc.WEST;
174
Magbc.gridwidth = Magbc.REMAINDER;
175
Magbc.fill = Magbc.HORIZONTAL;
176
Mapanel.add( _newSaslFilterText, Magbc );
181
Magbc.fill = Magbc.VERTICAL;
182
Mapanel.add(Box.createVerticalGlue(), Magbc);
187
* Returns the component where we put the focus
190
public JComponent getFocusComponent() {
191
return _newSuffixText;
195
* Enable/disable OK button
197
* @param ok true to enable the OK button
199
private void setOkay( boolean ok ) {
200
AbstractDialog dlg = getAbstractDialog();
202
dlg.setOKButtonEnabled( ok );
207
private void checkOkay() {
208
if((_newSaslMapNameText == null) || (_newSaslRegExText == null) || (_newSaslBaseDnText == null) || (_newSaslFilterText == null))
213
String a = _newSaslMapNameText.getText().trim();
214
String b = _newSaslRegExText.getText().trim();
215
String c = _newSaslBaseDnText.getText().trim();
216
String d = _newSaslFilterText.getText().trim();
217
boolean ok = ((a != null) && (a.length() > 0)
218
&& (b != null) && (b.length() > 0)
219
&& (c != null) && (c.length() > 0)
220
&& (d != null) && (d.length() > 0)) ;
225
* handle incoming event
229
public void actionPerformed(ActionEvent e) {
234
public void resetCallback() {
235
/* No state to preserve */
237
regExString=oldRegEx;
238
baseDnString=oldBaseDn;
239
filterString=oldFilter;
245
public void okCallback() {
247
String rdn = new DN(_newSuffixText.getText()).explodeDN(true)[0];
248
if (rdn.indexOf('"') >=0 || rdn.indexOf("\\\\") >=0) {
249
DSUtil.showErrorDialog(getModel().getFrame(),
250
"new-suffix-invalid-chars","" );
255
AbstractDialog dlg = getAbstractDialog();
257
dlg.setBusyCursor(true);
260
nameString = _newSaslMapNameText.getText();
261
regExString = _newSaslRegExText.getText();
262
baseDnString = _newSaslBaseDnText.getText();
263
filterString = _newSaslFilterText.getText();
265
/* No state to preserve
267
String[] suffixes = MappingUtils.getSuffixList(_model.getServerInfo().getLDAPConnection());
269
dady = MappingUtils.ROOT_MAPPING_NODE;
270
if (suffixes != null) {
271
/* Check if a mapping node already exists for this
272
* suffix OR if there is another root suffix that
273
* is parent of this one OR if there is a suffix
274
* that is a child of this one.
276
DN suffixDN = new DN(_newSuffixText.getText());
277
for (int i=0; i<suffixes.length; i++) {
278
DN currentSuffixDN = new DN(suffixes[i]);
280
if (suffixDN.equals(currentSuffixDN)) {
281
DSUtil.showErrorDialog(
282
getModel().getFrame(),
284
suffixDN.toString() );
286
dlg.setBusyCursor(false);
291
if (suffixDN.isDescendantOf(currentSuffixDN)) {
292
String[] args = {suffixes[i]};
293
int result = DSUtil.showConfirmationDialog( this,
294
"new-root-confirm-parent-exists",
297
if (result != JOptionPane.YES_OPTION) {
299
dlg.setBusyCursor(false);
305
if (currentSuffixDN.isDescendantOf(suffixDN)) {
306
String[] args = {suffixes[i]};
307
int result = DSUtil.showConfirmationDialog( this,
308
"new-root-confirm-child-exists",
311
if (result != JOptionPane.YES_OPTION) {
313
dlg.setBusyCursor(false);
322
dady = _subordinationText.getText();
325
boolean addLDBMB = false;
326
if( _cbCreateLDBM.isSelected()) {
327
String db = _newDBText.getText();
328
String[] dbList = { db };
329
String dbLoc = MappingUtils.getDefaultDBLoc( _model, _section) + db;
330
LDAPConnection ldc = _model.getServerInfo().getLDAPConnection();
332
if( ! MappingUtils.checkUnique( _model, db )) {
334
dlg.setBusyCursor(false);
340
addLDBMB = DSUtil.addLDBMBackend( _model,
342
MappingUtils.LDBM_CONFIG_BASEDN,
344
_newSuffixText.getText(),
347
addLDBMB = DSUtil.addLDBMBackend( _model,
349
MappingUtils.LDBM_CONFIG_BASEDN,
351
_resSuffixText.getText(),
357
( MappingUtils.addMappingNode( ldc,
359
_newSuffixText.getText(),
361
MappingUtils.BACKEND,
366
dlg.setBusyCursor(false);
372
final String cleanupDN = "cn=" + _newDBText.getText() + "," + MappingUtils.LDBM_CONFIG_BASEDN;
373
final LDAPConnection ldc_f = ldc; // = _model.getServerInfo().getLDAPConnection();
374
Debug.println("NewSufixPanel: failed to add mapping node, cleanup " + cleanupDN);
375
new Thread ( new Runnable () {
377
DSUtil.deleteTree(cleanupDN, ldc_f);
383
if( MappingUtils.addMappingNode(
384
_model.getServerInfo().getLDAPConnection(),
386
_newSuffixText.getText(),
388
MappingUtils.DISABLE,
393
dlg.setBusyCursor(false);
399
DSUtil.showErrorDialog( getModel().getFrame(),
400
"new-suffix-failed","" );
403
dlg.setBusyCursor(false);
409
public void changedUpdate(DocumentEvent e) {
411
super.changedUpdate( e );
415
public void removeUpdate(DocumentEvent e) {
417
super.removeUpdate( e );
421
public void insertUpdate(DocumentEvent e) {
423
super.insertUpdate( e );
427
private void suffixUpdate() {
429
_resSuffixText.setText( _newSuffixText.getText() +
431
_subordinationText.getText() );
433
if ( DN.isDN ( _newSuffixText.getText() )) {
434
setChangeState( _newSuffixLabel, CHANGE_STATE_UNMODIFIED );
436
setChangeState( _resSuffixLabel, CHANGE_STATE_UNMODIFIED );
438
_isNewMappingNodeValid = true;
440
setChangeState( _newSuffixLabel, CHANGE_STATE_ERROR );
442
setChangeState( _resSuffixLabel, CHANGE_STATE_ERROR );
444
_isNewMappingNodeValid = false;
446
if ( DSUtil.isValidBckName( _newDBText.getText()) ) {
447
setChangeState( _newDBLabel, CHANGE_STATE_UNMODIFIED );
449
setChangeState( _newDBLabel, CHANGE_STATE_ERROR);
453
public String getName()
458
public String getRegEx()
463
public String getBaseDn()
468
public String getFilter()
473
private JTextField _newSaslMapNameText;
474
private JLabel _newSaslMapNameLabel;
475
private JTextField _newSaslRegExText;
476
private JLabel _newSaslRegExLabel;
477
private JTextField _newSaslBaseDnText;
478
private JLabel _newSaslBaseDnLabel;
479
private JTextField _newSaslFilterText;
480
private JLabel _newSaslFilterLabel;
482
private String nameString;
483
private String regExString;
484
private String baseDnString;
485
private String filterString;
487
private String oldName;
488
private String oldRegEx;
489
private String oldBaseDn;
490
private String oldFilter;
492
private IDSModel _model = null;
494
private boolean _isRoot;
496
private boolean _isNewMappingNodeValid = false;
498
private boolean _initialized = false;
500
private final static String _section = "mod-sasl-mapping";
501
private final int ROWS = 4;
502
private LDAPEntry _entry = null;