From 621d9e5c413e561293d7484b93882d985b3fe15f Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Sat, 24 Mar 2012 02:27:47 -0500 Subject: Removed unnecessary pki folder. Previously the source code was located inside a pki folder. This folder was created during svn migration and is no longer needed. This folder has now been removed and the contents have been moved up one level. Ticket #131 --- .../netscape/admin/certsrv/ug/AuthBaseDialog.java | 355 ++++++++++++ .../admin/certsrv/ug/AuthConfigDialog.java | 91 +++ .../admin/certsrv/ug/AuthImplDataModel.java | 72 +++ .../com/netscape/admin/certsrv/ug/AuthImplTab.java | 353 ++++++++++++ .../netscape/admin/certsrv/ug/AuthInstanceTab.java | 141 +++++ .../certsrv/ug/AuthPluginSelectionDialog.java | 95 ++++ .../admin/certsrv/ug/AuthRegisterDialog.java | 40 ++ .../admin/certsrv/ug/AuthRuleDataModel.java | 64 +++ .../netscape/admin/certsrv/ug/AuthViewDialog.java | 65 +++ .../netscape/admin/certsrv/ug/CMSBaseUGTab.java | 153 +++++ .../netscape/admin/certsrv/ug/CMSUGTabPanel.java | 136 +++++ .../netscape/admin/certsrv/ug/CertDataModel.java | 85 +++ .../admin/certsrv/ug/CertImportDialog.java | 256 +++++++++ .../admin/certsrv/ug/CertManagementDialog.java | 441 +++++++++++++++ .../netscape/admin/certsrv/ug/CertViewDialog.java | 201 +++++++ .../netscape/admin/certsrv/ug/GroupDataModel.java | 61 ++ .../com/netscape/admin/certsrv/ug/GroupEditor.java | 596 ++++++++++++++++++++ .../admin/certsrv/ug/GroupListDataModel.java | 67 +++ .../netscape/admin/certsrv/ug/GroupListDialog.java | 284 ++++++++++ .../com/netscape/admin/certsrv/ug/GroupTab.java | 369 ++++++++++++ .../netscape/admin/certsrv/ug/MemberDataModel.java | 140 +++++ .../netscape/admin/certsrv/ug/UserDataModel.java | 68 +++ .../com/netscape/admin/certsrv/ug/UserEditor.java | 627 +++++++++++++++++++++ .../admin/certsrv/ug/UserListDataModel.java | 70 +++ .../netscape/admin/certsrv/ug/UserListDialog.java | 369 ++++++++++++ .../src/com/netscape/admin/certsrv/ug/UserTab.java | 374 ++++++++++++ 26 files changed, 5573 insertions(+) create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthBaseDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthConfigDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthImplDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthImplTab.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthInstanceTab.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthPluginSelectionDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthRegisterDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthRuleDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/AuthViewDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/CMSBaseUGTab.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/CMSUGTabPanel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/CertDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/CertImportDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/CertManagementDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/CertViewDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/GroupDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/GroupEditor.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/GroupListDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/GroupListDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/GroupTab.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/MemberDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/UserDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/UserEditor.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/UserListDataModel.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/UserListDialog.java create mode 100644 base/console/src/com/netscape/admin/certsrv/ug/UserTab.java (limited to 'base/console/src/com/netscape/admin/certsrv/ug') diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthBaseDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthBaseDialog.java new file mode 100644 index 000000000..6656b3abb --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthBaseDialog.java @@ -0,0 +1,355 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import javax.swing.text.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * Auth Parameter Configuration Dialog + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class AuthBaseDialog extends JDialog + implements ActionListener +{ + /*========================================================== + * variables + *==========================================================*/ + protected JFrame mParentFrame; + protected ResourceBundle mResource; + protected CMSTableModel mDataModel; + protected NameValuePairs mData; + protected JScrollPane mScrollPane; + protected JTable mTable; + protected String mRuleName; + protected String mPrefix; + protected String mType; + protected JButton mOK, mCancel, mHelp; + protected JTextField mAuthName; + protected JLabel mImplName, mAuthLabel; + protected AdminConnection mConn; + + /*========================================================== + * constructors + *==========================================================*/ + public AuthBaseDialog(JFrame parent, String type, String prefix) { + super(parent, true); + mParentFrame = parent; + mPrefix = prefix; + mType = type; + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + setSize(360, 316); + setTitle(mResource.getString(mPrefix+"_TITLE")); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + * @param users list of current groups + */ + // Changed by beomsuk + /*public void showDialog(NameValuePairs data, String name, + boolean pinDirExist, boolean userDirExist) {*/ + public void showDialog(NameValuePairs data, String name, + boolean pinDirExist, boolean userDirExist, boolean portalExist) { + // Change end + mDataModel.removeAllRows(); + mData = data; + + mImplName.setText(data.get(Constants.PR_AUTH_IMPL_NAME)); + + for (String entry : data.keySet()) { + entry = entry.trim(); + if (!entry.equals(Constants.PR_AUTH_IMPL_NAME)) { + String value = data.get(entry); + Vector v = new Vector(); + v.addElement(entry); + v.addElement(value); + mDataModel.addRow(v); + } + } + + if ((name==null)||name.equals("")) { + //new policy + mAuthName.setVisible(true); + mAuthName.setText(""); + mAuthLabel.setVisible(false); + String str = mImplName.getText().trim(); + if (!pinDirExist && str.equals("UidPwdPinDirAuth")) + mAuthName.setText("PinDirEnrollment"); + else if (!userDirExist && str.equals("UidPwdDirAuth")) + mAuthName.setText("UserDirEnrollment"); + else if (!userDirExist && str.equals("UdnPwdDirAuth")) + mAuthName.setText("UserDnEnrollment"); + else if (str.equals("NISAuth")) + mAuthName.setText("NISAuth"); + // Inserted by beomsuk + else if (!portalExist && str.equals("PortalEnroll")) + mAuthName.setText("PortalEnrollment"); + // Insert end + } else { + //old one + mRuleName = name; + mAuthName.setVisible(false); + mAuthLabel.setVisible(true); + mAuthLabel.setText(name); + } + + this.show(); + } + + protected NameValuePairs getData() { + NameValuePairs response = new NameValuePairs(); + response.put(Constants.PR_AUTH_IMPL_NAME, mImplName.getText()); + for (int i=0; i< mDataModel.getRowCount(); i++) { + response.put((String) mDataModel.getValueAt(i, 0), + (String) mDataModel.getValueAt(i, 1)); + } + return response; + } + + protected String getRuleName() { + return mRuleName; + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent evt) { + + if (evt.getSource().equals(mOK)) { + + if(mAuthName.isVisible()) { + mRuleName = mAuthName.getText(); + if (mRuleName.trim().equals("")) { + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + mResource.getString(mPrefix+"_DIALOG_NORULENAME_MESSAGE"), + CMSAdminUtil.ERROR_MESSAGE); + return; + } + } + + //save any current edit component + Component component = mTable.getEditorComponent(); + if (component!= null) { + int col = mTable.getEditingColumn(); + int row = mTable.getEditingRow(); + if ((col>-1)&&(row>-1)) { + String str = ((JTextComponent)component).getText(); + mTable.setValueAt(str, row, col); + } + } + + try { + if (mAuthName.isVisible()) + addPolicyRule(getData(), getRuleName()); + else + modifyPolicyRule(getData(), getRuleName()); + } catch (EAdminException e) { + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.toString(),CMSAdminUtil.ERROR_MESSAGE); + return; + } + } + + if (evt.getSource().equals(mOK) || evt.getSource().equals(mCancel)) + this.dispose(); + } + + /*========================================================== + * private methods + *==========================================================*/ + protected void setDisplay() { + getContentPane().setLayout(new BorderLayout()); + JPanel center = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + center.setLayout(gb); + + //content panel + JPanel content = makeContentPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gb.setConstraints(content, gbc); + center.add(content); + + //action panel + JPanel action = makeActionPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gb.setConstraints(action, gbc); + center.add(action); + + getContentPane().add("Center",center); + } + + //create botton action panel + private JPanel makeActionPane() { + mOK = CMSAdminUtil.makeJButton(mResource, mPrefix, "OK", null, this); + if (mType.equals(Constants.VIEW)) + mOK.setEnabled(false); + else + mOK.setEnabled(true); + mCancel = CMSAdminUtil.makeJButton(mResource, mPrefix, "CANCEL", null, this); + mHelp = CMSAdminUtil.makeJButton(mResource, mPrefix, "HELP", null, this); + // JButton[] buttons = { mOK, mCancel, mHelp}; + JButton[] buttons = { mOK, mCancel}; + JButtonFactory.resize( buttons ); + return CMSAdminUtil.makeJButtonPanel( buttons, true); + } + + private JPanel makeContentPane() { + JPanel mListPanel = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + mListPanel.setLayout(gb); + //content.setBorder(CMSAdminUtil.makeEtchedBorder()); + + CMSAdminUtil.resetGBC(gbc); + JLabel label1 = CMSAdminUtil.makeJLabel(mResource, mPrefix, "RULENAME", null); + mAuthLabel = new JLabel(); + mAuthLabel.setVisible(false); + mAuthName = new JTextField(); + + gbc.fill = gbc.NONE; + gbc.weightx = 0.0; + gbc.anchor = gbc.EAST; + gbc. insets = new Insets(CMSAdminUtil.COMPONENT_SPACE, + CMSAdminUtil.COMPONENT_SPACE,0,0); + mListPanel.add(label1, gbc); + + gbc.anchor = gbc.WEST; + gbc.fill = gbc.HORIZONTAL; + gbc.weightx = 1.0; + gbc. insets = new Insets(CMSAdminUtil.COMPONENT_SPACE, + CMSAdminUtil.COMPONENT_SPACE, + 0,CMSAdminUtil.COMPONENT_SPACE); + mListPanel.add( mAuthLabel, gbc ); + mListPanel.add( mAuthName, gbc ); + + JLabel dummy = new JLabel(); + dummy.setVisible(false); + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 0.0; + mListPanel.add( dummy, gbc); + + CMSAdminUtil.resetGBC(gbc); + JLabel label3 = CMSAdminUtil.makeJLabel(mResource, mPrefix, "IMPLNAME", null); + mImplName = new JLabel(); + CMSAdminUtil.addEntryField(mListPanel, label3, mImplName, gbc); + + //left side certificate table + mTable = new JTable(mDataModel); + mScrollPane = JTable.createScrollPaneForTable(mTable); + //mScrollPane.setBorder(CMSAdminUtil.makeTitledBorder(mResource,PANEL_NAME,"USERS")); + mScrollPane.setHorizontalScrollBarPolicy(mScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mScrollPane.setVerticalScrollBarPolicy(mScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + mTable.setAutoscrolls(true); + mTable.sizeColumnsToFit(true); + mTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + //mTable.getSelectionModel().addListSelectionListener(this); + mScrollPane.setBackground(Color.white); + setLabelCellRenderer(mTable,0); + setLabelCellRenderer(mTable,1); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gb.setConstraints(mScrollPane, gbc); + mListPanel.add(mScrollPane); + + return mListPanel; + } + + //Set the first column's cellrender as label cell + protected void setLabelCellRenderer(JTable table, int index) { + //table.getColumnModel().getColumn(index).setCellRenderer(new DefaultTableCellRenderer()); + JLabel label = new JLabel(); + if (mType.equals(Constants.VIEW)) { + label.setEnabled(false); + table.getColumnModel().getColumn(index).setCellRenderer( + new CustomLabelCellRenderer(label)); + } else { + label.setEnabled(true); + table.getColumnModel().getColumn(index).setCellRenderer( + new LabelCellRenderer(label)); + } + } + + public class CustomLabelCellRenderer extends LabelCellRenderer { + public CustomLabelCellRenderer(JLabel x) { + super(x); + } + + public Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column) { + + if(value == null) { + value = table.getModel().getValueAt(row, column); + } + this.value.setValue(value); + component.setBackground(WHITECOLOR); + component.setForeground(WHITECOLOR); + return component; + } + } + + protected void addPolicyRule(NameValuePairs config, String name) + throws EAdminException + { + mConn.add(DestDef.DEST_AUTH_ADMIN, + ScopeDef.SC_AUTH_MGR_INSTANCE, + name, config); + } + + protected void modifyPolicyRule(NameValuePairs config, String name) + throws EAdminException + { + mConn.modify(DestDef.DEST_AUTH_ADMIN, + ScopeDef.SC_AUTH_MGR_INSTANCE, + name, config); + } +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthConfigDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthConfigDialog.java new file mode 100644 index 000000000..aa756b388 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthConfigDialog.java @@ -0,0 +1,91 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.config.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.table.*; +import javax.swing.text.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; +import com.netscape.management.client.*; +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + + +/** + * Auth Parameter Configuration Dialog + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class AuthConfigDialog extends CMSBaseConfigDialog +{ + /*========================================================== + * constructors + *==========================================================*/ + + public AuthConfigDialog(NameValuePairs nvp, + JFrame parent, + AdminConnection conn, + String dest) { + + super(parent,dest); + + PREFIX = "AUTHCONFIGDIALOG"; + RAHELPINDEX = "authentication-certsrv-edit-authrule-dbox-help"; + KRAHELPINDEX = "authentication-certsrv-edit-authrule-dbox-help"; + CAHELPINDEX = "authentication-certsrv-edit-authrule-dbox-help"; + mImplName_token = Constants.PR_AUTH_IMPL_NAME; + mImplType = Constants.PR_EXT_PLUGIN_IMPLTYPE_AUTH; + mHelpToken = "configuration-authentication"; + init (nvp,parent,conn,dest); + } + + public String getDefaultInstanceName(String implName) + { + Debug.println("Getting DefaultInstanceName for "+implName); + String instanceName = ""; + if (implName.equals("UidPwdDirAuth")) { + instanceName = "UserDirEnrollment"; + } + else if (implName.equals("UidPwdPinDirAuth")) { + instanceName = "PinDirEnrollment"; + } + else if (implName.equals("UdnPwdDirAuth")) { + instanceName = "UserDnEnrollment"; + } + else if (implName.equals("NISAuth")) { + instanceName = "NISAuth"; + } + else if (implName.equals("PortalEnroll")) { + instanceName = "PortalEnrollment"; + } + + Debug.println("Returning instance name "+instanceName); + return instanceName; + + } + + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthImplDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthImplDataModel.java new file mode 100644 index 000000000..98214871e --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthImplDataModel.java @@ -0,0 +1,72 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import java.util.*; +import javax.swing.*; +import com.netscape.certsrv.common.*; +import com.netscape.admin.certsrv.*; + +/** + * Auth Plugin Implementation Data model - represents the implementation + * table information + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class AuthImplDataModel extends CMSContentTableModel + implements IDataProcessor +{ + + /*========================================================== + * variables + *==========================================================*/ + public static final String IMPL_NAME = "NAME"; + public static final String IMPL_CLASS = "CLASS"; + public static final String IMPL_DESC = "DESC"; + public static final String IMPL_TYPE = "TYPE"; + + private static String[] mColumns = {POLICY_IMPL, CLASSNAME}; + + /*========================================================== + * constructors + *==========================================================*/ + public AuthImplDataModel() { + super(); + init(mColumns); + } + + /*========================================================== + * public methods + *==========================================================*/ + public void processData(Object data) { + Vector v = new Vector(); + NameValuePairs obj = (NameValuePairs) data; + JLabel label = new JLabel(obj.get(IMPL_NAME), + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_AUTH_PLUGIN), + JLabel.LEFT); + if(!obj.get(IMPL_DESC).trim().equals("")) + label.setToolTipText(obj.get(IMPL_DESC)); + v.addElement(label); + v.addElement(obj.get(IMPL_CLASS)); + //v.addElement(obj.getValue(IMPL_DESC)); + addRow(v, data); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthImplTab.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthImplTab.java new file mode 100644 index 000000000..0cc964c60 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthImplTab.java @@ -0,0 +1,353 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; + +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * Auth Plugin Management Tab + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class AuthImplTab extends CMSBaseUGTab { + + /*========================================================== + * variables + *==========================================================*/ + private static final String IMPL_NAME = AuthImplDataModel.IMPL_NAME; + private static final String IMPL_CLASS = AuthImplDataModel.IMPL_CLASS; + private static final String IMPL_DESC = AuthImplDataModel.IMPL_DESC; + private static final String IMPL_TYPE = AuthImplDataModel.IMPL_TYPE; + + private static final String PANEL_NAME = "AUTHIMPL"; + private static final String TOKEN = ";"; + + private AdminConnection mConnection; + private String mDestination; + + protected JScrollPane mScrollPane; + protected JTable mTable; //table + protected AuthImplDataModel mDataModel; //table model + protected AuthRegisterDialog mEditor=null; //keep single copy + protected JButton mRefresh, mAdd, mDelete, mHelp; + private static final String HELPINDEX = + "authentication-certsrv-authplugin-help"; + + /*========================================================== + * constructors + *==========================================================*/ + public AuthImplTab(CMSBaseResourceModel model) { + super(PANEL_NAME, model); + mConnection = model.getServerInfo().getAdmin(); + mDataModel = new AuthImplDataModel(); + mDestination = DestDef.DEST_AUTH_ADMIN; + mHelpToken = HELPINDEX; + } + + /*========================================================== + * public methods + *==========================================================*/ + + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(mRefresh)) { + refresh(); + } + if (e.getSource().equals(mAdd)) { + if (mEditor==null) + mEditor = new AuthRegisterDialog(mModel.getFrame(), mConnection); + mEditor.showDialog(mDestination, ScopeDef.SC_AUTH_IMPLS); + + if (mEditor.isOK()) + refresh(); + } + if (e.getSource().equals(mDelete)) { + Debug.println("Delete"); + if(mTable.getSelectedRow()< 0) + return; + int i = showConfirmDialog("DELETE"); + if (i == JOptionPane.YES_OPTION) { + delete(); + Debug.println("Deleted"); + } + } + if (e.getSource().equals(mHelp)) { + helpCallback(); + } + } + + //==== MOUSELISTENER ====================== + public void mouseClicked(MouseEvent e) { + setButtons(); + } + + public void mouseReleased(MouseEvent e) { + setButtons(); + } + + /*========================================================== + * protected methods + *==========================================================*/ + public void refresh() { + + mDataModel.removeAllRows(); + update(); + + setButtons(); + mTable.invalidate(); + mTable.validate(); + mScrollPane.invalidate(); + mScrollPane.validate(); + mScrollPane.repaint(1); + } + + /** + * create the user action button panel + */ + protected JPanel createButtonPanel() { + //edit, add, delete, help buttons required + //actionlister to this object + mAdd = makeJButton("ADD"); + mDelete = makeJButton("DELETE"); + JButton[] buttons = {mAdd, mDelete}; + JButtonFactory.resize( buttons ); + return CMSAdminUtil.makeJButtonVPanel( buttons ); + } + + protected JPanel createActionPanel() { + //edit, add, delete, help buttons required + //actionlister to this object + mRefresh = makeJButton("REFRESH"); + mHelp = makeJButton("HELP"); + //JButton[] buttons = { mRefresh, mHelp }; + JButton[] buttons = { mRefresh }; + return makeJButtonPanel(buttons, true); + } + + protected JPanel createListPanel() { + mListPanel = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + mListPanel.setLayout(gb); + + //center table + mTable = new JTable(mDataModel); + mScrollPane = JTable.createScrollPaneForTable(mTable); + //mScrollPane.setBorder(CMSAdminUtil.makeTitledBorder(mResource,PANEL_NAME,"USERS")); + mScrollPane.setHorizontalScrollBarPolicy(mScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mScrollPane.setVerticalScrollBarPolicy(mScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + mTable.setAutoscrolls(true); + mTable.sizeColumnsToFit(true); + mTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + mTable.getSelectionModel().addListSelectionListener(this); + mScrollPane.setBackground(Color.white); + mTable.addMouseListener(this); + setLabelCellRenderer(mTable,0); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.fill = gbc.BOTH; + gbc.gridwidth = 1; + gbc.weightx = 1.0; + gbc.insets = EMPTY_INSETS; + gb.setConstraints(mScrollPane, gbc); + mListPanel.add(mScrollPane); + + JPanel buttonPanel = createButtonPanel(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 0.0; + gbc.weighty = 1.0; + gbc.insets = EMPTY_INSETS; + gb.setConstraints(buttonPanel, gbc); + mListPanel.add(buttonPanel); + + refresh(); + + return mListPanel; + } + + //Set the first column's cellrender as label cell + protected void setLabelCellRenderer(JTable table, int index) { + table.getColumnModel().getColumn(index).setCellRenderer(new LabelCellRenderer(new JLabel())); + } + + /*========================================================== + * private methods + *==========================================================*/ + + //set buttons + private void setButtons() { + + //enable and diable buttons accordingly + //Debug.println("setButtons() - "+mTable.getSelectedRow()); + //Debug.println("setButtons() - "+mTable.getSelectionModel().isSelectionEmpty()); + if (mTable.getSelectionModel().isSelectionEmpty()) { + mDelete.setEnabled(false); + return; + } + + if(mDataModel.getRowCount()< 0) { + mDelete.setEnabled(false); + return; + } + + mDelete.setEnabled(true); + int index = mTable.getSelectedRow(); + + if (index >= 0) { + NameValuePairs nvp = + (NameValuePairs)mDataModel.getObjectValueAt(index); + String type = nvp.get(IMPL_TYPE); + if (type.equals(Constants.VIEW) || type.equals(Constants.VIEW)) + mDelete.setEnabled(false); + } + } + + //============================================= + // SEND REQUESTS TO THE SERVER SIDE + //============================================= + private void update() { + //send request and parse data + + mModel.progressStart(); + NameValuePairs response; + try { + response = mConnection.search(mDestination, + ScopeDef.SC_AUTH_IMPLS, + new NameValuePairs()); + } catch (EAdminException e) { + //display error dialog + showErrorDialog(e.getMessage()); + mModel.progressStop(); + return; + } + + Debug.println(response.toString()); + + //parse the response + //The response is a set of name + int i=0; + String[] vals = new String[response.size()]; + Hashtable data = new Hashtable(); + for (String entry : response.keySet()) { + entry = entry.trim(); + String value = response.get(entry); + Debug.println("AuthImplTab.java update(): "+ + "entry="+entry+ + "value="+value + ); + int x = value.indexOf(","); + int y = value.indexOf(TOKEN); + NameValuePairs obj = new NameValuePairs(); + obj.put(IMPL_NAME, entry); + Debug.println("x="+x); + if(x != -1) { + Debug.println("0 obj.add(IMPL_CLASS,"+value.substring(0,x)); + obj.put(IMPL_CLASS, value.substring(0, x)); + if (y == -1) { + Debug.println("1 obj.add(IMPL_DESC,"+value.substring(0,x)); + obj.put(IMPL_DESC, value.substring(x + 1)); + } + else { + Debug.println("1 obj.add(IMPL_DESC,"+value.substring(x+1,y)); + obj.put(IMPL_DESC, value.substring(x + 1, y)); + } + } else { + Debug.println(" 2 obj.add(IMPL_CLASS,"+value.substring(0,y)); + obj.put(IMPL_CLASS, value.substring(0, y)); + Debug.println(" 2 obj.add(IMPL_DESC,\"\""); + obj.put(IMPL_DESC, ""); + } + + String type = ""; + Debug.println("y="+y); + if (y == -1) { + type = Constants.EDIT; + obj.put(IMPL_TYPE, Constants.EDIT); + } else { + type = value.substring(y+1); + obj.put(IMPL_TYPE, type); + } + if (type.equals(Constants.EDIT)) { + data.put(entry,obj); + vals[i++]= entry ; + } + } + + if (i >= 1) { + String[] valCopy = new String[i]; + System.arraycopy(vals, 0, valCopy, 0, i); + CMSAdminUtil.bubbleSort(valCopy); + for (int y=0; y< valCopy.length ; y++) { + if (data.get(valCopy[y]) instanceof String) { + Debug.println("processData: "+(String)data.get(valCopy[y])); + } + mDataModel.processData(data.get(valCopy[y])); + } + + data.clear(); + } + + if (mDataModel.getRowCount() >0) + mTable.setRowSelectionInterval(0,0); + + mModel.progressStop(); + } + + private void delete() { + //get entry name + mModel.progressStart(); + NameValuePairs obj = (NameValuePairs) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + + //send comment to server for the removal of user + try { + mConnection.delete(mDestination, + ScopeDef.SC_AUTH_IMPLS, + obj.get(IMPL_NAME)); + } catch (EAdminException e) { + //display error dialog + showErrorDialog(e.getMessage()); + mModel.progressStop(); + return; + } + mModel.progressStop(); + //send comment to server and refetch the content + refresh(); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthInstanceTab.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthInstanceTab.java new file mode 100644 index 000000000..929f99aef --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthInstanceTab.java @@ -0,0 +1,141 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import com.netscape.admin.certsrv.config.*; +import javax.swing.*; + +import com.netscape.certsrv.common.*; + +/** + * Auth Instances Management Tab + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class AuthInstanceTab extends CMSPluginInstanceTab { + + /*========================================================== + * variables + *==========================================================*/ + private static final String PANEL_NAME = "AUTHRULE"; + private static final String ADMINRULE = "adminAuth"; + private static final String AGENTRULE = "agentAuth"; + + private static final String HELPINDEX = + "authentication-certsrv-authrules-help"; + + private static final String DEST = DestDef.DEST_AUTH_ADMIN; + + /*========================================================== + * constructors + *==========================================================*/ + public AuthInstanceTab(CMSBaseResourceModel model) { + super(model,DEST, PANEL_NAME ); + RULE_NAME = AuthRuleDataModel.RULE_NAME; + RULE_IMPL = AuthRuleDataModel.RULE_IMPL; + RULE_TYPE = AuthRuleDataModel.RULE_TYPE; + mConnection = model.getServerInfo().getAdmin(); + mDataModel = new AuthRuleDataModel(); + mScope = ScopeDef.SC_AUTH_MGR_INSTANCE; + mHelpToken = HELPINDEX; + } + + /*========================================================== + * public methods + *==========================================================*/ + + public CMSBaseConfigDialog makeNewConfigDialog( + NameValuePairs nvp, + JFrame parent, + AdminConnection conn, + String dest + ) + { + + return new AuthConfigDialog(nvp, + parent, + conn, + dest); + } + + public PluginSelectionDialog getPluginSelectionDialog( + JFrame parent, + AdminConnection conn, + String dest, + CMSPluginInstanceTab pluginType + ) + { + return new AuthPluginSelectionDialog(parent,conn,dest,pluginType); + } + + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + /*========================================================== + * protected methods + *==========================================================*/ + + + //============================================= + // SEND REQUESTS TO THE SERVER SIDE + //============================================= + + private void delete() { + + mModel.progressStart(); + //get entry name + NameValuePairs data = (NameValuePairs) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + + //send comment to server for the removal of user + try { + mConnection.delete(DestDef.DEST_AUTH_ADMIN, + ScopeDef.SC_AUTH_MGR_INSTANCE, + data.get(RULE_NAME)); + } catch (EAdminException e) { + //display error dialog + showErrorDialog(e.getMessage()); + mModel.progressStop(); + return; + } + + mModel.progressStop(); + //send comment to server and refetch the content + refresh(); + + } + + //this returns the configuration + private NameValuePairs getConfig() throws EAdminException { + NameValuePairs data = (NameValuePairs) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + + NameValuePairs response; + response = mConnection.read(DestDef.DEST_AUTH_ADMIN, + ScopeDef.SC_AUTH_MGR_INSTANCE, + data.get(RULE_NAME), + new NameValuePairs()); + return response; + } +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthPluginSelectionDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthPluginSelectionDialog.java new file mode 100644 index 000000000..8721363d1 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthPluginSelectionDialog.java @@ -0,0 +1,95 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.config.*; +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; +import com.netscape.management.client.*; +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * Auth Plugin Selection Dialog + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class AuthPluginSelectionDialog extends PluginSelectionDialog +{ + /*========================================================== + * variables + *==========================================================*/ + private static String PREFIX = "AUTHSELECTIONDIALOG"; + +/* + private final static String token = ";"; + private JFrame mParentFrame; + private AdminConnection mConnection; + private ResourceBundle mResource; + protected DefaultListModel mDataModel; + private CMSBaseResourceModel mModel; + + private JScrollPane mScrollPane; + private JList mList; + + private JButton mOK, mCancel, mHelp; +*/ + + /*========================================================== + * constructors + *==========================================================*/ + public AuthPluginSelectionDialog(JFrame parent, + AdminConnection conn, + String dest, + CMSPluginInstanceTab pluginType) { + + super(PREFIX,parent,conn,dest,pluginType); + mScope = ScopeDef.SC_AUTH_IMPLS; + mInstanceScope = ScopeDef.SC_AUTH_MGR_INSTANCE; + mImageName = CMSAdminResources.IMAGE_RULE_PLUGIN; + + mHelpToken = "authentication-certsrv-add-authrule-dbox-help"; + setDisplay(); +/**** + super(model.getFrame(),true); + mParentFrame = model.getFrame(); + mModel = model; + mConnection = model.getServerInfo().getAdmin(); + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + mDataModel = new DefaultListModel(); + setTitle(mResource.getString(PREFIX+"_TITLE")); + setLocationRelativeTo(mParentFrame); + getRootPane().setDoubleBuffered(true); + setDisplay(); +***/ + } + + /*========================================================== + * public methods + *==========================================================*/ + + + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthRegisterDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthRegisterDialog.java new file mode 100644 index 000000000..f97a11388 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthRegisterDialog.java @@ -0,0 +1,40 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.config.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; + +/** + * Auth Plugin Implementation Registration Editor + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ + +public class AuthRegisterDialog extends RegisterDialog { + + private final static String PREFIX = "AUTHREGISTERDIALOG"; + + public AuthRegisterDialog(JFrame parent, AdminConnection conn) { + super(PREFIX, parent, conn); + setDisplay(); + } +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthRuleDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthRuleDataModel.java new file mode 100644 index 000000000..35e08d0eb --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthRuleDataModel.java @@ -0,0 +1,64 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import java.util.*; +import javax.swing.*; +import com.netscape.certsrv.common.*; +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.config.*; +import com.netscape.management.client.util.Debug; + + +/** + * Auth instance Data model - represents the instance + * table information + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class AuthRuleDataModel extends CMSRuleDataModel +{ + + /*========================================================== + * constructors + *==========================================================*/ + public AuthRuleDataModel() { + super(); + } + + protected String[] getColumns() { + Debug.println("PolicyRuleDataModel.getColumns()"); + String x[] = {RULE, PLUGIN}; + return x; + } + + public void processData(Object data) { + Vector v = new Vector(); + NameValuePairs obj = (NameValuePairs) data; + + //XXX NEED TO ADD STUFF + v.addElement(new JLabel(obj.get(RULE_NAME), + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_AUTH), + JLabel.LEFT)); + v.addElement(obj.get(RULE_IMPL)); + addRow(v, data); + } + + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/AuthViewDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/AuthViewDialog.java new file mode 100644 index 000000000..6f3ed575a --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/AuthViewDialog.java @@ -0,0 +1,65 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.config.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.table.*; +import javax.swing.text.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; +import com.netscape.management.client.*; +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * Authentication Parameter View Dialog + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class AuthViewDialog extends AuthBaseDialog +{ + /*========================================================== + * variables + *==========================================================*/ + private static final String PREFIX = "AUTHVIEWDIALOG"; + private static final String HELPINDEX = + "authentication-certsrv-view-authrule-dbox-help"; + + /*========================================================== + * constructors + *==========================================================*/ + public AuthViewDialog(CMSBaseResourceModel model) { + super(model.getFrame(), Constants.VIEW, PREFIX); + mConn = model.getServerInfo().getAdmin(); + mDataModel = new ViewTableModel(); + setDisplay(); + } + + public void actionPerformed(ActionEvent evt) { + super.actionPerformed(evt); + if (evt.getSource().equals(mHelp)) + CMSAdminUtil.help(HELPINDEX); + } +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/CMSBaseUGTab.java b/base/console/src/com/netscape/admin/certsrv/ug/CMSBaseUGTab.java new file mode 100644 index 000000000..8e7fb34dd --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/CMSBaseUGTab.java @@ -0,0 +1,153 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import java.util.*; +import java.awt.event.*; +import java.awt.*; +import javax.swing.*; +import javax.swing.border.*; + +/** + * Base class for the tabs in the User and group tabbed pane. + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public abstract class CMSBaseUGTab extends CMSBasePanel + implements MouseListener, IRefreshTab +{ + + /*========================================================== + * variables + *==========================================================*/ + protected CMSBaseResourceModel mModel; //resource model + + private String mTitle; // panel title actually shows + protected boolean mInit = false; // true if this panel is initialized + protected JPanel mListPanel, mActionPanel; //panels + protected String mHelpToken; + + /*========================================================== + * constructors + *==========================================================*/ + public CMSBaseUGTab(String panelName, CMSBaseResourceModel model) { + super(panelName); + mModel = model; + try { + String title = mResource.getString(mPanelName+"_TITLE"); + mTitle = title; + } catch (MissingResourceException e) { + mTitle = "Missing Title"; + } + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * Initialization of the panel. Subcalss must provide + * the proper implementation. + */ + public void init() { + setLayout(new BorderLayout()); + + //======== list panel ======================== + mListPanel = createListPanel(); + mListPanel.setBorder(new EmptyBorder(DIFFERENT_COMPONENT_SPACE, + DIFFERENT_COMPONENT_SPACE, + DIFFERENT_COMPONENT_SPACE - COMPONENT_SPACE, + DIFFERENT_COMPONENT_SPACE)); + add("Center",mListPanel); + + //====== action panel =========================== + mActionPanel = createActionPanel(); + add("South",mActionPanel); + } + + /** + * Called by the Tab parent to initialize the panel + */ + public void initialize() { + if (!mInit) { + init(); + mInit = true; + } + } + + + /** + * Returns the title of the tab + * @return string representation of the title + */ + public String getTitle() { + return mTitle; + } + + /** + * set the title of the tab + */ + public void setTitle(String title) { + mTitle = title; + } + + public void helpCallback() { + CMSAdminUtil.help(mHelpToken); + } + + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + + /*========================================================== + * protected methods + *==========================================================*/ + protected abstract JPanel createActionPanel(); + protected abstract JPanel createListPanel(); + + //=== OVERWRITE DIALOG MESSAGE ===================== + + protected void showMessageDialog(String keyword, int messageType ) { + CMSAdminUtil.showMessageDialog(mModel.getFrame(), mResource, mPanelName, keyword, messageType); + } + + protected void showMessageDialog(String keyword) { + showMessageDialog(keyword, ERROR_MESSAGE); + } + + protected int showConfirmDialog(String keyword, int messageType ) { + return CMSAdminUtil.showConfirmDialog(mModel.getFrame(), mResource, mPanelName, keyword, messageType); + } + + protected int showConfirmDialog(String keyword) { + return showConfirmDialog(keyword, WARNING_MESSAGE); + } + + protected int showConfirmDialog(String keyword, String[] params) { + return showConfirmDialog(keyword, params, WARNING_MESSAGE); + } + + protected void showErrorDialog(String message) { + CMSAdminUtil.showErrorDialog(mModel.getFrame(), mResource, message, ERROR_MESSAGE); + } + + public abstract void refresh(); +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/CMSUGTabPanel.java b/base/console/src/com/netscape/admin/certsrv/ug/CMSUGTabPanel.java new file mode 100644 index 000000000..b2f2b1c37 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/CMSUGTabPanel.java @@ -0,0 +1,136 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import javax.swing.*; +import javax.swing.event.*; +import com.netscape.management.client.*; +import com.netscape.management.client.util.*; +import javax.swing.tree.*; +import java.awt.event.*; +import java.awt.*; + +/** + * Base Class for Tabbed right hand pane + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class CMSUGTabPanel extends CMSBasePanel + implements IResourceSelectionListener, ChangeListener, + IRefreshTabPanel +{ + /*========================================================== + * variables + *==========================================================*/ + private static String PANEL_NAME = "CMSUGTABPANEL"; + + protected JTabbedPane mTabbedPane; //tabbed panel + protected CMSBaseResourceModel mModel; //resource model + protected ResourceObject mParent; //tree node parent + + /*========================================================== + * constructors + *==========================================================*/ + public CMSUGTabPanel(CMSBaseResourceModel model, ResourceObject parent) { + super(PANEL_NAME); + mModel = model; + mParent = parent; + mModel.addIResourceSelectionListener(this); + + setLayout(new BorderLayout()); + // Look and Feel + mTabbedPane = new NSTabbedPane(); + add("Center", mTabbedPane); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * Retrieve Resource Model + */ + public CMSBaseResourceModel getResourceModel() { + return mModel; + } + + //== IResourceListener === + + public void select(IResourceObject parent, Object viewInstance) { + //System.out.println("CMSTabPanel: select() "+ parent); + if (parent == mParent) { + try { + mTabbedPane.addChangeListener(this); + mTabbedPane.setSelectedIndex(0); + CMSBaseUGTab selectedPanel = (CMSBaseUGTab) mTabbedPane.getComponentAt(0); + if ( selectedPanel != null ) + selectedPanel.initialize(); + mTabbedPane.invalidate(); + mTabbedPane.validate(); + } catch (ArrayIndexOutOfBoundsException e) { + //NO TAB SO IGNORE + } + } + } + + public boolean unselect(IResourceObject parent, Object viewInstance) { + return true; + } + + public CMSBasePanel getSelectedTab() { + //Debug.println("CMSUGTabPanel: getSelectedTab()"); + return (CMSBasePanel)mTabbedPane.getSelectedComponent(); + } + + //== ChangeListener == + public void stateChanged(ChangeEvent e) { + //Debug.println("CMSTabPanel: stateChanged()"); + CMSBaseUGTab selectedPanel = (CMSBaseUGTab)mTabbedPane.getSelectedComponent(); + if ( selectedPanel != null ) + selectedPanel.initialize(); + mTabbedPane.invalidate(); + mTabbedPane.validate(); + mTabbedPane.repaint(1); + } + + /** + * Add Panels to the Tab Panel. ChangeListener is + * added automatically. + * + * @param p CMS Panel to be added + */ + public void addTab(CMSBaseUGTab p) { + mTabbedPane.addTab(p.getTitle(), p); + } + + /*========================================================== + * protected methods + *==========================================================*/ + + //look and feel + class NSTabbedPane extends JTabbedPane { +/* + public String getUIClassID() { + return "SecondaryTabbedPaneUI"; + } +*/ + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/CertDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/CertDataModel.java new file mode 100644 index 000000000..de6a588f6 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/CertDataModel.java @@ -0,0 +1,85 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.certsrv.common.*; +import com.netscape.management.client.util.*; +import java.util.*; +import javax.swing.*; + +/** + * Certificate Data Model + * Single column display with internal data object as NVP + * which stores Name and Data Blob (PrettyPrint or B64E) + */ +public class CertDataModel extends CMSContentTableModel + implements IDataProcessor +{ + /*========================================================== + * variables + *==========================================================*/ + public static final String CERT_NAME="CERT_NAME"; + public static final String CERT_DATA="CERT_DATA"; + public static final String CERT_VIEW="CERT_VIEW"; + public static final String CERT_B64E="CERT_B64E"; + public static final String CERT_PP="CERT_PP"; + + private static String[] mColumns = {CERTIFICATE}; + + /*========================================================== + * constructors + *==========================================================*/ + public CertDataModel() { + super(); + init(mColumns); + } + + /*========================================================== + * public methods + *==========================================================*/ + public void processData(Object data) { + Vector v = new Vector(); + + NameValuePairs obj = (NameValuePairs) data; + + //XXX NEED TO CHANGE if we are going to have multi-column table + v.addElement(new JLabel(obj.get(CERT_NAME), + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_CERTICON_SMALL), + JLabel.LEFT)); + addRow(v, data); + } + + /** + * Retrieve the data blob, Certificate Pretty Print + * or Base64Encode cert, from the data object. Used + * by the view functionality. + * + * @param row cert table row number + * @retrun data in string format + */ + public String getDataBlob(int row) { + try { + NameValuePairs obj = (NameValuePairs)getObjectValueAt(row); + return obj.get(CERT_DATA); + } catch (Exception e) { + Debug.println("CertDataModel: getDataBlob()- "+e.toString()); + return ""; + } + } +} \ No newline at end of file diff --git a/base/console/src/com/netscape/admin/certsrv/ug/CertImportDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/CertImportDialog.java new file mode 100644 index 000000000..758dda109 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/CertImportDialog.java @@ -0,0 +1,256 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; +import com.netscape.management.client.*; +import com.netscape.management.client.util.*; +import javax.swing.table.*; +import com.netscape.admin.certsrv.connection.*; +import com.netscape.certsrv.common.*; + +/** + * Certificate Import Editor - this UI will take Base64Encoded + * certificate block with BEGIN and END comment and deliver it + * to server side for processing. EOL, CRT, EOF characters are + * removed from the output. + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug.CertManagementDialog + */ +public class CertImportDialog extends JDialog + implements ActionListener, DocumentListener, MouseListener +{ + /*========================================================== + * variables + *==========================================================*/ + private String PREFIX = "CERTIMPORTDIALOG"; + + private JFrame mParentFrame; + private ResourceBundle mResource; + + private JTextArea mTextArea; + private JButton mOK, mCancel; + private String mB64E; + private boolean mIsOk = false; + private JButton mPaste; + + /*========================================================== + * constructors + *==========================================================*/ + public CertImportDialog(JFrame parent) { + super(parent,true); + mParentFrame = parent; + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + setSize(500, 400); + setTitle(mResource.getString(PREFIX+"_TITLE")); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + setDisplay(); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + */ + public void showDialog() { + //initialize and setup + mTextArea.setText(""); + mIsOk = false; + this.show(); + } + + /** + * get Base 64 Encoded blob + */ + public String getB64E() { + return mB64E; + } + + /** + * get the exit code + * @return true if ok; otherwise false + */ + public boolean isOK() { + return mIsOk; + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent evt) { + + if (evt.getSource().equals(mPaste)) { + mTextArea.paste(); + return; + } + + if (evt.getSource().equals(mCancel)) { + this.hide(); + } + + if (evt.getSource().equals(mOK)) { + + //set values + mB64E = mTextArea.getText().trim(); + mIsOk = true; + this.hide(); + } + } + + //==== MOUSELISTENER ====================== + public void mouseClicked(MouseEvent e) { + setButtons(); + } + + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) { + setButtons(); + } + + //== DocumentListener == + public void insertUpdate(DocumentEvent e) { + setButtons(); + } + + public void removeUpdate(DocumentEvent e){ + setButtons(); + } + + public void changedUpdate(DocumentEvent e){ + setButtons(); + } + + /*========================================================== + * private methods + *==========================================================*/ + + /** + * set buttons - proactive verification + */ + private void setButtons() { + if (mTextArea.getText().trim().equals("")) { + mOK.setEnabled(false); + } else { + mOK.setEnabled(true); + } + } + + /** + * Setup the initial UI components + */ + private void setDisplay() { + getContentPane().setLayout(new BorderLayout()); + JPanel center = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + center.setLayout(gb); + + //content panel + JPanel content = makeContentPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.fill = gbc.BOTH; + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gb.setConstraints(content, gbc); + center.add(content); + + //action panel + JPanel action = makeActionPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gb.setConstraints(action, gbc); + center.add(action); + + getContentPane().add("Center",center); + } + + private JPanel makeActionPane() { + mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, this); + mOK.setEnabled(false); + mCancel = CMSAdminUtil.makeJButton(mResource, PREFIX, "CANCEL", null, this); + JButton[] buttons = { mOK, mCancel}; + return CMSAdminUtil.makeJButtonPanel( buttons ); + } + + private JPanel makeContentPane() { + JPanel content = new JPanel(); + GridBagLayout gb3 = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + content.setLayout(gb3); + //content.setBorder(CMSAdminUtil.makeEtchedBorder()); + + CMSAdminUtil.resetGBC(gbc); + JLabel label2 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "B64E", null); + gbc.fill = gbc.NONE; + gbc.anchor = gbc.WEST; + gbc.weightx=0.0; + gb3.setConstraints(label2, gbc); + content.add(label2); + + CMSAdminUtil.resetGBC(gbc); + mPaste = CMSAdminUtil.makeJButton(mResource, PREFIX, "PASTE", null, this); + gbc.fill = gbc.NONE; + gbc.anchor = gbc.EAST; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx=1.0; + gb3.setConstraints(mPaste, gbc); + content.add(mPaste); + + CMSAdminUtil.resetGBC(gbc); + mTextArea = new JTextArea("",40,70); + Font f = new Font("Monospaced", Font.PLAIN, 12); + if (f != null) mTextArea.setFont(f); + mTextArea.getDocument().addDocumentListener(this); + mTextArea.addMouseListener(this); + JScrollPane scrollPanel = new JScrollPane(mTextArea, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPanel.setAlignmentX(LEFT_ALIGNMENT); + scrollPanel.setAlignmentY(TOP_ALIGNMENT); + scrollPanel.setBorder(BorderFactory.createLoweredBevelBorder()); + scrollPanel.setPreferredSize(new Dimension(300, 500)); + gbc.fill = gbc.BOTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx=1.0; + gbc.weighty=1.0; + gb3.setConstraints(scrollPanel, gbc); + content.add(scrollPanel); + + return content; + } +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/CertManagementDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/CertManagementDialog.java new file mode 100644 index 000000000..82083649e --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/CertManagementDialog.java @@ -0,0 +1,441 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * User Certificate Management Dialog -

