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 **/
19
package com.netscape.admin.dirserv;
23
import java.awt.event.*;
25
import javax.swing.tree.*;
26
import com.netscape.management.client.*;
27
import com.netscape.management.client.console.*;
28
import com.netscape.management.client.util.*;
29
import com.netscape.management.client.ace.ACIManager;
30
import com.netscape.management.client.security.CertificateDialog;
31
import com.netscape.management.client.security.PKCSConfigDialog;
32
import com.netscape.management.client.security.CertMigrateWizard;
33
import com.netscape.management.client.preferences.*;
34
import netscape.ldap.*;
37
public class DSTaskModel extends TaskModel
38
implements IMenuInfo {
40
public DSTaskModel( Vector v,
41
ConsoleInfo ci, ConsoleInfo si ) {
50
public void reset( Vector v,
51
ConsoleInfo ci, ConsoleInfo si) {
62
TaskObject root = new TaskObject( "root", _info );
63
root.setAllowsChildren(true);
64
String serverDN = _serverInfo.getCurrentDN();
65
if ( serverDN != null ) {
66
/* Check if there is a list of tasks */
67
String order = findTaskOrder( serverDN );
69
/* Accumulate tasks in a hash table */
70
Hashtable list = new Hashtable();
71
Debug.println( "DSTaskModel.init: Searching for tasks under " +
73
findTasks( root, serverDN, list );
74
/* Need to go up one from the instance entry, to get non-instance-
75
specific task entries. */
76
serverDN = "cn=Tasks," +
77
new netscape.ldap.util.DN(
78
_serverInfo.getCurrentDN() ).getParent().toString();
79
Debug.println( "DSTaskModel.init: Searching for tasks under " +
81
findTasks( root, serverDN, list );
82
Debug.println(9, "DSTaskModel.init: Finished searching for tasks");
84
/* Now sort them by preferred order, or just list them as found */
85
if ( order != null ) {
86
StringTokenizer st = new StringTokenizer( order, " " );
87
while( st.hasMoreTokens() ) {
88
TaskObject task = (TaskObject)list.get( st.nextToken() );
94
Enumeration en = list.elements();
95
while( en.hasMoreElements() ) {
96
root.add( (TaskObject)en.nextElement() );
100
Debug.println( "DSTaskModel.init: no currentDN" );
105
private void findTasks( TaskObject root, String base, Hashtable list ) {
106
// connect to the DS and search for task information
107
LDAPConnection ldc = _info.getLDAPConnection();
111
String[] attrs = {"nsclassname", "nsexecref"};
112
Debug.println(9, "DSTaskModel.findTasks: searching for tasks " +
113
"under DN=" + base + " on directory server " +
115
LDAPSearchResults result =
116
ldc.search( base, ldc.SCOPE_SUB,
117
"(objectclass=nstask)",
120
while ( result.hasMoreElements() ) {
121
String sJavaClassName = null;
122
LDAPEntry findEntry = (LDAPEntry)result.nextElement();
123
LDAPAttribute anAttr =
124
findEntry.getAttribute( attrs[0] );
125
if ( anAttr != null )
127
LDAPUtil.flatting( anAttr.getStringValues() );
128
Debug.println(9, "DSTaskModel.findTasks: Found task " +
130
" class name=" + sJavaClassName);
131
if ( sJavaClassName != null ) {
132
// load the associated task class file
135
ClassLoaderUtil.getClass(_info,
137
Debug.println(9, "DSTaskModel.findTasks: loaded " +
139
TaskObject task = (TaskObject)c.newInstance();
140
Debug.println(9, "DSTaskModel.findTasks: new " +
142
ConsoleInfo taskConsoleInfo =
143
(ConsoleInfo)_serverInfo.clone();
144
taskConsoleInfo.setCurrentDN(findEntry.getDN());
145
/* Add a listener interface for
146
authentication changes */
147
taskConsoleInfo.put( DSUtil.AUTH_CHANGE_LISTENERS,
149
anAttr = findEntry.getAttribute( attrs[1] );
150
if ( anAttr != null ) {
151
String s = LDAPUtil.flatting(
152
anAttr.getStringValues() );
153
taskConsoleInfo.put( "execref", s );
155
taskConsoleInfo.put( "dstaskmodel", this );
156
taskConsoleInfo.put( GlobalConstants.CONSOLE_INFO, _info );
157
task.setConsoleInfo(taskConsoleInfo);
159
LDAPDN.explodeDN( findEntry.getDN(), true );
160
list.put( rdns[0], task );
161
Debug.println(9, "DSTaskModel.findTasks: finish task " +
163
} catch (Exception e) {
164
Debug.println("DSTaskModel.findTasks: could not " +
165
"load class: " + sJavaClassName + ", " +
167
// This implicitly means that this task should
173
} catch ( LDAPException e ) {
174
Debug.println( "DSTaskModel.findTasks: " + e.toString() );
178
private String findTaskOrder( String base ) {
180
/* See if there is a personal preference set */
181
PreferenceManager pm =
182
PreferenceManager.getPreferenceManager(Framework.IDENTIFIER,
184
Preferences p = pm.getPreferences(PREFERENCES_TASK_TAB);
186
order = p.getString( PREFERENCES_TASK_LIST );
187
if ( (order != null) && (order.trim().length() > 0) ) {
194
LDAPConnection ldc = _info.getLDAPConnection();
198
/* Check if there is a list */
200
String dn = "cn=task summary, cn=Operation, cn=Tasks," + base;
201
String[] attrs = {"description"};
202
LDAPEntry entry = ldc.read( dn, attrs );
203
if ( entry != null ) {
204
LDAPAttribute attr = entry.getAttribute( attrs[0] );
205
if ( attr != null ) {
206
order = (String)attr.getStringValues().nextElement();
209
} catch ( LDAPException ex ) {
210
Debug.println( "DSTaskModel.findTaskOrder: no list of tasks, " +
217
* Called internally when page is selected
219
public void pageSelected( IFramework framework, IPage viewInstance ) {
220
if (getRefreshUponSelect()) {
222
setRefreshUponSelect(false);
226
public void setSelectedPage(IPage viewInstance) {
227
if (viewInstance != null)
228
_viewInstance = viewInstance;
231
public IPage getSelectedPage() {
232
return _viewInstance;
236
* Returns supported menu categories
238
public String[] getMenuCategoryIDs() {
239
if (_categoryID == null) {
240
_categoryID = new String[]
244
ResourcePage.MENU_CONTEXT,
252
* add menu items for this page.
254
public IMenuItem[] getMenuItems(String categoryID) {
255
if(categoryID.equals(Framework.MENU_FILE)) {
256
if (_menuFile == null) {
257
_menuFile = new IMenuItem[] {
258
new MenuItemCategory( MENU_SECURITY,
259
_resource.getString("menu", "Security")),
260
new MenuItemSeparator(),
261
new MenuItemText( MENU_OPEN,
262
_resource.getString("menu", "open"),
263
_resource.getString("menu",
264
"open-description")),
268
} else if( categoryID.equals(MENU_SECURITY) ) {
269
if (_menuSecurity == null) {
270
_menuSecurity = new IMenuItem[] {
272
MENU_KEYCERT_MANAGEMENT,
273
_resource.getString( "menu",
274
"SecurityCertManagement"),
275
_resource.getString( "menu",
276
"SecurityCertManagement-description")),
279
_resource.getString("menu",
281
_resource.getString("menu",
282
"SecurityPKCS11-description")),
285
_resource.getString( "menu",
286
"SecurityCertImport"),
287
_resource.getString( "menu",
288
"SecurityCertImport-description"))
291
return _menuSecurity;
292
} else if( categoryID.equals(Framework.MENU_EDIT) ) {
293
if (_menuEdit == null) {
294
_menuEdit = new IMenuItem[] {
295
new MenuItemText( MENU_ACL,
296
_resource.getString("menu", "editacls"),
297
_resource.getString("menu",
298
"editacls-description"),
305
else if ( categoryID.equals(ResourcePage.MENU_CONTEXT) ) {
306
if (_menuContext == null) {
307
_menuContext = new IMenuItem[] {
308
new MenuItemText( MENU_ACL,
309
_resource.getString("menu", "editacls"),
310
_resource.getString("menu",
311
"editacls-description")
320
public void actionObjectSelected( IPage viewInstance,
321
ITaskObject selection,
322
ITaskObject previousSelection ) {
323
super.actionObjectSelected( viewInstance, selection,
325
setSelectedPage(viewInstance);
326
_selection = selection;
327
if( selection == null ) {
328
fireDisableMenuItem( viewInstance, MENU_ACL );
330
fireEnableMenuItem( viewInstance, MENU_ACL );
335
* Notification that a menu item has been selected.
337
public void actionMenuSelected(IPage viewInstance, IMenuItem item) {
338
setSelectedPage(viewInstance);
339
if( item.getID().equals(MENU_OPEN) ) {
340
actionObjectRun(viewInstance, _selection);
341
} else if( item.getID().equals(MENU_ACL) ) {
342
if ( _selection == null ) {
345
String dn = _selection.getConsoleInfo().getCurrentDN();
346
ACIManager acm = new ACIManager(
351
} else if( item.getID().equals(MENU_KEYCERT_MANAGEMENT) ) {
352
Framework f = (Framework)viewInstance.getFramework();
354
f.setBusyCursor(true);
356
CertificateDialog dlg = new CertificateDialog(
359
(String)_serverInfo.get("SIE") );
363
f.setBusyCursor(false);
365
} else if( item.getID().equals(MENU_PKCS11) ) {
366
Framework f = (Framework)viewInstance.getFramework();
368
f.setBusyCursor(true);
370
PKCSConfigDialog dlg = new PKCSConfigDialog(
373
(String)_serverInfo.get("SIE") );
374
dlg.setVisible(true);
377
f.setBusyCursor(false);
379
} else if( item.getID().equals(MENU_KEYCERT_IMPORT) ) {
380
actionMenuImport(viewInstance);
386
* Import menu action.
387
* Before opening the 'certificate import' dialog,
388
* we check if SSL is enabled or not. If yes, we
389
* inform the user, it's not possible to import.
391
public void actionMenuImport(IPage viewInstance) {
392
DSFramework fmk = (DSFramework)viewInstance.getFramework();
393
DSAdmin serverObj = fmk.getServerObject();
395
// Check if SSL is enabled
398
sslEnabled = serverObj.getSecurityState() == DSAdmin.SECURITY_ENABLE;
400
catch(LDAPException x) {
401
Debug.println(0, "DSTaskModel.actionMenuImport: failed to read directory");
402
Debug.println(0, "DSTaskModel.actionMenuImport: SSL is considered as off");
406
// Open the 'import certificate' dialog or warn the user.
408
DSUtil.showInformationDialog(getFrame(), "impossible-when-ssl-enabled", "", "dirtask");
411
CertMigrateWizard w = new CertMigrateWizard(
414
(String)_serverInfo.get("SIE") );
416
serverObj.fireDSAdminEvent(DSAdminEvent.IMPORT_CERTIFICATE);
422
* Notification that the framework window is closing.
423
* Called by ResourcePage
425
public void actionViewClosing(IPage viewInstance)
426
throws CloseVetoException {
427
/* No unsaved changes in this model */
430
public void setWaitCursor( boolean on ) {
431
// Debug.println( "DSTaskModel.setWaitCursor: " + on +
432
// ", _viewInstance = " + _viewInstance );
433
fireChangeFeedbackCursor(
435
on ? FeedbackIndicator.FEEDBACK_WAIT :
436
FeedbackIndicator.FEEDBACK_DEFAULT );
439
fireChangeStatusItemState( getSelectedPage(),
440
ResourcePage.STATUS_PROGRESS,
441
StatusItemProgress.STATE_BUSY );
444
fireChangeStatusItemState( getSelectedPage(),
445
ResourcePage.STATUS_PROGRESS,
450
public void setRefreshUponSelect(boolean val) {
451
_refreshUponSelect = val;
454
public boolean getRefreshUponSelect() {
455
return _refreshUponSelect;
458
public void setFrame(JFrame f) {
462
public JFrame getFrame() {
463
if (_frame == null) {
464
Debug.println(0, "DSTaskModel.getFrame: returning null frame !");
469
// This flag will be true if the view for this model needs
470
// to be refreshed the next time it's displayed e.g. because
471
// the authentication changed and the new user may not have
472
// permission to see the same view the old user saw
473
private boolean _refreshUponSelect = false;
474
static public String MENU_OPEN = "OPEN";
475
static public String MENU_ACL = "ACL";
476
static public String MENU_SECURITY = "SECURITY";
477
static public String MENU_KEYCERT_MANAGEMENT = "CERT_MANAGEMENT";
478
static public String MENU_PKCS11 = "PKCS_MANAGEMENT";
479
static public String MENU_KEYCERT_IMPORT = "CERT_IMPORT";
480
private static final String PREFERENCES_TASK_TAB = "TaskTab";
481
private static final String PREFERENCES_TASK_LIST = "TaskList";
482
static ResourceSet _resource = DSUtil._resource;
483
protected ITaskObject _selection;
484
private IPage _viewInstance = null;
485
private ConsoleInfo _info;
486
private ConsoleInfo _serverInfo;
487
private Vector _authListeners = null;
488
private JFrame _frame;
489
private String[] _categoryID = null;
490
private IMenuItem[] _menuFile = null;
491
private IMenuItem[] _menuContext = null;
492
private IMenuItem[] _menuSecurity = null;
493
private IMenuItem[] _menuEdit = null;