📄 cbopenconwin.java
字号:
package com.ca.commons.naming;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URISyntaxException;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import com.ca.commons.jndi.ConnectionData;
import com.ca.commons.cbutil.*;
/**
* CBOpenConWin displays connection info to the user, allowing them
* to open a connection to an ldap server.
*/
// Programming note: this class is a bit of an interloper; but it requires classes from both com.ca.commons.cbutil and
// com.ca.commons.jndi, so it get stuck in naming...
public abstract class CBOpenConWin extends CBDialog
{
/**
* stores the users connection data for passing to the 'connect()' method.
*/
protected ConnectionData newCon; //ConnectionData newCon;
protected JTextField hostName, port, baseDN, managerDN;
protected CBJComboBox version, level;
//protected JCheckBox useSSL; // whether to use SSL
protected JPasswordField password;
protected JLabel hostLabel, portLabel, userMessage;
protected CBSaveLoadTemplate myTemplater;
static int threadID = 1; // naming variable for thread debugging
static final boolean DEBUGTHREADS = false;
// Security Levels ...
static final int NONE = 0;
static final int USER_AUTH = 1;
static final int SSL_NO_AUTH = 2;
static final int SSL_USER_AUTH = 3;
static final int SASL = 4;
static final int GSSAPI = 5; // Vadim: GSSAPI
// Protocols + Version strings for combo selection box
protected static final String LDAPV2 = CBIntText.get("LDAP v2");
protected static final String LDAPV3 = CBIntText.get("LDAP v3");
protected SecurityActionListener securityListener;
private final static Logger log = Logger.getLogger(CBOpenConWin.class.getName());
/**
* <p>CBOpenConWin allows the user to open an ldap connection. The jndiBroker
* that the connection is opened through is attached to a tree display, and
* a separate schema tree display. An attribute viewer is linked with the
* main tree display. A JLabel allows the connection window to communicate
* status to the user. These parameters are all obtained directly from the
* main JXplorer object</p>
* <p/>
*
* @param owner the owning frame (used for look and feel propagation etc.)
* @param statusDisplay a label used to give status feedback to the user.
* @param clientcerts the client certificate keystore (optional if 'simple ssl' is used).
* @param cacerts the trusted server certificate keystore (required for ssl)
* @param referral the jndi referral handling method ("follow" is default).
* @param aliasType the jndi alias handling - whether aliases are searched or not.
* (default is "searching");
* @deprecated use constructor that takes Help ID.
*/
public CBOpenConWin(Frame owner, JLabel statusDisplay, String clientcerts, String cacerts,
String referral, String aliasType)
{
this(owner, statusDisplay, clientcerts, cacerts, referral, aliasType, null);
}
/**
* <p>CBOpenConWin allows the user to open an ldap connection. The jndiBroker
* that the connection is opened through is attached to a tree display, and
* a separate schema tree display. An attribute viewer is linked with the
* main tree display. A JLabel allows the connection window to communicate
* status to the user. These parameters are all obtained directly from the
* main JXplorer object</p>
* <p/>
*
* @param owner the owning frame (used for look and feel propagation etc.)
* @param statusDisplay a label used to give status feedback to the user.
* @param clientcerts the client certificate keystore (optional if 'simple ssl' is used).
* @param cacerts the trusted server certificate keystore (required for ssl)
* @param referral the jndi referral handling method ("follow" is default).
* @param aliasType the jndi alias handling - whether aliases are searched or not.
* (default is "searching");
* @param helpID the help ID to attach to the Help button.
*/
public CBOpenConWin(Frame owner, JLabel statusDisplay, String clientcerts, String cacerts,
String referral, String aliasType, String helpID)
{
this(owner, statusDisplay, clientcerts, cacerts, helpID);
newCon.referralType = referral;
newCon.aliasType = aliasType;
}
/**
* <p>CBOpenConWin allows the user to open an ldap connection. The jndiBroker
* that the connection is opened through is attached to a tree display, and
* a separate schema tree display. An attribute viewer is linked with the
* main tree display. A JLabel allows the connection window to communicate
* status to the user. These parameters are all obtained directly from the
* main JXplorer object.</p>
* <p/>
* <p/>
* <p>This constructor allows for setting up ssl connections, by
* passing details of keystores through.</p>
*
* @param owner the owning frame (used for look and feel propagation etc.)
* @param statusDisplay a label used to give status feedback to the user.
* @param clientcerts the client certificate keystore (optional if 'simple ssl' is used).
* @param cacerts the trusted server certificate keystore (required for ssl)
* @deprecated use constructor that takes Help ID.
*/
public CBOpenConWin(Frame owner, JLabel statusDisplay, String clientcerts, String cacerts)
{
this(owner, statusDisplay, clientcerts, cacerts, null);
}
/**
* <p>CBOpenConWin allows the user to open an ldap connection. The jndiBroker
* that the connection is opened through is attached to a tree display, and
* a separate schema tree display. An attribute viewer is linked with the
* main tree display. A JLabel allows the connection window to communicate
* status to the user. These parameters are all obtained directly from the
* main JXplorer object.</p>
* <p/>
* <p/>
* <p>This constructor allows for setting up ssl connections, by
* passing details of keystores through.</p>
*
* @param owner the owning frame (used for look and feel propagation etc.)
* @param statusDisplay a label used to give status feedback to the user.
* @param clientcerts the client certificate keystore (optional if 'simple ssl' is used).
* @param cacerts the trusted server certificate keystore (required for ssl)
* @param helpID the help ID to attach to the Help button.
*/
public CBOpenConWin(Frame owner, JLabel statusDisplay, String clientcerts, String cacerts, String helpID)
{
super(owner, CBIntText.get("Open LDAP connection"), helpID); // create modal dialog ...
newCon = new ConnectionData();//ConnectionData();
newCon.clientcerts = clientcerts;
newCon.cacerts = cacerts;
initGUI(statusDisplay);
}
protected void initGUI(JLabel statusDisplay)
{
String oldConnection = "";
int oldPortNo = 19389;
String oldBaseDN = "";
//String oldUseSSL = CBIntText.get("false");
userMessage = statusDisplay;
/**
* Host / port and ldap version details
*/
display.makeHeavy();
JLabel temp;
display.add(hostLabel = new JLabel(" " + CBIntText.get("Host") + ": "));
display.addWide(hostName = new JTextField(oldConnection, 30), 2);
hostLabel.setToolTipText(CBIntText.get("The url of the server; e.g. ") + "'www.cai.com'");
display.add(portLabel = new JLabel(" " + CBIntText.get("Port") + ": "));
display.addLine(port = new JTextField(String.valueOf(oldPortNo), 5));
portLabel.setToolTipText(CBIntText.get("The port number of the LDAP server; often 389."));
display.add(temp = new JLabel(" " + CBIntText.get("Protocol") + (": ")));
display.add(version = new CBJComboBox(new String[]{LDAPV2, LDAPV3}));
version.setSelectedIndex(1);
temp.setToolTipText(CBIntText.get("For all but the oldest servers, this should be 'Ldap v3'."));
version.setToolTipText(CBIntText.get("For all but the oldest servers, this should be 'Ldap v3'."));
display.addLine(new JLabel("")); // padding
display.newLine(); //TE: hack to add space for an extra component to be added in...ie. the DSML URL field...DO NOT REMOVE (see addExtraComponent).
/**
* Optional Panel for base DN.
*/
CBPanel inset = new CBPanel();
inset.setBorder(new TitledBorder(CBIntText.get("Optional Values")));
inset.add(temp = new JLabel(CBIntText.get("Base DN") + ": "));
temp.setToolTipText(CBIntText.get("The base to start browsing from; e.g. ") + "'o=Democorp,c=au'");
inset.makeWide();
inset.addln(baseDN = new JTextField(String.valueOf(oldBaseDN), 30));
display.addLines(inset, 1);
/*
* Security Panel for anonymous vs user/password vs SASL
*/
CBPanel ssl = new CBPanel();
String[] securityOptions = {
CBIntText.get("Anonymous"),
CBIntText.get("User + Password"),
CBIntText.get("SSL + Anonymous"),
CBIntText.get("SSL + User + Password"),
CBIntText.get("SSL + SASL + Keystore Password"),
CBIntText.get("GSSAPI") // Vadim: GSSAPI
};
ssl.setBorder(new TitledBorder(CBIntText.get("Security")));
ssl.makeLight();
ssl.add(temp = new JLabel(CBIntText.get("Level") + ":"));
temp.setToolTipText(CBIntText.get("The level of authentication."));
level = new CBJComboBox(securityOptions);
level.setToolTipText(CBIntText.get("Before using SSL, make sure you've set up your keystores in the 'Security' menu."));
ssl.addln(level);
ssl.add(temp = new JLabel(CBIntText.get("User DN") + ": "));
ssl.addln(managerDN = new JTextField(30));
temp.setToolTipText(CBIntText.get("To log on as an authenticated user, enter your user dn here."));
ssl.add(temp = new JLabel(CBIntText.get("Password") + ": "));
ssl.addLine(password = new JPasswordField(30));
temp.setToolTipText(CBIntText.get("Set your user password (or SASL keystore password) here."));
display.addLines(ssl, 3);
OK.setToolTipText(CBIntText.get("Click here to connect using current settings."));
/*
* ca.commons.cbutil.CBSaveLoadTemplate is a fairly cunning component (see)
* that allows the user to save and restore the state of edit fields in a dialog
*/
display.addWide(myTemplater = new CBSaveLoadTemplate("connections.txt"), 5);
addExtraComponent(); //TE: allows the user to insert a component and not mess up the template handling.
display.newLine();
display.add(new JLabel("")); // padding
display.doLayout();
getContentPane().add(display);
doLayout();
myTemplater.loadDefault();
checkSecurityLevel();
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -