~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/ModSaslMappingPanel.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.awt.*;
 
23
import java.awt.event.*;
 
24
import java.util.*;
 
25
import javax.swing.*;
 
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;
 
37
 
 
38
 
 
39
/**
 
40
 * Panel for Directory Server resource page
 
41
 *
 
42
 * @author  rmarco
 
43
 * @see     com.netscape.admin.dirserv
 
44
 */
 
45
public class ModSaslMappingPanel extends BlankPanel implements SuiConstants {
 
46
 
 
47
    public ModSaslMappingPanel(IDSModel model, String name, String regEx, String baseDn, String filter) {
 
48
        super( model, _section);
 
49
        setTitle( DSUtil._resource.getString( _section, "title"));
 
50
        _model = model;
 
51
        nameString = name;
 
52
        regExString = regEx;
 
53
        baseDnString = baseDn;
 
54
        filterString = filter;
 
55
        
 
56
        _isRoot = false;
 
57
        SetHelpToken("configuration-system-sasl-mod-dbox-help");
 
58
    }
 
59
 
 
60
    public void init() {
 
61
                if (!_initialized) {
 
62
                        _myPanel.setLayout( new GridBagLayout() );
 
63
                        GridBagConstraints gbc = getGBC();
 
64
                        
 
65
                        // Mapping Tree info
 
66
                        createTypeArea( _myPanel );
 
67
                        AbstractDialog dlg = getAbstractDialog();
 
68
                        if ( dlg != null ) {
 
69
                                dlg.setOKButtonEnabled( false );
 
70
                        }
 
71
                        _initialized = true;
 
72
                }
 
73
 
 
74
    }
 
75
 
 
76
 
 
77
    protected void createTypeArea( JPanel grid ) {
 
78
 
 
79
        JPanel Mapanel = _myPanel;
 
80
        GridBagConstraints Magbc = new GridBagConstraints() ;
 
81
 
 
82
 
 
83
        Magbc.gridx      = 0;
 
84
        Magbc.gridy      = 0;
 
85
        Magbc.gridwidth  = Magbc.REMAINDER;
 
86
        Magbc.gridheight = 1;
 
87
        Magbc.weightx    = 0;
 
88
        Magbc.weighty    = 0;
 
89
        Magbc.fill       = Magbc.BOTH;
 
90
        Magbc.anchor     = Magbc.CENTER;
 
91
        Magbc.insets     = new Insets(0, DIFFERENT_COMPONENT_SPACE,
 
92
                                      COMPONENT_SPACE,
 
93
                                      DIFFERENT_COMPONENT_SPACE);
 
94
        Magbc.ipadx = 0;
 
95
        Magbc.ipady = 0;
 
96
                
 
97
 
 
98
        _newSaslMapNameLabel = makeJLabel( _section, "name" );
 
99
        _newSaslMapNameLabel.resetKeyboardActions();
 
100
        Magbc.gridx = 0;
 
101
        Magbc.gridwidth = 1;
 
102
        Magbc.fill = Magbc.NONE;
 
103
        Magbc.anchor = Magbc.EAST;
 
104
        Magbc.weightx = 0.0;
 
105
        Mapanel.add( _newSaslMapNameLabel, Magbc );
 
106
 
 
107
        _newSaslMapNameText = makeJTextField( _section, "name" );
 
108
        _newSaslMapNameText.setText(nameString);
 
109
        _newSaslMapNameText.setEditable(false);
 
110
        _newSaslMapNameLabel.setLabelFor(_newSaslMapNameText);
 
111
        Magbc.weightx = 1.0;
 
112
        Magbc.gridx = 1;
 
113
        Magbc.anchor     = Magbc.WEST;
 
114
        Magbc.gridwidth = Magbc.REMAINDER;
 
115
        Magbc.fill = Magbc.HORIZONTAL;
 
116
        Mapanel.add( _newSaslMapNameText, Magbc );              
 
117
 
 
118
        _newSaslRegExLabel = makeJLabel( _section, "regex" );
 
119
        _newSaslRegExLabel.resetKeyboardActions();
 
120
        Magbc.gridy++;
 
121
        Magbc.gridx = 0;
 
122
        Magbc.gridwidth = 1;
 
123
        Magbc.fill = Magbc.NONE;
 
124
        Magbc.anchor     = Magbc.EAST;
 
125
        Magbc.weightx = 0.0;
 
126
        Mapanel.add( _newSaslRegExLabel, Magbc );
 
127
 
 
128
        _newSaslRegExText = makeJTextField( _section, "regex" );
 
129
        _newSaslRegExText.setText(regExString);
 
130
        _newSaslRegExLabel.setLabelFor(_newSaslRegExText);
 
131
        Magbc.weightx = 1.0;
 
132
        Magbc.gridx = 1;
 
133
        Magbc.anchor     = Magbc.WEST;
 
134
        Magbc.gridwidth = Magbc.REMAINDER;
 
135
        Magbc.fill = Magbc.HORIZONTAL;  
 
136
        Mapanel.add( _newSaslRegExText, Magbc );
 
137
        
 
138
        _newSaslBaseDnLabel = makeJLabel( _section, "basedn" );
 
139
        _newSaslBaseDnLabel.resetKeyboardActions();
 
140
        Magbc.gridy++;
 
141
        Magbc.gridx = 0;
 
142
        Magbc.gridwidth = 1;
 
143
        Magbc.fill = Magbc.NONE;
 
144
        Magbc.anchor     = Magbc.EAST;
 
145
        Magbc.weightx = 0.0;
 
146
        Mapanel.add( _newSaslBaseDnLabel, Magbc );
 
147
 
 
148
        _newSaslBaseDnText = makeJTextField( _section, "basedn" );
 
149
        _newSaslBaseDnText.setText(baseDnString);
 
150
        _newSaslBaseDnLabel.setLabelFor(_newSaslBaseDnText);
 
151
        Magbc.weightx = 1.0;
 
152
        Magbc.gridx = 1;
 
153
        Magbc.anchor     = Magbc.WEST;
 
154
        Magbc.gridwidth = Magbc.REMAINDER;
 
155
        Magbc.fill = Magbc.HORIZONTAL;  
 
156
        Mapanel.add( _newSaslBaseDnText, Magbc );
 
157
        
 
158
        _newSaslFilterLabel = makeJLabel( _section, "filter" );
 
159
        _newSaslFilterLabel.resetKeyboardActions();
 
160
        Magbc.gridy++;
 
161
        Magbc.gridx = 0;
 
162
        Magbc.gridwidth = 1;
 
163
        Magbc.fill = Magbc.NONE;
 
164
        Magbc.anchor     = Magbc.EAST;
 
165
        Magbc.weightx = 0.0;
 
166
        Mapanel.add( _newSaslFilterLabel, Magbc );
 
167
 
 
168
        _newSaslFilterText = makeJTextField( _section, "filter" );
 
169
        _newSaslFilterText.setText(filterString);
 
170
        _newSaslFilterLabel.setLabelFor(_newSaslFilterText);
 
171
        Magbc.weightx = 1.0;
 
172
        Magbc.gridx = 1;
 
173
        Magbc.anchor     = Magbc.WEST;
 
174
        Magbc.gridwidth = Magbc.REMAINDER;
 
175
        Magbc.fill = Magbc.HORIZONTAL;  
 
176
        Mapanel.add( _newSaslFilterText, Magbc );
 
177
                
 
178
                Magbc.gridy++;
 
179
                Magbc.gridx = 0;
 
180
                Magbc.weighty    = 1.0;
 
181
                Magbc.fill = Magbc.VERTICAL;
 
182
                Mapanel.add(Box.createVerticalGlue(), Magbc);
 
183
 
 
184
    }   
 
185
 
 
186
        /**
 
187
          * Returns the component where we put the focus
 
188
          *
 
189
          
 
190
        public JComponent getFocusComponent() {
 
191
                return _newSuffixText;
 
192
        }*/
 
193
 
 
194
    /**
 
195
     * Enable/disable OK button
 
196
     *
 
197
     * @param ok true to enable the OK button
 
198
     */
 
199
    private void setOkay( boolean ok ) {
 
200
        AbstractDialog dlg = getAbstractDialog();
 
201
        if ( dlg != null ) {
 
202
            dlg.setOKButtonEnabled( ok );
 
203
        } else {
 
204
        }
 
205
    }
 
206
 
 
207
    private void checkOkay() {
 
208
        if((_newSaslMapNameText == null) || (_newSaslRegExText == null) || (_newSaslBaseDnText == null) || (_newSaslFilterText == null))
 
209
        {
 
210
            setOkay(false);
 
211
            return;
 
212
        }
 
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)) ;
 