+ * + * The administrator can use this dialog to management the + * certificates of specific user. This allows the import of + * new certificates and delete/view of existing certificates. + * + * This dialog is launched by clicking on the certificate button + * on the main user management tab. + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug.CertImportDialog + * @see com.netscape.admin.certsrv.ug.CertViewDialog + * @see com.netscape.admin.certsrv.ug.UserTab + */ +public class CertManagementDialog extends JDialog + implements ActionListener, MouseListener +{ + /*========================================================== + * variables + *==========================================================*/ + private String PREFIX = "CERTMANAGEMENTDIALOG"; + + private JFrame mParentFrame; + private AdminConnection mConnection; + private ResourceBundle mResource; + protected DefaultListModel mDataModel; + protected Vector mPPData; + protected String mUID; //dest flag + protected CertViewDialog mViewDialog = null; //keeping a copy for reuse + protected CertImportDialog mCertDialog = null; //keeping a copy for reuse + + private JScrollPane mScrollPane; + private JList mList; + + private JButton mOK, mCancel, mAdd, mDelete, mView, mHelp; + private final static String HELPINDEX = + "usersgroups-certsrv-manage-usercert-dbox-help"; + + /*========================================================== + * constructors + *==========================================================*/ + public CertManagementDialog(JFrame parent, AdminConnection conn) { + super(parent,true); + mParentFrame = parent; + mConnection = conn; + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + mDataModel = new DefaultListModel(); + mPPData = new Vector(); + setSize(800, 216); + setTitle(mResource.getString(PREFIX+"_TITLE")); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + setDisplay(); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + * @param uid current user id + */ + public void showDialog(String uid) { + mUID = uid; + + if (!refresh()) + return; + setButtons(); + this.show(); + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent evt) { + + if (evt.getSource().equals(mOK)) { + //nothing to do here + this.dispose(); + } else if (evt.getSource().equals(mCancel)) { + this.dispose(); + } else if (evt.getSource().equals(mAdd)) { + //call cert import editor + if (mCertDialog==null) + mCertDialog = new CertImportDialog(mParentFrame); + mCertDialog.showDialog(); + if (!mCertDialog.isOK()) + return; + addCert(mCertDialog.getB64E()); + refresh(); + setButtons(); + } else if (evt.getSource().equals(mDelete)) { + int i = CMSAdminUtil.showConfirmDialog(mParentFrame, mResource, "USERCERTS", + "DELETE", JOptionPane.INFORMATION_MESSAGE); + if (i == JOptionPane.YES_OPTION) { + deleteCert(); + refresh(); + setButtons(); + } + } else if (evt.getSource().equals(mView)) { + if (mViewDialog==null) + mViewDialog = new CertViewDialog(mParentFrame); + String id = ((JLabel)mDataModel.elementAt(mList.getSelectedIndex())).getText(); + mViewDialog.showDialog(id,(String)mPPData.elementAt(mList.getSelectedIndex())); + } else if (evt.getSource().equals(mHelp)) { + CMSAdminUtil.help(HELPINDEX); + } + } + + //==== MOUSELISTENER ====================== + public void mouseClicked(MouseEvent e) { + setButtons(); + } + + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + + /*========================================================== + * private methods + *==========================================================*/ + + /** + * Setup the initial UI components + */ + private void setDisplay() { + getContentPane().setLayout(new BorderLayout()); + JPanel center = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + center.setLayout(gb); + + //content panel + JPanel content = makeContentPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.fill = gbc.BOTH; + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gb.setConstraints(content, gbc); + center.add(content); + + //action panel + JPanel action = makeActionPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gb.setConstraints(action, gbc); + center.add(action); + + getContentPane().add("Center",center); + } + + /** + * create the bottom action button panel + */ + protected JPanel createUDButtonPanel() { + //up, down buttons required + //actionlister to this object + mAdd = CMSAdminUtil.makeJButton(mResource, PREFIX, "IMPORT", null, this); + mDelete = CMSAdminUtil.makeJButton(mResource, PREFIX, "DELETE", null, this); + mView = CMSAdminUtil.makeJButton(mResource, PREFIX, "VIEW", null, this); + JButton[] buttons = { mAdd, mDelete, mView}; + JButtonFactory.resize( buttons ); + return CMSAdminUtil.makeJButtonVPanel( buttons ); + } + + //create botton action panel + private JPanel makeActionPane() { + mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, this); + mCancel = CMSAdminUtil.makeJButton(mResource, PREFIX, "CANCEL", null, this); + mHelp = CMSAdminUtil.makeJButton(mResource, PREFIX, "HELP", null, this); + // JButton[] buttons = { mOK, mHelp}; + JButton[] buttons = { mOK}; + JButtonFactory.resize( buttons ); + return CMSAdminUtil.makeJButtonPanel( buttons, true); + } + + private JPanel makeContentPane() { + JPanel mListPanel = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + mListPanel.setLayout(gb); + //content.setBorder(CMSAdminUtil.makeEtchedBorder()); + + //left side certificate table + mList = CMSAdminUtil.makeJList(mDataModel,10); + mScrollPane = new JScrollPane(mList, + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + mList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); + mList.addMouseListener(this); + mScrollPane.setBackground(Color.white); + mScrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.fill = gbc.BOTH; + gbc.gridwidth = 1; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbc.insets = new Insets(CMSAdminUtil.COMPONENT_SPACE,CMSAdminUtil.COMPONENT_SPACE,0,0); + gb.setConstraints(mScrollPane, gbc); + mListPanel.add(mScrollPane); + + JPanel buttonPanel = createUDButtonPanel(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 0.0; + gbc.weighty = 1.0; + gbc.insets = new Insets(CMSAdminUtil.COMPONENT_SPACE, + 0,0,CMSAdminUtil.COMPONENT_SPACE); + gb.setConstraints(buttonPanel, gbc); + mListPanel.add(buttonPanel); + + return mListPanel; + } + + /** + * set buttons - proactive verification + */ + private void setButtons() { + + //enable and diable buttons accordingly + //Debug.println("setButtons() - "+mList.getSelectedIndex()); + if (mList.getSelectedIndex()< 0) { + mDelete.setEnabled(false); + mView.setEnabled(false); + return; + } + mDelete.setEnabled(true); + mView.setEnabled(true); + } + + //================================================= + // RETRIEVE INFO FROM SERVER SIDE + //================================================= + + //refresh the table content + private boolean refresh() { + + mDataModel.clear(); + mPPData.removeAllElements(); + + NameValuePairs response; + try { + response = mConnection.read(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USER_CERTS, + mUID, new NameValuePairs()); + } catch (EAdminException e) { + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.getMessage(), CMSAdminUtil.ERROR_MESSAGE); + return false; + } + + //parse data + String[] vals = new String[response.size()]; + int i=0; + + for (String entry : response.keySet()) { + vals[i++] = entry.trim(); + } + + CMSAdminUtil.bubbleSort(vals); + + for (int y=0; y< vals.length ; y++) { + String str = reformat(vals[y]); + mDataModel.addElement(new JLabel(str, + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_CERTICON_SMALL), + JLabel.LEFT)); + mPPData.addElement(response.get(vals[y])); + } + + return true; + } + + /** + * Change DN from the following format: + * Serial:0x0 Subject: Issuer: + * to the following fomrat: + * ;;; + */ + private String toServerFormat(String val) { + if (val == null) + return ""; + int subject_pos = val.indexOf("Subject:"); + if (subject_pos == -1) + return ""; + int issuer_pos = val.indexOf("Issuer:"); + if (issuer_pos == -1) + return ""; + // we lost the version in reformat() + + String serial = val.substring(9, subject_pos).trim(); + long num = CMSAdminUtil.hexToLong(serial); + try { + return "-1;" + + num + ";" + + val.substring(issuer_pos+7).trim() + ";" + + val.substring(subject_pos+8, issuer_pos).trim(); + } catch (NumberFormatException e) { + return "-1;" + num+";"+ + val.substring(issuer_pos+7).trim() + ";" + + val.substring(subject_pos+8, issuer_pos).trim(); + } + } + + // swap the issuer name order with the subject name + private String reformat(String val) { + + String name = ""; + + StringTokenizer st = new StringTokenizer(val,";",false); + String version=null; // I think this is cert version # + String serial=null; + String issuer=null; + String subject=null; + + try { + version = st.nextToken(); + serial = st.nextToken(); + issuer = st.nextToken(); + subject = st.nextToken(); + } catch (Exception e) {} + + try { + if (serial != null) { + String hexserial = Integer.toHexString(Integer.parseInt(serial)); + name = name + "Serial:0x"+hexserial; + } + } catch (Exception e) {} + + + if (subject != null) { + name = name + " Subject:"+subject; + } + + if (issuer != null) { + name = name + " Issuer:"+issuer; + } + + return name; + } + + private void addCert(String B64E) { + //send comment to server for the removal of user + NameValuePairs config = new NameValuePairs(); + config.put(Constants.PR_USER_CERT, cleanupCertData(B64E)); + try { + mConnection.add(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USER_CERTS, + mUID, + config); + } catch (EAdminException e) { + //display error dialog + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.getMessage(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + } + + /** + * routine to cleanup the certificate data + * this removes end of line embedded in the + * certificate data. + * + * @param data b64e cert request blob + */ + private String cleanupCertData(String data) { + StringBuffer input = new StringBuffer(data); + StringBuffer buff = new StringBuffer(); + for (int i=0; i< input.length(); i++) { + char c = input.charAt(i); + if ((c != '\n') && (c != '\r')) + buff.append(c); + } + return buff.toString(); + } + + private void deleteCert() { + //get entry name + String dn = ((JLabel)mDataModel.elementAt(mList.getSelectedIndex())).getText(); + dn = toServerFormat(dn); + NameValuePairs config = new NameValuePairs(); + config.put(Constants.PR_USER_CERT, dn); + + //send comment to server for the removal of user + try { + mConnection.modify(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USER_CERTS, + mUID, + config); + } catch (EAdminException e) { + //display error dialog + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.getMessage(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/CertViewDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/CertViewDialog.java new file mode 100644 index 000000000..ae4cfd113 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/CertViewDialog.java @@ -0,0 +1,201 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; +import com.netscape.management.client.*; +import com.netscape.management.client.util.*; +import javax.swing.table.*; +import com.netscape.admin.certsrv.connection.*; +import com.netscape.certsrv.common.*; + +/** + * Certificate Import Editor + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class CertViewDialog extends JDialog + implements ActionListener +{ + /*========================================================== + * variables + *==========================================================*/ + private String PREFIX = "CERTVIEWDIALOG"; + + private JFrame mParentFrame; + private ResourceBundle mResource; + private JTextArea mTextArea; + private JLabel mCertNameField; + + private JButton mOK; + + /*========================================================== + * constructors + *==========================================================*/ + public CertViewDialog(JFrame parent) { + super(parent,true); + mParentFrame = parent; + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + //setSize(800, 700); + setSize(400, 350); + setTitle(mResource.getString(PREFIX+"_TITLE")); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + setDisplay(); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + */ + public void showDialog(String name, String pp) { + //initialize and setup + String certName = ""; + if (name != null && name.length() > 0) { + int j = name.indexOf("Subject:"); + int i = name.indexOf("Issuer:"); + if (j < i) { + certName = name.substring(j, i); + } + } + mCertNameField.setText(certName); + mTextArea.setText(pp); + this.show(); + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent evt) { + if (evt.getSource().equals(mOK)) { + this.hide(); + } + } + + /*========================================================== + * private methods + *==========================================================*/ + private void setDisplay() { + getContentPane().setLayout(new BorderLayout()); + JPanel center = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + center.setLayout(gb); + + //content panel + JPanel content = makeContentPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.fill = gbc.BOTH; + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gb.setConstraints(content, gbc); + center.add(content); + + //action panel + JPanel action = makeActionPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gb.setConstraints(action, gbc); + center.add(action); + + getContentPane().add("Center",center); + } + + private JPanel makeActionPane() { + mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, this); + Dimension d = mOK.getMinimumSize(); + if (d.width < CMSAdminUtil.DEFAULT_BUTTON_SIZE) { + d.width = CMSAdminUtil.DEFAULT_BUTTON_SIZE; + mOK.setMinimumSize(d); + } + JButton[] buttons = {mOK}; + return CMSAdminUtil.makeJButtonPanel( buttons ); + } + + private JPanel makeContentPane() { + JPanel content = new JPanel(); + GridBagLayout gb3 = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + content.setLayout(gb3); + //content.setBorder(CMSAdminUtil.makeEtchedBorder()); + + CMSAdminUtil.resetGBC(gbc); + //JLabel label1 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "CERTNAME", null); + mCertNameField = new JLabel(); + gbc.fill = gbc.NONE; + gbc.anchor = gbc.WEST; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx=1.0; + gbc.weightx=0.0; + gb3.setConstraints(mCertNameField, gbc); + content.add(mCertNameField); + //CMSAdminUtil.addEntryField(content, label1, mCertNameField, gbc); + + CMSAdminUtil.resetGBC(gbc); + JLabel label2 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "PP", null); + gbc.fill = gbc.NONE; + gbc.anchor = gbc.WEST; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx=1.0; + gb3.setConstraints(label2, gbc); + content.add(label2); + + CMSAdminUtil.resetGBC(gbc); + mTextArea = new JTextArea("",40,70); + Font f = new Font("Monospaced", Font.PLAIN, 12); + if (f != null) mTextArea.setFont(f); + mTextArea.setEditable(false); + mTextArea.setBackground(getBackground()); + JScrollPane scrollPanel = new JScrollPane(mTextArea, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPanel.setAlignmentX(LEFT_ALIGNMENT); + scrollPanel.setAlignmentY(TOP_ALIGNMENT); + scrollPanel.setBorder(BorderFactory.createLoweredBevelBorder()); + scrollPanel.setPreferredSize(new Dimension(300, 500)); + gbc.fill = gbc.BOTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx=1.0; + gbc.weighty=1.0; +// gbc.insets = new Insets(0, CMSAdminUtil.COMPONENT_SPACE, +// CMSAdminUtil.COMPONENT_SPACE, +// CMSAdminUtil.COMPONENT_SPACE); + gb3.setConstraints(scrollPanel, gbc); + content.add(scrollPanel); + + return content; + } +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/GroupDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/GroupDataModel.java new file mode 100644 index 000000000..779e9903e --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/GroupDataModel.java @@ -0,0 +1,61 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import java.util.*; +import javax.swing.*; +import com.netscape.certsrv.common.*; +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; + +/** + * Group Data model - represents the group table information + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class GroupDataModel extends CMSContentTableModel { + + /*========================================================== + * variables + *==========================================================*/ + private static String[] mColumns = {GROUPNAME, GROUPDESC}; + + /*========================================================== + * constructors + *==========================================================*/ + public GroupDataModel() { + super(); + init(mColumns); + } + + /*========================================================== + * public methods + *==========================================================*/ + public void processData(String name, String desc) { + Vector v = new Vector(); + + //XXX NEED TO CHANGE if we are going to have multi-column table + v.addElement(new JLabel((String)name, + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_USERGROUP), + JLabel.LEFT)); + v.addElement(desc); + addRow(v,name); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/GroupEditor.java b/base/console/src/com/netscape/admin/certsrv/ug/GroupEditor.java new file mode 100644 index 000000000..e9693b15d --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/GroupEditor.java @@ -0,0 +1,596 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * Group Membership Editor + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class GroupEditor extends JDialog + implements ActionListener, ListSelectionListener +{ + + /*========================================================== + * variables + *==========================================================*/ + private String PREFIX = "GROUPEDITOR"; + + private JFrame mParentFrame; + private AdminConnection mConnection; + private String mGroupName; + private boolean mIsNewGroup = false; + private ResourceBundle mResource; + protected DefaultListModel mDataModel; + protected UserListDialog mUserDialog = null; //keeping a copy for reuse + + protected JScrollPane mScrollPane; + protected JList mList; + + private JButton mOK, mCancel, mHelp, mAddUser, mDelete; + private JTextField mGroupNameField, mGroupDescField; + private JLabel mGroupNameLabel; + + private static final String ADDHELPINDEX = + "usersgroups-certsrv-add-group-dbox-help"; + private static final String EDITHELPINDEX = + "usersgroups-certsrv-edit-group-dbox-help"; + private String mHelpToken; + + /*========================================================== + * constructors + *==========================================================*/ + public GroupEditor(JFrame parent, AdminConnection conn) { + super(parent,true); + mParentFrame = parent; + mConnection = conn; + mDataModel = new DefaultListModel(); + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + + setSize(360, 300); + setTitle(mResource.getString(PREFIX+"_TITLE")); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + setDisplay(); + //toFront(); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + * @param users list of current groups + */ + public void showDialog(String group, boolean isNew) { + + //initialize and setup + mGroupName = group; + mIsNewGroup = isNew; + + if (isNew) + mHelpToken = ADDHELPINDEX; + else + mHelpToken = EDITHELPINDEX; + + mGroupDescField.setText(""); + mGroupNameField.setText(""); + + mDataModel.clear(); + + //disable name change + if(!mIsNewGroup) { + mGroupNameField.setVisible(false); + mGroupNameLabel.setVisible(true); + mGroupNameLabel.setText(mGroupName); + } else { + mGroupNameField.setVisible(true); + mGroupNameLabel.setVisible(false); + } + + //retrieve the user record from the server + try { + if (mIsNewGroup == false) + refresh(); + } catch (EAdminException ex) { + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + ex.toString(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + + setButtons(); + this.show(); + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + + public void actionPerformed(ActionEvent evt) { + + if (evt.getSource().equals(mOK)) { + + if (mIsNewGroup) { + + //check text fields + if (mGroupNameField.getText().trim().equals("")) { + CMSAdminUtil.showMessageDialog(mParentFrame, mResource, PREFIX, + "NOGROUPNAME", CMSAdminUtil.ERROR_MESSAGE); + return; + } + + try { + mGroupName = mGroupNameField.getText().trim(); + addGroup(); + } catch (EAdminException e) { + //display error dialog + Debug.println(e.toString()); + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.toString(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + + } else { + + try { + modifyGroup(); + } catch (EAdminException e) { + //display error dialog + Debug.println(e.toString()); + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.toString(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + + } + this.hide(); + } + + if (evt.getSource().equals(mCancel)) { + Debug.println("Cancel Pressed"); + + //display are you sure dialog + this.hide(); + } + + if (evt.getSource().equals(mHelp)) { + CMSAdminUtil.help(mHelpToken); + } + + if (evt.getSource().equals(mAddUser)) { + //bring up the list for selection + + //create vector here + Vector currentUser = new Vector(); + for (int i=0; i0) + for (int i=0; i0) + userBuf.append(","); + userBuf.append(data); + } + + //set parameters + config.put(Constants.PR_GROUP_USER, userBuf.toString()); + } + + //refresh the table content + private void refreshTable() { + //Debug.println("GroupEditor: refreshTable() - start"); + //mTable.invalidate(); + //mTable.validate(); + //mTable.repaint(1); + //mScrollPane.invalidate(); + //mScrollPane.validate(); + //mScrollPane.repaint(1); + //Debug.println("GroupEditor: refreshTable() - end"); + } + + public JList makeJList(DefaultListModel listModel, int visibleCount) { + JList listbox = new JList(listModel); + listbox.setCellRenderer(new AttrCellRenderer()); + listbox.setSelectionModel(new DefaultListSelectionModel()); + listbox.setVisibleRowCount(visibleCount); + if(listModel.size()!=0) + listbox.setSelectedIndex(0); + return listbox; + } + +} + + diff --git a/base/console/src/com/netscape/admin/certsrv/ug/GroupListDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/GroupListDataModel.java new file mode 100644 index 000000000..7893d9cb0 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/GroupListDataModel.java @@ -0,0 +1,67 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import java.util.*; +import javax.swing.*; +import com.netscape.certsrv.common.*; +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; + +/** + * Group List Data model - represents the group selection information + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class GroupListDataModel extends CMSContentTableModel + implements IDataProcessor +{ + + /*========================================================== + * variables + *==========================================================*/ + private static String[] mColumns = {GROUPNAME}; + + /*========================================================== + * constructors + *==========================================================*/ + public GroupListDataModel() { + super(); + init(mColumns); + } + + /*========================================================== + * public methods + *==========================================================*/ + public void processData(Object data) { + Vector v = new Vector(); + + String entry = (String)data; + String name; + if (entry.startsWith(PrefixDef.PX_SYS)) + name = entry.substring(PrefixDef.PX_SYS.length()); + else + name = entry.substring(PrefixDef.PX_DEF.length()); + + v.addElement(new JLabel(name, + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_USERGROUP), + JLabel.LEFT)); + addRow(v, data); + } +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/GroupListDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/GroupListDialog.java new file mode 100644 index 000000000..d5931a6f8 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/GroupListDialog.java @@ -0,0 +1,284 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; +import javax.swing.table.*; +import com.netscape.management.client.*; +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * Group Listing Dialog -

+ * + * This dialog support multiple group selection and displays + * only groups that are not in the current group. This dialog + * will be created once and being reused per group editor. + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class GroupListDialog extends JDialog + implements ActionListener +{ + /*========================================================== + * variables + *==========================================================*/ + private String PREFIX = "GROUPLISTDIALOG"; + + private JFrame mParentFrame; + private AdminConnection mConnection; + private ResourceBundle mResource; + protected GroupListDataModel mDataModel; + protected Vector mCurrentGroups; + protected Vector mSelectedGroups; + + private JScrollPane mScrollPane; + private JTable mTable; + + private JButton mOK, mCancel; + private boolean mIsOk = false; + + /*========================================================== + * constructors + *==========================================================*/ + public GroupListDialog(JFrame parent, AdminConnection conn) { + super(parent,true); + mParentFrame = parent; + mConnection = conn; + mSelectedGroups = new Vector(); + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + mDataModel = new GroupListDataModel(); + setSize(350, 300); + setTitle(mResource.getString(PREFIX+"_TITLE")); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + setDisplay(); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + * @param users list of current groups + */ + public void showDialog(Vector groups) { + + mCurrentGroups = groups; + mSelectedGroups.removeAllElements(); + + //retrieve the cert record from the server + try { + refresh(); + } catch (EAdminException ex) { + CMSAdminUtil.showMessageDialog(mParentFrame, mResource, PREFIX, + "SERVERERROR", CMSAdminUtil.ERROR_MESSAGE); + return; + } + mIsOk = false; + this.show(); + } + + + /** + * if selection is ok, the group names will be returned + * otherwise, empty vector will be returned. + * @return group names + */ + public Vector getSelectedGroup() { + return mSelectedGroups; + } + + /** + * get the exit code + * @return true if ok; otherwise false + */ + public boolean isOK() { + return mIsOk; + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent evt) { + if (evt.getSource().equals(mOK)) { + //check if selection has been made + //Debug.println("Row Selected = "+mDataModel.getRowCount()); + if(mDataModel.getRowCount()<=0) { + //display error message + CMSAdminUtil.showMessageDialog(mParentFrame, mResource, PREFIX, + "NOSELECTION", CMSAdminUtil.ERROR_MESSAGE); + return; + } + + //get selection + //int i = mTable.getSelectedRowCount(); + //Debug.println("Rows Selected ="+i); + int[] rowIndex = mTable.getSelectedRows(); + //Debug.println("Rows Selected ="+rowIndex.length); + for (int j=0; j< rowIndex.length; j++) + mSelectedGroups.addElement( + mDataModel.getObjectValueAt(rowIndex[j])); + + //set return flag + mIsOk = true; + this.hide(); + } + + if (evt.getSource().equals(mCancel)) { + this.hide(); + } + } + + /*========================================================== + * private methods + *==========================================================*/ + private void setDisplay() { + getContentPane().setLayout(new BorderLayout()); + JPanel center = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + center.setLayout(gb); + + //content panel + JPanel content = makeContentPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gb.setConstraints(content, gbc); + center.add(content); + + //action panel + JPanel action = makeActionPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gb.setConstraints(action, gbc); + center.add(action); + + getContentPane().add("Center",center); + } + + private JPanel makeActionPane() { + mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, this); + mCancel = CMSAdminUtil.makeJButton(mResource, PREFIX, "CANCEL", null, this); + JButton[] buttons = { mOK, mCancel}; + JButtonFactory.resize( buttons ); + return CMSAdminUtil.makeJButtonPanel( buttons ); + } + + private JPanel makeContentPane() { + JPanel content = new JPanel(); + GridBagLayout gb3 = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + content.setLayout(gb3); + //content.setBorder(CMSAdminUtil.makeEtchedBorder()); + + //left side certificate table + mTable = new JTable(mDataModel); + mScrollPane = JTable.createScrollPaneForTable(mTable); + //mScrollPane.setBorder(CMSAdminUtil.makeTitledBorder(mResource,PREFIX,"CERTIFICATE")); + mScrollPane.setHorizontalScrollBarPolicy(mScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mScrollPane.setVerticalScrollBarPolicy(mScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + int width = CMSAdminUtil.getTotalColumnWidth( mTable ); + //Dimension d = new Dimension( width, mTable.getRowHeight()*14); + //mTable.setMinimumSize( d ); + //mTable.setSize( d ); + mTable.setAutoscrolls(true); + mTable.sizeColumnsToFit(true); + mTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + //mTable.getSelectionModel().addListSelectionListener(new StandardListSelectionListener()); + //mTable.addMouseListener(this); + //mTable.setPreferredScrollableViewportSize(d); + setLabelCellRenderer(mTable,0); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weighty = 1.0; + gbc.weightx = 1.0; + gb3.setConstraints(mScrollPane, gbc); + content.add(mScrollPane); + + return content; + } + + //Set the first column's cellrender as label cell + protected void setLabelCellRenderer(JTable table, int index) { + table.getColumnModel().getColumn(index).setCellRenderer(new LabelCellRenderer(new JLabel())); + } + + //================================================= + // RETRIEVE INFO FROM SERVER SIDE + //================================================= + + //retrieve group information from the server + private void refresh() throws EAdminException { + mDataModel.removeAllRows(); + + NameValuePairs response; + try { + response = mConnection.search(DestDef.DEST_GROUP_ADMIN, + ScopeDef.SC_GROUPS, + new NameValuePairs()); + } catch (EAdminException e) { + //display error dialog + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.getMessage(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + + //parse the data + for (String entry : response.keySet()) { + entry = entry.trim(); + //check if not already in current list + if (mCurrentGroups.indexOf(entry)== -1) + mDataModel.processData(entry); + } + + refreshTable(); + } + + //refresh the table content + private void refreshTable() { + mTable.invalidate(); + mTable.validate(); + //mTable.repaint(1); + mScrollPane.invalidate(); + mScrollPane.validate(); + //mScrollPane.repaint(1); + repaint(); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/GroupTab.java b/base/console/src/com/netscape/admin/certsrv/ug/GroupTab.java new file mode 100644 index 000000000..e80cc7047 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/GroupTab.java @@ -0,0 +1,369 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * Group Tab + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class GroupTab extends CMSBaseUGTab { + + /*========================================================== + * variables + *==========================================================*/ + private static final String PANEL_NAME = "GROUPTAB"; + private AdminConnection mConnection; + + protected JScrollPane mScrollPane; + protected JTable mTable; //table + protected GroupDataModel mDataModel; //table model + protected GroupEditor mEditor=null; //keep single copy + + protected JButton mRefresh, mEdit, mAdd, mDelete, mHelp; + private static final String HELPINDEX = "usersgroups-certsrv-groups-help"; + + /*========================================================== + * constructors + *==========================================================*/ + public GroupTab(CMSBaseResourceModel model) { + super(PANEL_NAME, model); + mConnection = model.getServerInfo().getAdmin(); + mDataModel = new GroupDataModel(); + mHelpToken = HELPINDEX; + } + + /*========================================================== + * public methods + *==========================================================*/ + + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent e) { + + if (e.getSource().equals(mRefresh)) { + Debug.println("Refresh Group"); + refresh(); + } + if (e.getSource().equals(mEdit)) { + if(mTable.getSelectedRow()< 0) + return; + + Debug.println("Edit Groups "+mTable.getSelectedRow()); + String groupName = (String) mDataModel.getObjectValueAt(mTable.getSelectedRow()); + + if (mEditor==null){ + mEditor = new GroupEditor(mModel.getFrame(), mConnection); + } + + mEditor.showDialog(groupName, false); + refresh(); + + } + if (e.getSource().equals(mAdd)) { + Debug.println("Show Editor"); + if (mEditor==null) + mEditor = new GroupEditor(mModel.getFrame(), mConnection); + mEditor.showDialog("",true); + refresh(); + } + if (e.getSource().equals(mDelete)) { + if(mTable.getSelectedRow()< 0) + return; + int i = showConfirmDialog("DELETE"); + if (i == JOptionPane.YES_OPTION) { + deleteGroup(); + Debug.println("Group Deleted"); + } + } + if (e.getSource().equals(mHelp)) { + helpCallback(); + } + } + + //==== MOUSELISTENER ====================== + public void mouseClicked(MouseEvent e) { + setButtons(); + + /* + + //NEED TO DISABLE THIS DUE TO BUG THAT WILL RE-DISPLAY + //THE DISLOG WINDOW AFTER CLOSING + + //NEED TO PUT CODE TO DO PROACTIVE VERIFICATION + + Debug.println("GroupTab: mouseClicked() -"+e.toString()); + + //we track the double click action on the table entry - View op + if(mTable.getSelectedRow() >= 0) { + if(e.getClickCount() == 2) { + Debug.println("Edit System group"); + String groupName = (String) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + mEditor = new GroupEditor(mModel.getFrame(), mConnection); + mEditor.showDialog(PrefixDef.PX_SYS+groupName,false); + refresh(); + } + } + + //we track the double click action on the table entry - View op + if(mDefTable.getSelectedRow() >= 0) { + if(e.getClickCount() == 2) { + Debug.println("Edit Admin Define Group"); + String groupName = (String) + mDefDataModel.getObjectValueAt(mDefTable.getSelectedRow()); + mEditor = new GroupEditor(mModel.getFrame(), mConnection); + mEditor.showDialog(PrefixDef.PX_DEF+groupName,false); + refresh(); + } + } + */ + + } + + public void mouseReleased(MouseEvent e) { + setButtons(); + } + + /*========================================================== + * protected methods + *==========================================================*/ + + /** + * Updates the groups + */ + public void refresh() { + //Debug.println("refresh group"); + + mDataModel.removeAllRows(); + + updateGroup(); + setButtons(); + + mTable.invalidate(); + mTable.validate(); + mTable.repaint(1); + mScrollPane.invalidate(); + mScrollPane.validate(); + mScrollPane.repaint(1); + } + + //resize vertical buttons + protected void resizeButtons() { + mEdit = makeJButton("EDIT"); + mAdd = makeJButton("ADD"); + mDelete = makeJButton("DELETE"); + //JButton[] buttons = {mEdit}; + JButton[] buttons = {mAdd, mDelete, mEdit}; + JButtonFactory.resize( buttons ); + } + + /** + * create the bottom action button panel + */ + protected JPanel createUDButtonPanel() { + //edit, add, delete, help buttons required + //actionlister to this object + // JButton[] buttons = { mEdit }; + JButton[] buttons = { mAdd, mDelete, mEdit }; + return CMSAdminUtil.makeJButtonVPanel( buttons ); + } + + /** + * create the bottom action button panel + */ + protected JPanel createActionPanel() { + //edit, add, delete, help buttons required + //actionlister to this object + mRefresh = makeJButton("REFRESH"); + mHelp = makeJButton("HELP"); + // JButton[] buttons = { mRefresh, mHelp }; + JButton[] buttons = { mRefresh }; + return makeJButtonPanel( buttons, true); + } + + /** + * create the center listing panel + */ + protected JPanel createListPanel() { + mListPanel = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + mListPanel.setLayout(gb); + + resizeButtons(); + + //top standard table + //fix the size of the top table - since the content will be fixed + //also fixed the problem of resizing. + mTable = new JTable(mDataModel); + mScrollPane = JTable.createScrollPaneForTable(mTable); + //mScrollPane.setBorder(CMSAdminUtil.makeTitledBorder(mResource,PANEL_NAME,"STANDARD")); + mScrollPane.setHorizontalScrollBarPolicy(mScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mScrollPane.setVerticalScrollBarPolicy(mScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + //int width = CMSAdminUtil.getTotalColumnWidth( mTable ); + //Dimension d = new Dimension( width, mTable.getRowHeight()*8); + //mTable.setMinimumSize( d ); + //mTable.setSize( d ); + mTable.setAutoscrolls(true); + mTable.sizeColumnsToFit(true); + mTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + //mTable.getSelectionModel().addListSelectionListener(new StandardListSelectionListener()); + mTable.addMouseListener(this); + //mTable.setPreferredScrollableViewportSize(d); + mScrollPane.setBackground(Color.white); + setLabelCellRenderer(mTable,0); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.fill = gbc.BOTH; + gbc.gridwidth = 1; + gbc.weightx = 1.0; + gbc.insets = EMPTY_INSETS; + gb.setConstraints(mScrollPane, gbc); + mListPanel.add(mScrollPane); + + JPanel buttonPanel = createUDButtonPanel(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 0.0; + gbc.weighty = 1.0; + gbc.insets = EMPTY_INSETS; + gb.setConstraints(buttonPanel, gbc); + mListPanel.add(buttonPanel); + + refresh(); + + return mListPanel; + } + + //Set the first column's cellrender as label cell + protected void setLabelCellRenderer(JTable table, int index) { + table.getColumnModel().getColumn(index).setCellRenderer(new LabelCellRenderer(new JLabel())); + } + + //============================================= + // SEND REQUESTS TO THE SERVER SIDE + //============================================= + + + /** + * set buttons - proactive verification + */ + private void setButtons() { + + //enable and diable buttons accordingly + if (mTable.getSelectionModel().isSelectionEmpty()) { + mDelete.setEnabled(false); + mEdit.setEnabled(false); + return; + } + + if(mDataModel.getRowCount()< 0) { + mDelete.setEnabled(false); + mEdit.setEnabled(false); + return; + } + + mDelete.setEnabled(true); + mEdit.setEnabled(true); + + } + + private void updateGroup() { + //send request and parse data + + NameValuePairs response; + mModel.progressStart(); + try { + response = mConnection.search(DestDef.DEST_GROUP_ADMIN, + ScopeDef.SC_GROUPS, + new NameValuePairs()); + } catch (EAdminException e) { + //display error dialog + showErrorDialog(e.getMessage()); + mModel.progressStop(); + return; + } + + Debug.println(response.toString()); + + //parse the data + Vector store = new Vector(); + for (String entry : response.keySet()) { + store.addElement(entry.trim()); + } + + String[] vals = new String[store.size()]; + store.copyInto(vals); + + CMSAdminUtil.bubbleSort(vals); + + for (int y=0; y< vals.length ; y++) { + String value = response.get(vals[y]); + mDataModel.processData(vals[y],value); + } + + if (mDataModel.getRowCount() >0) + mTable.setRowSelectionInterval(0,0); + + mModel.progressStop(); + } + + private void deleteGroup() { + //get entry name + String groupName = (String) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + + //send comment to server for the removal of the admin + //defined group - no multiple groups selection - append + //admin prefix + mModel.progressStart(); + try { + mConnection.delete(DestDef.DEST_GROUP_ADMIN, + ScopeDef.SC_GROUPS, + groupName); + } catch (EAdminException e) { + //display error dialog + showErrorDialog(e.getMessage()); + mModel.progressStop(); + return; + } + mModel.progressStop(); + //send comment to server and refetch the content + refresh(); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/MemberDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/MemberDataModel.java new file mode 100644 index 000000000..6b1fbfeec --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/MemberDataModel.java @@ -0,0 +1,140 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import java.util.*; +import javax.swing.*; +import com.netscape.certsrv.common.*; +import com.netscape.admin.certsrv.*; +import com.netscape.management.client.util.*; + +/** + * Group Membership model - represents the group table information + * We will need to store the user and group information in separate + * vector also for comparison purpose. + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class MemberDataModel extends CMSContentTableModel + implements IDataProcessor +{ + + /*========================================================== + * variables + *==========================================================*/ + public static final String MEMBER_NAME = "MEMBER_NAME"; + public static final String MEMBER_TYPE = "MEMBER_TYPE"; + public static final String MEMBER_GROUP = "MEMBER_GROUP"; + public static final String MEMBER_USER = "MEMBER_USER"; + + private static String[] mColumns = {MEMBER}; + + private Vector mUsers = new Vector(); + private Vector mGroups = new Vector(); + + /*========================================================== + * constructors + *==========================================================*/ + public MemberDataModel() { + super(); + init(mColumns); + } + + /*========================================================== + * public methods + *==========================================================*/ + public void processData(Object data) { + Vector v = new Vector(); + + NameValuePairs rec = (NameValuePairs)data; + + Icon icon; + icon = (rec.get(MEMBER_TYPE).equals(MEMBER_GROUP))? + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_USERGROUP): + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_USER); + + String entry = rec.get(MEMBER_NAME); + String name = entry; + if(rec.get(MEMBER_TYPE).equals(MEMBER_GROUP)) { + if (entry.startsWith(PrefixDef.PX_SYS)) + name = entry.substring(PrefixDef.PX_SYS.length()); + else + name = entry.substring(PrefixDef.PX_DEF.length()); + } + v.addElement(new JLabel(name,icon, JLabel.LEFT)); + addRow(v, data); + } + + /** + * clean up the table including the datat objects + */ + public void removeAllRows() { + super.removeAllRows(); + mObjectContainer.removeAllElements(); + mUsers.removeAllElements(); + mGroups.removeAllElements(); + } + + /** + * Remove row at the specified index position + * @param index row index to be removed + */ + public void removeRow(int index) + throws ArrayIndexOutOfBoundsException + { + Debug.println("MemberDataModel: removeRow() - start"); + NameValuePairs data = (NameValuePairs)getObjectValueAt(index); + if (data.get(MEMBER_TYPE).equals(MEMBER_GROUP)) + mGroups.removeElement(data.get(MEMBER_NAME)); + else + mUsers.removeElement(data.get(MEMBER_NAME)); + super.removeRow(index); + Debug.println("MemberDataModel: removeRow() - end"); + } + + /** + * Add data row and data object associated with this row + * @param values row values for the table + * @param obj data object + */ + public void addRow(Vector values, Object obj) { + super.addRow(values); + mObjectContainer.addElement(obj); + NameValuePairs rec = (NameValuePairs)obj; + if (rec.get(MEMBER_TYPE).equals(MEMBER_GROUP)) + mGroups.addElement(rec.get(MEMBER_NAME)); + else + mUsers.addElement(rec.get(MEMBER_NAME)); + } + + /** + * get user vector for comparison + */ + public Vector getUsers() { + return (Vector)mUsers.clone(); + } + + /** + * get group vector for comparison + */ + public Vector getGroups() { + return (Vector)mGroups.clone(); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/UserDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/UserDataModel.java new file mode 100644 index 000000000..c3b74ce35 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/UserDataModel.java @@ -0,0 +1,68 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import java.util.*; +import javax.swing.*; +import com.netscape.certsrv.common.*; +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; + +/** + * User Data model - represents the user table information + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class UserDataModel extends CMSContentTableModel { + + /*========================================================== + * variables + *==========================================================*/ + private static String[] mColumns = {USERID, FULLNAME}; + + /*========================================================== + * constructors + *==========================================================*/ + public UserDataModel() { + super(); + init(mColumns); + } + + /*========================================================== + * public methods + *==========================================================*/ + public void processData(String uid, String name) { + Vector v = new Vector(); + + v.addElement(new JLabel(uid, + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_USER), + JLabel.LEFT)); + v.addElement(name); + + addRow(v,uid); + } + + /** + * get user vector for comparison + */ + public Vector getUsers() { + return (Vector) mObjectContainer.clone(); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/UserEditor.java b/base/console/src/com/netscape/admin/certsrv/ug/UserEditor.java new file mode 100644 index 000000000..75908fe6a --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/UserEditor.java @@ -0,0 +1,627 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * User Information Editor - UI provides the user information + * management functionality. The management of user certificate + * is done by certificate management dialog + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * + * @see com.netscape.admin.certsrv.ug.UserTab + */ +public class UserEditor extends JDialog + implements ActionListener, MouseListener, DocumentListener +{ + + /*========================================================== + * variables + *==========================================================*/ + private String PREFIX = "USEREDITOR"; + + private JFrame mParentFrame; + private AdminConnection mConnection; + private String mUserName; + private boolean mIsNewUser = false; + private ResourceBundle mResource; + private Color mActiveColor; + protected DefaultListModel mDataModel; + + protected JScrollPane mScrollPane; + protected JList mList; + + private boolean mUserAdded; + private JButton mOK, mCancel, mHelp; + private JLabel mPasswordLbl, mPasswordConfirmLbl; + private JTextField mUserNameField, mFullNameField, mEMailField, mPhoneField, mStateField; + private JPasswordField mPasswordField; + private JPasswordField mPasswordConfirm; + private JLabel mUserLabel, mMembership, mGroupLbl, dummy1; + private JComboBox mGroupBox; + private static final String ADDHELPINDEX = + "usersgroups-certsrv-add-user-dbox-help"; + private static final String EDITHELPINDEX = + "usersgroups-certsrv-edit-user-dbox-help"; + + /*========================================================== + * constructors + *==========================================================*/ + public UserEditor( JFrame parent, + AdminConnection conn, boolean isNew) { + super(parent,true); + mParentFrame = parent; + mConnection = conn; + mDataModel = new DefaultListModel(); + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + setTitle(mResource.getString(PREFIX+"_TITLE")); + mIsNewUser = isNew; + if(!mIsNewUser) + setSize(360, 370); + else + setSize(360, 350); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + setDisplay(); + + if(!mIsNewUser) { + mUserNameField.setVisible(false); + mUserLabel.setVisible(true); + mMembership.setVisible(true); + mScrollPane.setVisible(true); + mGroupLbl.setVisible(false); + mGroupBox.setVisible(false); + dummy1.setVisible(false); + } else { + mUserNameField.setVisible(true); + mUserNameField.setText(""); + mUserLabel.setVisible(false); + mUserLabel.setText(""); + mMembership.setVisible(false); + mScrollPane.setVisible(false); + mGroupLbl.setVisible(true); + mGroupBox.setVisible(true); + dummy1.setVisible(true); + } + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + * @param user user name + * @param isNew true if this is a new entry + */ + public void showDialog(String user) { + + //initialize and setup + mUserName = user; + mFullNameField.setText(""); + mEMailField.setText(""); + mPhoneField.setText(""); + mStateField.setText(""); + mPasswordField.setText(""); + mPasswordConfirm.setText(""); + + mDataModel.clear(); + //mViewCert.setEnabled(false); + + if(!mIsNewUser) { + mUserLabel.setText(user); + } else { + mUserNameField.setText(""); + mUserLabel.setText(""); + mStateField.setText("1"); + } + + //retrieve the cert record from the server + try { + if (mIsNewUser == false) + refresh(); + else { + addGroup(); + } + } catch (EAdminException ex) { + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + ex.toString(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + updateView(); + this.show(); + } + + private void enablePasswordFields(boolean enable, Color color) { + mPasswordField.setVisible(enable); + mPasswordLbl.setVisible(enable); + mPasswordConfirm.setVisible(enable); + mPasswordConfirmLbl.setVisible(enable); + CMSAdminUtil.repaintComp(mPasswordField); + CMSAdminUtil.repaintComp(mPasswordConfirm); + CMSAdminUtil.repaintComp(mPasswordLbl); + CMSAdminUtil.repaintComp(mPasswordConfirmLbl); + } + + public boolean isUserAdded() { + return mUserAdded; + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + + public void actionPerformed(ActionEvent evt) { + + mUserAdded = false; + if (evt.getSource().equals(mOK)) { + + //check password field + String pwd = mPasswordField.getText().trim(); + if (!pwd.equals("")) { + if (!mPasswordConfirm.getText().trim().equals(pwd)) { + CMSAdminUtil.showMessageDialog(mParentFrame, mResource, PREFIX, + "PWDNOTMATCH", CMSAdminUtil.ERROR_MESSAGE); + return; + } + } + + if (mIsNewUser) { + + //check text fields + if (mUserNameField.getText().trim().equals("")) { + CMSAdminUtil.showMessageDialog(mParentFrame, mResource, PREFIX, + "NOUSERNAME", CMSAdminUtil.ERROR_MESSAGE); + return; + } + + try { + addUser(); + mUserAdded = true; + } catch (EAdminException e) { + //display error dialog + Debug.println(e.toString()); + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.toString(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + + } else { + + try { + modifyUser(); + } catch (EAdminException e) { + //display error dialog + Debug.println(e.toString()); + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.toString(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + + } + this.hide(); + } + + if (evt.getSource().equals(mCancel)) { + Debug.println("Cancel Pressed"); + + //display are you sure dialog + this.hide(); + } + + if (evt.getSource().equals(mHelp)) { + if (mIsNewUser) + CMSAdminUtil.help(ADDHELPINDEX); + else + CMSAdminUtil.help(EDITHELPINDEX); + } + + /* + * possible enhancement here to put in + * a WIZARD that will take 1) B64E ,2) + * ldap dir, 3) cert server for retrieval + * we will do B64E first + * + if (evt.getSource().equals(mAddCert)) { + //display dialog to add B64E + if (mCertDialog==null) + mCertDialog = new CertImportDialog(mParentFrame); + mCertDialog.showDialog(); + if (!mCertDialog.isOK()) + return; + + //add entry + Debug.println("Name="+mCertDialog.getCertName()); + Debug.println("B64E= "+mCertDialog.getB64E()); + NameValuePairs data = new NameValuePairs(); + data.add(CERT_NAME,mCertDialog.getCertName()); + data.add(CERT_DATA,mCertDialog.getB64E()); + data.add(CERT_VIEW,CERT_B64E); + mDataModel.processData(data); + refreshTable(); + } + + if (evt.getSource().equals(mViewCert)) { + //display certificate pp + NameValuePairs obj = (NameValuePairs)mDataModel.getObjectValueAt + (mTable.getSelectedRow()); + if (mViewDialog==null) + mViewDialog = new CertViewDialog(mParentFrame); + mViewDialog.showDialog(obj.getValue(CERT_NAME),obj.getValue(CERT_DATA)); + } + + if (evt.getSource().equals(mDeleteCert)) { + if(mTable.getSelectedRow()< 0) + return; + int i = CMSAdminUtil.showConfirmDialog(mParentFrame, mResource, + PREFIX, "DELETE", CMSAdminUtil.WARNING_MESSAGE); + if (i == JOptionPane.YES_OPTION) { + deleteCert(); + Debug.println("Cert Deleted"); + } + } + */ + } + + //==== MOUSELISTENER ====================== + public void mouseClicked(MouseEvent e) { + //check if stuff is selected + updateView(); + } + + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) { + updateView(); + } + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + + + //== DocumentListener == + public void insertUpdate(DocumentEvent e) { + updateView(); + } + + public void removeUpdate(DocumentEvent e){ + updateView(); + } + + public void changedUpdate(DocumentEvent e){ + updateView(); + } + + /*========================================================== + * private methods + *==========================================================*/ + + /** + * proactive verification + */ + private void updateView() { + if (mIsNewUser) { + if (mUserNameField.getText().trim().equals("")) { + mOK.setEnabled(false); + return; + } + } + if (mFullNameField.getText().trim().equals("")) { + mOK.setEnabled(false); + return; + } + /* ONLY UID is verify now + if (mPasswordField.getText().trim().equals("")) { + mOK.setEnabled(false); + return; + } + */ + mOK.setEnabled(true); + } + + /** + * Construction of the initial UI components + */ + private void setDisplay() { + getContentPane().setLayout(new BorderLayout()); + JPanel center = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + center.setLayout(gb); + + //content panel + JPanel content = makeContentPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbc.fill = gbc.BOTH; + gb.setConstraints(content, gbc); + center.add(content); + + //action panel + JPanel action = makeActionPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gb.setConstraints(action, gbc); + center.add(action); + + getContentPane().add("Center",center); + + } + + private JPanel makeActionPane() { + mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, this); + mCancel = CMSAdminUtil.makeJButton(mResource, PREFIX, "CANCEL", null, this); + mHelp = CMSAdminUtil.makeJButton(mResource, PREFIX, "HELP", null, this); + //JButton[] buttons = { mOK, mCancel, mHelp }; + JButton[] buttons = { mOK, mCancel }; + return CMSAdminUtil.makeJButtonPanel( buttons, true); + } + + private JPanel makeContentPane() { + + Insets insets = new Insets(CMSAdminUtil.COMPONENT_SPACE,0, + CMSAdminUtil.COMPONENT_SPACE,0); + + //top panel + JPanel top = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + CMSAdminUtil.resetGBC(gbc); + top.setLayout(gb); + + JLabel label1 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "USERNAME", null); + mUserNameField = new JTextField(); + mUserNameField.addMouseListener(this); + mUserNameField.getDocument().addDocumentListener(this); + mUserLabel = new JLabel(); + mUserLabel.setVisible(false); + gbc.fill = gbc.NONE; + gbc.weightx = 0.0; + gbc.anchor = gbc.EAST; + gbc. insets = new Insets(CMSAdminUtil.COMPONENT_SPACE, + CMSAdminUtil.COMPONENT_SPACE,0,0); + top.add(label1, gbc); + + gbc.anchor = gbc.WEST; + gbc.fill = gbc.HORIZONTAL; + gbc.weightx = 1.0; + gbc. insets = new Insets(CMSAdminUtil.COMPONENT_SPACE, + CMSAdminUtil.COMPONENT_SPACE, + 0,CMSAdminUtil.COMPONENT_SPACE); + top.add( mUserLabel, gbc ); + top.add( mUserNameField, gbc ); + + JLabel dummy = new JLabel(); + dummy.setVisible(false); + gbc.gridwidth = gbc.REMAINDER; + gbc.weightx = 0.0; + top.add( dummy, gbc); + + JLabel label2 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "FULLNAME", null); + mFullNameField = new JTextField(); + mFullNameField.addMouseListener(this); + mFullNameField.getDocument().addDocumentListener(this); + CMSAdminUtil.addEntryField(top, label2, mFullNameField, gbc); + + mPasswordLbl = CMSAdminUtil.makeJLabel(mResource, PREFIX, "PASSWORD", null); + mPasswordField = new JPasswordField(); + mPasswordField.addMouseListener(this); + mPasswordField.getDocument().addDocumentListener(this); + mActiveColor = mPasswordField.getBackground(); + CMSAdminUtil.addEntryField(top, mPasswordLbl, mPasswordField, gbc); + + mPasswordConfirmLbl = CMSAdminUtil.makeJLabel(mResource, PREFIX, "PASSWORDCONFIRM", null); + mPasswordConfirm = new JPasswordField(); + mPasswordConfirm.addMouseListener(this); + mPasswordConfirm.getDocument().addDocumentListener(this); + CMSAdminUtil.addEntryField(top, mPasswordConfirmLbl, mPasswordConfirm, gbc); + + JLabel label4 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "EMAIL", null); + mEMailField = new JTextField(); + CMSAdminUtil.addEntryField(top, label4, mEMailField, gbc); + + CMSAdminUtil.resetGBC(gbc); + //gbc.gridheight = gbc.REMAINDER; + JLabel label5 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "PHONE", null); + mPhoneField = new JTextField(); + CMSAdminUtil.addEntryField(top, label5, mPhoneField, gbc); + + CMSAdminUtil.resetGBC(gbc); + //gbc.gridheight = gbc.REMAINDER; + JLabel label51 = CMSAdminUtil.makeJLabel(mResource, PREFIX, "STATE", null); + mStateField = new JTextField(); + CMSAdminUtil.addEntryField(top, label51, mStateField, gbc); + + CMSAdminUtil.resetGBC(gbc); + mGroupLbl = CMSAdminUtil.makeJLabel(mResource, PREFIX, "GROUP",null); + mGroupBox = new JComboBox(); + //mGroupBox.addItem("Admin group"); + dummy1 = new JLabel(" "); + CMSAdminUtil.addEntryField(top, mGroupLbl, mGroupBox, dummy1, gbc); + + mMembership = CMSAdminUtil.makeJLabel(mResource, PREFIX, "MEMBER", null); + //group membership table + mList = CMSAdminUtil.makeJList(mDataModel,6); + mScrollPane = new JScrollPane(mList, + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION ); + mList.addMouseListener(this); + mScrollPane.setBackground(Color.white); + + mScrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); + //setLabelCellRenderer(mTable,0); + + CMSAdminUtil.resetGBC(gbc); + gbc.fill = gbc.NONE; + gbc.weightx = 0.0; + gbc.gridwidth = 1; + gbc.gridx = 0; + gbc.anchor = gbc.NORTHEAST; + gbc.gridheight = gbc.REMAINDER; + gbc.insets = new Insets(CMSAdminUtil.COMPONENT_SPACE, + CMSAdminUtil.COMPONENT_SPACE,0,0); + top.add( mMembership, gbc ); + + gbc.gridx++; + gbc.anchor = gbc.NORTHWEST; + gbc.fill = gbc.BOTH; + gbc.weightx = 0.5; + gbc.weighty=1.0; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.insets = new Insets(CMSAdminUtil.COMPONENT_SPACE, + CMSAdminUtil.COMPONENT_SPACE,0,CMSAdminUtil.COMPONENT_SPACE); + top.add( mScrollPane, gbc ); + + return top; + } + + //================================================= + // RETRIEVE INFO FROM SERVER SIDE + //================================================= + + //retrieve group information from the server + private void refresh() throws EAdminException { + + //construct NVP + NameValuePairs config = new NameValuePairs(); + config.put(Constants.PR_USER_FULLNAME, ""); + config.put(Constants.PR_USER_EMAIL, ""); + config.put(Constants.PR_USER_PHONE, ""); + config.put(Constants.PR_USER_STATE, ""); + config.put(Constants.PR_USER_GROUP, ""); + + NameValuePairs response; + response = mConnection.read(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USERS, + mUserName, + config); + + //setup the ui + mUserNameField.setText(mUserName); + mFullNameField.setText(response.get(Constants.PR_USER_FULLNAME)); + mEMailField.setText(response.get(Constants.PR_USER_EMAIL)); + mPhoneField.setText(response.get(Constants.PR_USER_PHONE)); + mStateField.setText(response.get(Constants.PR_USER_STATE)); + + //parse group entry + String userStr = response.get(Constants.PR_USER_GROUP); + if ( (userStr != null) && (!userStr.trim().equals("")) ) { + StringTokenizer tokenizer = new StringTokenizer(userStr, ","); + while (tokenizer.hasMoreTokens()) { + String groupstr = tokenizer.nextToken().trim(); + mDataModel.addElement(groupstr); + } + } + + } + + private void addGroup() throws EAdminException { + NameValuePairs response = mConnection.search(DestDef.DEST_GROUP_ADMIN, + ScopeDef.SC_GROUPS, new NameValuePairs()); + if (mGroupBox.getItemCount() > 0) + mGroupBox.removeAllItems(); + for (String groupname : response.keySet()) { + mGroupBox.addItem(groupname.trim()); + } + + } + + //add new group information + private void addUser() throws EAdminException { + + //construct NVP + NameValuePairs config = new NameValuePairs(); + config.put(Constants.PR_USER_FULLNAME, mFullNameField.getText().trim()); + config.put(Constants.PR_USER_PASSWORD, mPasswordField.getText().trim()); + config.put(Constants.PR_USER_EMAIL, mEMailField.getText().trim()); + config.put(Constants.PR_USER_PHONE, mPhoneField.getText().trim()); + config.put(Constants.PR_USER_STATE, mStateField.getText().trim()); + config.put(Constants.PR_USER_GROUP, (String) mGroupBox.getSelectedItem()); + config.put(Constants.PR_USER_TYPE, ""); + //config.add(Constants.PR_USER_CERT,""); + //createCertEntry(config); + + //send request + mConnection.add(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USERS, + mUserNameField.getText().trim(), + config); + } + + //change new group information + private void modifyUser() throws EAdminException { + + //construct NVP + NameValuePairs config = new NameValuePairs(); + config.put(Constants.PR_USER_FULLNAME, mFullNameField.getText().trim()); + config.put(Constants.PR_USER_PASSWORD, mPasswordField.getText().trim()); + config.put(Constants.PR_USER_EMAIL, mEMailField.getText().trim()); + config.put(Constants.PR_USER_PHONE, mPhoneField.getText().trim()); + config.put(Constants.PR_USER_STATE, mStateField.getText().trim()); + config.put(Constants.PR_USER_TYPE, ""); + //createCertEntry(config); + + //send request + mConnection.modify(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USERS, + mUserName, + config); + + // #343872 + // see if it is password change of the currently logged-in + // user. If it is the case, we need to update Console password + // cache + String pwd = mPasswordField.getText().trim(); + if (!pwd.equals("")) { + BasicAuthenticator auth = (BasicAuthenticator) + mConnection.getAuthenticator(); + if (mUserName.equals(auth.getUserid()) && + !pwd.equals(auth.getPassword())) { + auth.setPassword(pwd); + } + } + } + + //refresh the table content + private void refreshTable() { + mScrollPane.repaint(1); + } + + +} + diff --git a/base/console/src/com/netscape/admin/certsrv/ug/UserListDataModel.java b/base/console/src/com/netscape/admin/certsrv/ug/UserListDataModel.java new file mode 100644 index 000000000..e66c14d94 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/UserListDataModel.java @@ -0,0 +1,70 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import java.util.*; +import javax.swing.*; +import com.netscape.certsrv.common.*; +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; + +/** + * User List Data model - represents the single column user + * table information + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + */ +public class UserListDataModel extends CMSContentTableModel + implements IDataProcessor +{ + + /*========================================================== + * variables + *==========================================================*/ + private static String[] mColumns = {USERID}; + + /*========================================================== + * constructors + *==========================================================*/ + public UserListDataModel() { + super(); + init(mColumns); + } + + /*========================================================== + * public methods + *==========================================================*/ + public void processData(Object data) { + Vector v = new Vector(); + + //XXX NEED TO CHANGE if we are going to have multi-column table + v.addElement(new JLabel((String)data, + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_USER), + JLabel.LEFT)); + addRow(v, data); + } + + /** + * get user vector for comparison + */ + public Vector getUsers() { + return (Vector) mObjectContainer.clone(); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/UserListDialog.java b/base/console/src/com/netscape/admin/certsrv/ug/UserListDialog.java new file mode 100644 index 000000000..6f0c6215b --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/UserListDialog.java @@ -0,0 +1,369 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * User Listing Dialog -

+ * + * This dialog support multiple user selection and displays + * only users that are not in the current group. This dialog + * will be created once and being reused per group editor. + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * @see com.netscape.admin.certsrv.ug + */ +public class UserListDialog extends JDialog + implements ActionListener, MouseListener +{ + /*========================================================== + * variables + *==========================================================*/ + private String PREFIX = "USERLISTDIALOG"; + + private JFrame mParentFrame; + private AdminConnection mConnection; + private ResourceBundle mResource; + protected DefaultListModel mDataModel; + protected Vector mCurrentUsers; + protected Vector mSelectedUser; + + private JScrollPane mScrollPane; + private JList mList; + + private JButton mOK, mCancel; + private boolean mIsOk = false; + + /*========================================================== + * constructors + *==========================================================*/ + public UserListDialog(JFrame parent, AdminConnection conn) { + super(parent,true); + mParentFrame = parent; + mConnection = conn; + mSelectedUser = new Vector(); + mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); + mDataModel = new DefaultListModel(); + setSize(360, 216); + setTitle(mResource.getString(PREFIX+"_TITLE")); + setLocationRelativeTo(parent); + getRootPane().setDoubleBuffered(true); + setDisplay(); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * show the windows + * @param users list of current users + */ + public void showDialog(Vector users) { + + mCurrentUsers = users; + mSelectedUser.removeAllElements(); + + //retrieve the cert record from the server + try { + refresh(); + } catch (EAdminException ex) { + CMSAdminUtil.showMessageDialog(mParentFrame, mResource, PREFIX, + "SERVERERROR", CMSAdminUtil.ERROR_MESSAGE); + return; + } + setButtons(); + mIsOk = false; + this.show(); + } + + + /** + * if selection is ok, the user name will be returned + * otherwise, empty string will be returned. + * @return user name + */ + public Vector getSelectedUser() { + return mSelectedUser; + } + + /** + * get the exit code + * @return true if ok; otherwise false + */ + public boolean isOK() { + return mIsOk; + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent evt) { + if (evt.getSource().equals(mOK)) { + //get selected user + int[] rowIndex = mList.getSelectedIndices(); + //Debug.println("Rows Selected ="+rowIndex.length); + for (int j=0; j< rowIndex.length; j++) + mSelectedUser.addElement( + ((JLabel)mDataModel.elementAt(rowIndex[j])).getText()); + + //set return flag + mIsOk = true; + this.hide(); + } + + if (evt.getSource().equals(mCancel)) { + this.hide(); + } + } + + //==== MOUSELISTENER ====================== + public void mouseClicked(MouseEvent e) { + setButtons(); + } + + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + + public void mouseEntered(MouseEvent e) { + setButtons(); + } + public void mouseExited(MouseEvent e) { + setButtons(); + } + + /*========================================================== + * private methods + *==========================================================*/ + + //set buttons + private void setButtons() { + if (mList.getSelectedIndex()< 0) { + mOK.setEnabled(false); + return; + } + mOK.setEnabled(true); + } + + private void setDisplay() { + getContentPane().setLayout(new BorderLayout()); + JPanel center = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + center.setLayout(gb); + + //content panel + JPanel content = makeContentPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.fill = gbc.BOTH; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gb.setConstraints(content, gbc); + center.add(content); + + //action panel + JPanel action = makeActionPane(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gb.setConstraints(action, gbc); + center.add(action); + + getContentPane().add("Center",center); + } + + private JPanel makeActionPane() { + mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, this); + mCancel = CMSAdminUtil.makeJButton(mResource, PREFIX, "CANCEL", null, this); + JButton[] buttons = { mOK, mCancel}; + JButtonFactory.resize( buttons ); + return CMSAdminUtil.makeJButtonPanel( buttons ); + } + + private JPanel makeContentPane() { + JPanel mListPanel = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + mListPanel.setLayout(gb); + + mList = CMSAdminUtil.makeJList(mDataModel,9); + mScrollPane = new JScrollPane(mList, + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + mList.addMouseListener(this); + mScrollPane.setBackground(Color.white); + mScrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbc.fill = gbc.BOTH; + gb.setConstraints(mScrollPane, gbc); + mListPanel.add(mScrollPane); + + return mListPanel; + + /* + JPanel content = new JPanel(); + GridBagLayout gb3 = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + content.setLayout(gb3); + //content.setBorder(CMSAdminUtil.makeEtchedBorder()); + + //left side certificate table + mTable = new JTable(mDataModel); + mScrollPane = JTable.createScrollPaneForTable(mTable); + //mScrollPane.setBorder(CMSAdminUtil.makeTitledBorder(mResource,PREFIX,"CERTIFICATE")); + mScrollPane.setHorizontalScrollBarPolicy(mScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mScrollPane.setVerticalScrollBarPolicy(mScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + int width = CMSAdminUtil.getTotalColumnWidth( mTable ); + //Dimension d = new Dimension( width, mTable.getRowHeight()*14); + //mTable.setMinimumSize( d ); + //mTable.setSize( d ); + mTable.setAutoscrolls(true); + mTable.sizeColumnsToFit(true); + mTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + //mTable.getSelectionModel().addListSelectionListener(new StandardListSelectionListener()); + //mTable.addMouseListener(this); + //mTable.setPreferredScrollableViewportSize(d); + setLabelCellRenderer(mTable,0); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weighty = 1.0; + gbc.weightx = 1.0; + gb3.setConstraints(mScrollPane, gbc); + content.add(mScrollPane); + + return content; + */ + } + + /*Set the first column's cellrender as label cell + protected void setLabelCellRenderer(JTable table, int index) { + table.getColumnModel().getColumn(index).setCellRenderer(new LabelCellRenderer(new JLabel())); + } + */ + + //================================================= + // RETRIEVE INFO FROM SERVER SIDE + //================================================= + + //retrieve group information from the server + private void refresh() throws EAdminException { + mDataModel.removeAllElements(); + + NameValuePairs response; + try { + response = mConnection.search(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USERS, + new NameValuePairs()); + } catch (EAdminException e) { + //display error dialog + CMSAdminUtil.showErrorDialog(mParentFrame, mResource, + e.getMessage(), CMSAdminUtil.ERROR_MESSAGE); + return; + } + + //parse the data +/* + Vector store = new Vector(); + for (Enumeration e = response.getNames(); e.hasMoreElements() ;) { + String entry = ((String)e.nextElement()).trim(); + if (mCurrentUsers.indexOf(entry)== -1) + store.addElement(entry); + } + + String[] vals = new String[store.size()]; + store.copyInto(vals); +*/ + + String responseValue = response.get("userInfo"); + + StringTokenizer tokenizer = new StringTokenizer(responseValue, ";"); + StringTokenizer subTokenizer = null; + + Vector store = new Vector(); + Hashtable table = new Hashtable(); + + while (tokenizer.hasMoreTokens()) { + String t = (String)tokenizer.nextToken(); + subTokenizer = new StringTokenizer(t, ":"); + int i=0; + String str1 = null; + String str2 = null; + while (subTokenizer.hasMoreTokens()) { + if (i == 0) { + str1 = (String)subTokenizer.nextToken(); + store.addElement(str1); + } else { + str2 = (String)subTokenizer.nextToken(); + table.put(str1, str2); + } + i++; + } + } + + String[] vals = new String[store.size()]; + store.copyInto(vals); + + CMSAdminUtil.bubbleSort(vals); + + for (int y=0; y< vals.length ; y++) { + mDataModel.addElement(new JLabel(vals[y], + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_USER), + JLabel.LEFT)); + } + + refreshTable(); + } + + //refresh the table content + private void refreshTable() { + //mTable.invalidate(); + //mTable.validate(); + //mTable.repaint(1); + //mScrollPane.invalidate(); + //mScrollPane.validate(); + //mScrollPane.repaint(1); + //repaint(); + } + +} diff --git a/base/console/src/com/netscape/admin/certsrv/ug/UserTab.java b/base/console/src/com/netscape/admin/certsrv/ug/UserTab.java new file mode 100644 index 000000000..78b7e5252 --- /dev/null +++ b/base/console/src/com/netscape/admin/certsrv/ug/UserTab.java @@ -0,0 +1,374 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.admin.certsrv.ug; + +import com.netscape.admin.certsrv.*; +import com.netscape.admin.certsrv.connection.*; +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import java.util.*; + +import com.netscape.management.client.util.*; +import com.netscape.certsrv.common.*; + +/** + * User Tab - this UI component provides the user + * management functionality of the certificate server. + * + * @author Jack Pan-Chen + * @version $Revision$, $Date$ + * + * @see com.netscape.admin.certsrv.ug.CertImportDialog + * @see com.netscape.admin.certsrv.ug.CertManagementDialog + * @see com.netscape.admin.certsrv.ug.CertViewDialog + * @see com.netscape.admin.certsrv.ug.UserEditor + */ +public class UserTab extends CMSBaseUGTab { + + /*========================================================== + * variables + *==========================================================*/ + private static final String PANEL_NAME = "USERTAB"; + private AdminConnection mConnection; + + protected JScrollPane mScrollPane; + protected JTable mTable; //table + protected UserDataModel mDataModel; //table model + protected UserEditor mEditor=null; //keep single copy + protected UserEditor mAddEditor=null; //keep single copy + protected CertManagementDialog mCertEditor=null; //single copy + protected JButton mRefresh, mEdit, mAdd, mDelete, mHelp, mCert; + private final static String HELPINDEX = "usersgroups-certsrv-users-help"; + + /*========================================================== + * constructors + *==========================================================*/ + public UserTab(CMSBaseResourceModel model) { + super(PANEL_NAME, model); + mConnection = model.getServerInfo().getAdmin(); + mDataModel = new UserDataModel(); + mHelpToken = HELPINDEX; + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * refresh the content of the tab + * IRefreshTab menthod + */ + public void refresh() { + //Debug.println("refresh() user tab"); + + mDataModel.removeAllRows(); + updateUser(); + setButtons(); + mTable.invalidate(); + mTable.validate(); + mScrollPane.invalidate(); + mScrollPane.validate(); + mScrollPane.repaint(1); + } + + /*========================================================== + * EVNET HANDLER METHODS + *==========================================================*/ + + //=== ACTIONLISTENER ===================== + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(mRefresh)) { + Debug.println("Refresh User"); + refresh(); + } else if (e.getSource().equals(mEdit)) { + if(mTable.getSelectedRow()< 0) + return; + + Debug.println("Edit User"); + String userName = (String) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + + mAddEditor = new UserEditor(mModel.getFrame(), mConnection, + false); + mAddEditor.showDialog(userName); + mAddEditor.dispose(); + refresh(); + } else if (e.getSource().equals(mAdd)) { + mAddEditor = new UserEditor(mModel.getFrame(), mConnection, true); + mAddEditor.showDialog(""); + if (mAddEditor.isUserAdded()) + refresh(); + mAddEditor.dispose(); + } else if (e.getSource().equals(mDelete)) { + Debug.println("Delete User"); + if(mTable.getSelectedRow()< 0) + return; + int i = showConfirmDialog("DELETE"); + if (i == JOptionPane.YES_OPTION) { + deleteUser(); + Debug.println("User Deleted"); + } + } else if (e.getSource().equals(mHelp)) { + helpCallback(); + } else if (e.getSource().equals(mCert)) { + String userName = (String) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + if (mCertEditor==null) + mCertEditor = new CertManagementDialog(mModel.getFrame(), mConnection); + mCertEditor.showDialog(userName); + Debug.println("Cert"); + //refresh(); + //XXX HELP + } + } + + //==== MOUSELISTENER ====================== + public void mouseClicked(MouseEvent e) { + //Debug.println("CertRepositoryPanel: mouseClicked() -"+e.toString()); + setButtons(); + + //we track the double click action on the table entry - View op + if(mTable.getSelectedRow() >= 0) { + if(e.getClickCount() == 2) { + Debug.println("Edit User"); + //editUser(); + } + } + } + + public void mouseReleased(MouseEvent e) { + setButtons(); + } + + /*========================================================== + * protected methods + *==========================================================*/ + + /** + * create the user action button panel + */ + protected JPanel createUserButtonPanel() { + //edit, add, delete, help buttons required + //actionlister to this object + mEdit = makeJButton("EDIT"); + mAdd = makeJButton("ADD"); + mDelete = makeJButton("DELETE"); + mCert = makeJButton("CERT"); + JButton[] buttons = {mAdd, mDelete, mEdit, mCert}; + JButtonFactory.resize( buttons ); + return CMSAdminUtil.makeJButtonVPanel( buttons ); + } + + protected JPanel createActionPanel() { + //edit, add, delete, help buttons required + //actionlister to this object + mRefresh = makeJButton("REFRESH"); + mHelp = makeJButton("HELP"); + //JButton[] buttons = { mRefresh, mHelp }; + JButton[] buttons = { mRefresh }; + return makeJButtonPanel( buttons, true); + } + + protected JPanel createListPanel() { + mListPanel = new JPanel(); + GridBagLayout gb = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + mListPanel.setLayout(gb); + + //center table + mTable = new JTable(mDataModel); + mScrollPane = JTable.createScrollPaneForTable(mTable); + //mScrollPane.setBorder(CMSAdminUtil.makeTitledBorder(mResource,PANEL_NAME,"USERS")); + mScrollPane.setHorizontalScrollBarPolicy(mScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + mScrollPane.setVerticalScrollBarPolicy(mScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + mTable.setAutoscrolls(true); + mTable.sizeColumnsToFit(true); + mTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + mTable.getSelectionModel().addListSelectionListener(this); + mTable.addMouseListener(this); + mScrollPane.setBackground(Color.white); + setLabelCellRenderer(mTable,0); + + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.fill = gbc.BOTH; + gbc.gridwidth = 1; + gbc.weightx = 1.0; + gbc.insets = EMPTY_INSETS; + gb.setConstraints(mScrollPane, gbc); + mListPanel.add(mScrollPane); + + JPanel buttonPanel = createUserButtonPanel(); + CMSAdminUtil.resetGBC(gbc); + gbc.anchor = gbc.NORTH; + gbc.gridwidth = gbc.REMAINDER; + gbc.gridheight = gbc.REMAINDER; + gbc.weightx = 0.0; + gbc.weighty = 1.0; + gbc.insets = EMPTY_INSETS; + gb.setConstraints(buttonPanel, gbc); + mListPanel.add(buttonPanel); + + refresh(); + + return mListPanel; + } + + //Set the first column's cellrender as label cell + protected void setLabelCellRenderer(JTable table, int index) { + table.getColumnModel().getColumn(index).setCellRenderer(new LabelCellRenderer(new JLabel())); + } + + /*========================================================== + * private methods + *==========================================================*/ + + /** + * set buttons - proactive verification + */ + private void setButtons() { + + //enable and diable buttons accordingly + if (mTable.getSelectionModel().isSelectionEmpty()) { + mDelete.setEnabled(false); + mEdit.setEnabled(false); + mCert.setEnabled(false); + return; + } + + if(mDataModel.getRowCount()< 0) { + mDelete.setEnabled(false); + mEdit.setEnabled(false); + mCert.setEnabled(false); + return; + } + + mDelete.setEnabled(true); + mEdit.setEnabled(true); + mCert.setEnabled(true); + + } + + //============================================= + // SEND REQUESTS TO THE SERVER SIDE + //============================================= + + private void updateUser() { + //send request and parse data + + NameValuePairs response; + mModel.progressStart(); + + try { + response = mConnection.search(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USERS, + new NameValuePairs()); + } catch (EAdminException e) { + //display error dialog + showErrorDialog(e.getMessage()); + mModel.progressStop(); + return; + } + + Debug.println(response.toString()); + + String responseValue = response.get("userInfo"); + + StringTokenizer tokenizer = new StringTokenizer(responseValue, ";"); + StringTokenizer subTokenizer = null; + + Vector store = new Vector(); + Hashtable table = new Hashtable(); + + while (tokenizer.hasMoreTokens()) { + String t = (String)tokenizer.nextToken(); + subTokenizer = new StringTokenizer(t, ":"); + int i=0; + String str1 = null; + String str2 = null; + while (subTokenizer.hasMoreTokens()) { + if (i == 0) { + str1 = (String)subTokenizer.nextToken(); + store.addElement(str1); + } else { + str2 = (String)subTokenizer.nextToken(); + table.put(str1, str2); + } + i++; + } + } + + String[] names = new String[store.size()]; + store.copyInto(names); + + if (names.length > 1) { + names = CMSAdminUtil.randomize(names); + CMSAdminUtil.quickSort(names, 0, names.length-1); + } + + for (int y=0; y< names.length ; y++) { + String s = (String)table.get(names[y]); + mDataModel.processData(names[y], s); + } + + if (mDataModel.getRowCount() >0) + mTable.setRowSelectionInterval(0,0); + + mModel.progressStop(); + } + + private void deleteUser() { + //get entry name + String userName = (String) + mDataModel.getObjectValueAt(mTable.getSelectedRow()); + + mModel.progressStart(); + //send comment to server for the removal of user + try { + mConnection.delete(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USERS, + userName); + } catch (EAdminException e) { + String str = e.toString(); + + if (str.indexOf("The user") == 0) { + int i = + JOptionPane.showConfirmDialog(new JFrame(), str, + "Information", JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE, + CMSAdminUtil.getImage(CMSAdminResources.IMAGE_INFO_ICON)); + if (i == JOptionPane.YES_OPTION) { + Debug.println("User Deleted"); + try { + mConnection.delete(DestDef.DEST_USER_ADMIN, + ScopeDef.SC_USERS, + userName+":true"); + } catch (EAdminException ee) { + showErrorDialog(ee.getMessage()); + } + } + } + } + + mModel.progressStop(); + //send comment to server and refetch the content + refresh(); + } + +} -- cgit