~ubuntu-branches/ubuntu/utopic/389-admin-console/utopic

« back to all changes in this revision

Viewing changes to src/com/netscape/management/admserv/AdminFrameworkInitializer.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2011-10-12 11:05:09 UTC
  • Revision ID: package-import@ubuntu.com-20111012110509-ybd1jr5xeat2ug1i
Tags: upstream-1.1.8
ImportĀ upstreamĀ versionĀ 1.1.8

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
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; version 2
 
9
 * of the License.
 
10
 * 
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 * 
 
20
 * END COPYRIGHT BLOCK **/
 
21
package com.netscape.management.admserv;
 
22
 
 
23
import java.util.*;
 
24
import java.awt.*;
 
25
import java.awt.event.*;
 
26
import javax.swing.*;
 
27
import com.netscape.management.client.*;
 
28
import com.netscape.management.admserv.panel.*;
 
29
import com.netscape.management.admserv.task.AdminTaskObject;
 
30
import com.netscape.management.client.console.*;
 
31
import com.netscape.management.client.util.*;
 
32
 
 
33
 
 
34
/**
 
35
 *      Initializes Admin Server Config framework
 
36
 */
 
37
public class AdminFrameworkInitializer extends FrameworkInitializer {
 
38
    private static String PERMID_SECURITY = "SecurityVisibility";
 
39
    public static boolean canAccessSecurity = false;
 
40
 
 
41
    public AdminFrameworkInitializer(ConsoleInfo consoleInfo) {
 
42
        Console.setConsoleInfo(consoleInfo); // workaround to classloading static reference problem
 
43
        UIPermissions uip = new UIPermissions(LDAPUtil.getAdminGlobalParameterEntry());
 
44
        canAccessSecurity = uip.hasPermission(PERMID_SECURITY);
 
45
        TaskPage taskPage = new TaskPage(consoleInfo);
 
46
        TaskObject root = (TaskObject) taskPage.getModel().getRoot();
 
47
 
 
48
        addPage(taskPage);
 
49
        String [] taskList = getTaskList(taskPage);
 
50
        setTaskConsoleInfo(taskPage, consoleInfo); // override cloning of ConsoleInfo
 
51
        addPage( new AdminResourcePage(
 
52
                new AdminResourceModel(consoleInfo, taskList)));
 
53
        RemoteImage imageIcon = new RemoteImage(
 
54
                AdminServer._resource.getString("admin", "largeIcon"));
 
55
        setMinimizedImage(imageIcon.getImage());
 
56
 
 
57
        setBannerImage(getBannerImage(consoleInfo));
 
58
        setFrameTitle(consoleInfo.getLDAPConnection(),
 
59
                consoleInfo.getCurrentDN());
 
60
        setBannerText("");
 
61
    }
 
62
 
 
63
    private Image getBannerImage(ConsoleInfo consoleInfo) {
 
64
        String imageBase="com/netscape/management/admserv/images/";
 
65
        return new RemoteImage(imageBase + "admin.gif").getImage();
 
66
    }
 
67
 
 
68
    private String[] getTaskList(TaskPage taskPage) {
 
69
        TaskObject root = (TaskObject) taskPage.getModel().getRoot();
 
70
        String[] tasks = new String[root.getChildCount()];
 
71
        for (int i = 0; i < root.getChildCount(); i++) {
 
72
            tasks[i] = root.getChildAt(i).getClass().getName();
 
73
        }
 
74
        return tasks;
 
75
    }
 
76
 
 
77
    /**
 
78
      * TaskPage clones ConsoleInfo when creating a task. We want to
 
79
      * override that and force all Admin Server tasks to use the same
 
80
      * adminURL as the AdminServer object. This is important as
 
81
      * adminURL might change if the port number is changed.
 
82
      */
 
83
    private void setTaskConsoleInfo(TaskPage taskPage,
 
84
            ConsoleInfo consoleInfo) {
 
85
        TaskObject root = (TaskObject) taskPage.getModel().getRoot();
 
86
        for (int i = 0; i < root.getChildCount(); i++) {
 
87
            AdminTaskObject task = (AdminTaskObject) root.getChildAt(i);
 
88
            task.setConsoleInfo( new TaskConsoleInfo(task.getConsoleInfo(),
 
89
                    consoleInfo));
 
90
        }
 
91
    }
 
92
 
 
93
    /**
 
94
      * TaskConsoleInfo class overrides getAdminURL to return the
 
95
      * value from the ConsoleInfo in the ServerNode
 
96
      */
 
97
    private static class TaskConsoleInfo extends ConsoleInfo {
 
98
        private ConsoleInfo serverNodeConsoleInfo;
 
99
        public TaskConsoleInfo(ConsoleInfo taskConsoleInfo,
 
100
                ConsoleInfo serverNodeConsoleInfo) {
 
101
            for (Enumeration eKey = taskConsoleInfo.keys();
 
102
                    eKey.hasMoreElements();) {
 
103
                Object oKey = eKey.nextElement();
 
104
                Object oValue = taskConsoleInfo.get(oKey);
 
105
                put(oKey, oValue);
 
106
            }
 
107
            this.serverNodeConsoleInfo = serverNodeConsoleInfo;
 
108
        }
 
109
        public String getAdminURL() {
 
110
            return serverNodeConsoleInfo.getAdminURL();
 
111
        }
 
112
        /* We have to make sure we use the same password throughout
 
113
         * for the main console and for the tasks - if we do not do
 
114
         * this and we change the password, the tasks will use the
 
115
         * wrong password.  This way, if we change the password from
 
116
         * either the Configure task, or from the Configuration tab,
 
117
         * we will use the same password throughout.
 
118
         */
 
119
        public void setAuthenticationPassword(String password) {
 
120
            serverNodeConsoleInfo.setAuthenticationPassword(password);
 
121
        }
 
122
        public String getAuthenticationPassword() {
 
123
                return serverNodeConsoleInfo.getAuthenticationPassword();
 
124
        }
 
125
    };
 
126
 
 
127
    private void removeTask(TaskObject root, String taskName) {
 
128
        for (int i = 0; i < root.getChildCount(); i++) {
 
129
            // can not use instanceof because of compilation dependency
 
130
            if (root.getChildAt(i).getClass().getName().endsWith(
 
131
                    taskName)) {
 
132
                ((TaskObject) root).remove(i);
 
133
                break;
 
134
            }
 
135
        }
 
136
    }
 
137
}
 
138
 
 
139
 
 
140
class AdminResourcePage extends ResourcePage {
 
141
    public AdminResourcePage(IResourceModel model) {
 
142
        super(model);
 
143
    }
 
144
 
 
145
    public void initialize(Framework framework) {
 
146
        MenuItemText item = new MenuItemText(
 
147
                AdminServer._resource.getString("menu",
 
148
                "HelpAdminServer"), "TODO:description");
 
149
        item.addActionListener(new HelpAction());
 
150
        framework.addMenuItem(Framework.MENU_HELPWEBHELP, item);
 
151
    }
 
152
 
 
153
    class HelpAction implements ActionListener {
 
154
        public void actionPerformed(ActionEvent e) {
 
155
            Help helpSession = new Help(AdminServer._resource);
 
156
            helpSession.contextHelp("menubar", "adminserverHelpToken");
 
157
        }
 
158
    }
 
159
}