221
        setOkay( ok );
 
222
    }
 
223
 
 
224
    /**
 
225
     *  handle incoming event
 
226
     *
 
227
     * @param e event
 
228
     */
 
229
    public void actionPerformed(ActionEvent e) {
 
230
        checkOkay();
 
231
    }
 
232
 
 
233
 
 
234
    public void resetCallback() {
 
235
        /* No state to preserve */
 
236
        nameString=oldName;
 
237
        regExString=oldRegEx;
 
238
        baseDnString=oldBaseDn;
 
239
        filterString=oldFilter;
 
240
        clearDirtyFlag();
 
241
        hideDialog();
 
242
    }
 
243
 
 
244
 
 
245
    public void okCallback() {
 
246
/*
 
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","" );
 
251
            return;            
 
252
                }
 
253
 */
 
254
 
 
255
        AbstractDialog dlg = getAbstractDialog();
 
256
                if (dlg != null) {
 
257
                        dlg.setBusyCursor(true);
 
258
                }
 
259
        
 
260
        nameString = _newSaslMapNameText.getText();
 
261
        regExString = _newSaslRegExText.getText();
 
262
        baseDnString = _newSaslBaseDnText.getText();
 
263
        filterString = _newSaslFilterText.getText();
 
264
 
 
265
        /* No state to preserve 
 
266
        String dady;
 
267
        String[] suffixes = MappingUtils.getSuffixList(_model.getServerInfo().getLDAPConnection());
 
268
        if( _isRoot ) {
 
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.
 
275
                         
 
276
                        DN suffixDN = new DN(_newSuffixText.getText());
 
277
                        for (int i=0; i<suffixes.length; i++) {
 
278
                                DN currentSuffixDN = new DN(suffixes[i]);
 
279
 
 
280
                                if (suffixDN.equals(currentSuffixDN)) {
 
281
                                        DSUtil.showErrorDialog(
 
282
                                                        getModel().getFrame(),
 
283
                                                        "new-suffix-exists",
 
284
                                                        suffixDN.toString() );
 
285
                                        if (dlg != null) {
 
286
                                                dlg.setBusyCursor(false);
 
287
                                        }
 
288
                                        return;
 
289
                                }
 
290
 
 
291
                                if (suffixDN.isDescendantOf(currentSuffixDN)) {
 
292
                                        String[] args = {suffixes[i]};
 
293
                                        int result = DSUtil.showConfirmationDialog( this,
 
294
                                                                                                                           "new-root-confirm-parent-exists",
 
295
                                                                                                                           args,
 
296
                                                                                                                           _section);
 
297
                                        if (result != JOptionPane.YES_OPTION) {
 
298
                                                if (dlg != null) {
 
299
                                                        dlg.setBusyCursor(false);
 
300
                                                }
 
301
                                                return;
 
302
                                        }
 
303
                                        break;
 
304
                                }
 
305
                                if (currentSuffixDN.isDescendantOf(suffixDN)) {
 
306
                                        String[] args = {suffixes[i]};
 
307
                                        int result = DSUtil.showConfirmationDialog( this,
 
308
                                                                                                                                "new-root-confirm-child-exists",
 
309
                                                                                                                                args,
 
310
                                                                                                                                _section);
 
311
                                        if (result != JOptionPane.YES_OPTION) {
 
312
                                                if (dlg != null) {
 
313
                                                        dlg.setBusyCursor(false);
 
314
                                                }
 
315
                                                return;
 
316
                                        }
 
317
                                        break;
 
318
                                }
 
319
                        }       
 
320
                }               
 
321
        } else {
 
322
            dady = _subordinationText.getText();
 
323
        } 
 
324
        
 
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();
 
331
 
 
332
            if( ! MappingUtils.checkUnique( _model, db )) {
 
333
                        if (dlg != null) {
 
334
                                dlg.setBusyCursor(false);
 
335
                        }
 
336
                        return;
 
337
                }
 
338
 
 
339
            if( _isRoot ) {
 
340
                addLDBMB = DSUtil.addLDBMBackend( _model,
 
341
                                            db,
 
342
                                            MappingUtils.LDBM_CONFIG_BASEDN,
 
343
                                            dbLoc,
 
344
                                            _newSuffixText.getText(),
 
345
                                            _section );
 
346
            } else {
 
347
                addLDBMB = DSUtil.addLDBMBackend( _model,
 
348
                                            db,
 
349
                                            MappingUtils.LDBM_CONFIG_BASEDN,
 
350
                                            dbLoc,
 
351
                                            _resSuffixText.getText(),
 
352
                                            _section );
 
353
            }
 
354
                    
 
355
                
 
356
            if( addLDBMB &&
 
357
                ( MappingUtils.addMappingNode( ldc,
 
358
                                               _section,
 
359
                                               _newSuffixText.getText(),
 
360
                                               dady,
 
361
                                               MappingUtils.BACKEND,
 
362
                                               dbList,
 
363
                                               null))) {
 
364
                hideDialog();
 
365
                if (dlg != null) {
 
366
                        dlg.setBusyCursor(false);
 
367
                }
 
368
                return;
 
369
            }
 
370
            else if (addLDBMB) {
 
371
            // Cleanup required
 
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 () {
 
376
                public void run() {
 
377
                    DSUtil.deleteTree(cleanupDN, ldc_f);
 
378
                }
 
379
            }).start();
 
380
            }
 
381
        
 
382
        } else {
 
383
            if( MappingUtils.addMappingNode(
 
384
                                            _model.getServerInfo().getLDAPConnection(),
 
385
                                            _section,
 
386
                                            _newSuffixText.getText(),
 
387
                                            dady,
 
388
                                            MappingUtils.DISABLE,
 
389
                                            null,
 
390
                                            null)) {
 
391
                        hideDialog();
 
392
                        if (dlg != null) {
 
393
                                dlg.setBusyCursor(false);
 
394
                        }
 
395
                        return;
 
396
                        
 
397
            }
 
398
        }
 
399
        DSUtil.showErrorDialog( getModel().getFrame(),
 
400
                                "new-suffix-failed","" );
 
401
*/
 
402
    if (dlg != null) {
 
403
                dlg.setBusyCursor(false);
 
404
        }
 
405
        hideDialog();
 
406
        //return;       
 
407
    }
 
408
 
 
409
    public void changedUpdate(DocumentEvent e) {
 
410
        //suffixUpdate();
 
411
        super.changedUpdate( e );
 
412
        checkOkay();
 
413
    }
 
414
 
 
415
    public void removeUpdate(DocumentEvent e) {
 
416
        //suffixUpdate();
 
417
        super.removeUpdate( e );
 
418
        checkOkay();
 
419
    }
 
420
 
 
421
    public void insertUpdate(DocumentEvent e) {
 
422
        //suffixUpdate();
 
423
        super.insertUpdate( e );
 
424
        checkOkay();
 
425
    }
 
426
/*
 
427
    private void suffixUpdate() {
 
428
        if( ! _isRoot ) {
 
429
            _resSuffixText.setText(  _newSuffixText.getText() +
 
430
                                     "," +
 
431
                                     _subordinationText.getText() );
 
432
        }
 
433
        if ( DN.isDN ( _newSuffixText.getText() )) {
 
434
            setChangeState( _newSuffixLabel, CHANGE_STATE_UNMODIFIED );
 
435
            if( ! _isRoot ) {
 
436
                setChangeState( _resSuffixLabel, CHANGE_STATE_UNMODIFIED ); 
 
437
            }
 
438
            _isNewMappingNodeValid = true;
 
439
        } else {
 
440
            setChangeState( _newSuffixLabel, CHANGE_STATE_ERROR );
 
441
            if( ! _isRoot ) {
 
442
                setChangeState( _resSuffixLabel, CHANGE_STATE_ERROR ); 
 
443
            }
 
444
            _isNewMappingNodeValid = false;
 
445
        }
 
446
        if ( DSUtil.isValidBckName( _newDBText.getText()) ) {
 
447
            setChangeState( _newDBLabel, CHANGE_STATE_UNMODIFIED );
 
448
        } else {
 
449
            setChangeState( _newDBLabel, CHANGE_STATE_ERROR);
 
450
        }
 
451
    }
 
452
*/
 
453
    public String getName()
 
454
    {
 
455
        return nameString;
 
456
    }
 
457
    
 
458
    public String getRegEx()
 
459
    {
 
460
        return regExString;
 
461
    }
 
462
    
 
463
    public String getBaseDn()
 
464
    {
 
465
        return baseDnString;
 
466
    }
 
467
    
 
468
    public String getFilter()
 
469
    {
 
470
        return filterString;
 
471
    }
 
472
 
 
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;
 
481
 
 
482
    private String                      nameString;
 
483
    private String                      regExString;
 
484
    private String                      baseDnString;
 
485
    private String                      filterString;
 
486
    
 
487
    private String                      oldName;
 
488
    private String                      oldRegEx;
 
489
    private String                      oldBaseDn;
 
490
    private String                      oldFilter;
 
491
    
 
492
    private IDSModel                    _model = null;
 
493
 
 
494
    private boolean                             _isRoot;
 
495
 
 
496
    private boolean                             _isNewMappingNodeValid = false;
 
497
 
 
498
        private boolean _initialized = false;
 
499
 
 
500
    private final static String _section = "mod-sasl-mapping";
 
501
    private final int ROWS = 4; 
 
502
    private LDAPEntry _entry = null;
 
503
 
 
504
}