⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 networkconfigdialog.java

📁 aglet的部分源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.ibm.aglets.tahiti;/* * @(#)NetworkConfigDialog.java *  * IBM Confidential-Restricted *  * OCO Source Materials *  * 03L7246 (c) Copyright IBM Corp. 1996, 1998 *  * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. */import com.ibm.atp.auth.SharedSecret;import com.ibm.atp.auth.SharedSecrets;// import com.ibm.atp.auth.Challenge;// import com.ibm.atp.auth.Randoms;// import com.ibm.aglets.security.User;// import com.ibm.aglets.security.UserAuthenticator;// import com.ibm.aglets.security.UserAdministrator;import java.awt.Button;import java.awt.Checkbox;import java.awt.Choice;import java.awt.Color;import java.awt.Dialog;import java.awt.Event;import java.awt.FlowLayout;import java.awt.Font;import java.awt.Frame;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Insets;import java.awt.Label;import java.awt.List;import java.awt.Panel;import java.awt.Graphics;import java.awt.TextField;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.io.File;import java.io.InputStream;import java.io.DataInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.net.URL;import java.security.cert.Certificate;import java.util.Hashtable;import java.util.Enumeration;import com.ibm.aglet.system.AgletRuntime;import com.ibm.awb.misc.Resource;import com.ibm.awb.misc.FileUtils;/** * Class NetworkConfigDialog represents the dialog for *  * @version     1.03    96/04/15 * @author      Danny B. Lange * @modified  97/02/17 Yariv Aridor : add subsription support */final class NetworkConfigDialog extends TahitiDialog 	implements ActionListener, ItemListener {	private static final String ACTION_RESTORE_DEFAULTS = "Restore Defaults";	/*	 * Proxy Configuration	 */	private Checkbox _useProxy = new Checkbox("Use HTTP Proxy");	private TextField _proxyHost = new TextField(30);	private TextField _proxyPort = new TextField(5);	private TextField _noProxy = new TextField(35);	/*	 * 	 */	private Checkbox _httpTunneling = 		new Checkbox("Accept HTTP Tunneling Request");	private Checkbox _httpMessaging = 		new Checkbox("Accept HTTP Request as a Message");	/* subscription panel */	private static final int UNDEFINED = 0;	private static final int YES = 1;	private static final int NO = 2;	private static final String ACTION_OK = "OK";	private static final String ACTION_SUBSCRIBE = "subscribe";	private static final String ACTION_UNSUBSCRIBE = "unsubscribe";	protected Button _subscribe = new Button("Subscribe");	protected Button _unsubscribe = new Button("Unsubscribe");	private TextField _boxHost = new TextField(35);	private TextField _boxUserid = new TextField(35);	private TextField _boxPasswd = new TextField(35);	private Choice _updateChoice = new Choice();	private int _boxSubscribe = UNDEFINED;	/* authentication panel */	private Checkbox _authenticationMode = 		new Checkbox("Do Authentication on ATP Connection");	private Checkbox _secureRandomSeed = 		new Checkbox("Use Secure Random Seed");	private static final String CREATE_SHARED_SECRET = 		"Create a new shared secret";	private Button _createSharedSecret = new Button(CREATE_SHARED_SECRET);	private static final String REMOVE_SHARED_SECRET = 		"Remove a shared secret";	private Button _removeSharedSecret = new Button(REMOVE_SHARED_SECRET);	private static final String IMPORT_SHARED_SECRET = 		"Import a shared secret";	private Button _importSharedSecret = new Button(IMPORT_SHARED_SECRET);	private static final String EXPORT_SHARED_SECRET = 		"Export a shared secret";	private Button _exportSharedSecret = new Button(EXPORT_SHARED_SECRET);	/*	 * Singleton instance reference.	 */	private static NetworkConfigDialog _instance = null;	private int boxUpdateValues[] = {		0, 15, 30, 60, 60 * 5, 60 * 15, 60 * 60	};	/*	 * Constructs a new Aglet creation dialog.	 */	private NetworkConfigDialog(MainWindow parent) {		super(parent, "Network Preferences", true);		makePanel();		addButton(ACTION_OK, this);		addCloseButton(null);		addButton(ACTION_RESTORE_DEFAULTS, this);	}	/*	 * The call back methods	 */	public void actionPerformed(ActionEvent ev) {		String cmd = ev.getActionCommand();		if (ACTION_SUBSCRIBE.equals(cmd)) {			subscribe();		} else if (ACTION_UNSUBSCRIBE.equals(cmd)) {			unsubscribe();		} else if (CREATE_SHARED_SECRET.equals(cmd)) {			createSharedSecret();		} else if (REMOVE_SHARED_SECRET.equals(cmd)) {			removeSharedSecret();		} else if (IMPORT_SHARED_SECRET.equals(cmd)) {			importSharedSecret();		} else if (EXPORT_SHARED_SECRET.equals(cmd)) {			exportSharedSecret();		} else if (ACTION_RESTORE_DEFAULTS.equals(cmd)) {			restoreDefaults();		} else if (ACTION_OK.equals(cmd)) {			dispose();			if (save()) {				ShutdownDialog sd = 					new ShutdownDialog((MainWindow)getParent(), 									   "To be effective, you need reboot the server.");				sd.popupAtCenterOfParent();			} 			inform();		} 	}	private void createSharedSecret() {		TahitiDialog d = new CreateSharedSecretDialog(getMainWindow());		d.popupAtCenterOfParent();	}	private void exportSharedSecret() {		class ExportSharedSecret extends TahitiDialog 			implements ActionListener, ItemListener {			List list;			TextField filename;			SharedSecrets secrets;			ExportSharedSecret(Frame f, SharedSecrets secs) {				super(f, EXPORT_SHARED_SECRET, true);				secrets = secs;				add("North", new Label(EXPORT_SHARED_SECRET, Label.CENTER));				GridBagPanel p = new GridBagPanel();				add(p);				list = new List(5, false);				filename = new TextField(20);				GridBagConstraints cns = new GridBagConstraints();				cns.fill = GridBagPanel.HORIZONTAL;				cns.anchor = GridBagConstraints.WEST;				cns.gridwidth = GridBagConstraints.REMAINDER;				p.setConstraints(cns);				p.addLabeled("Domain name list", list);				p.addLabeled("Filename", filename);				list.addItemListener(this);				list.addActionListener(this);				Enumeration domains = secrets.getDomainNames();				if (domains != null) {					while (domains.hasMoreElements()) {						String domain = (String)domains.nextElement();						list.add(domain);					} 				} 				filename.addActionListener(this);				addButton(ACTION_OK, this);				addCloseButton("Cancel");			}			public void itemStateChanged(ItemEvent ev) {				if (ev.getStateChange() == ItemEvent.SELECTED) {					String domainName = list.getSelectedItem();					if (domainName != null &&!domainName.equals("")) {						String filen = 							domainName.toLowerCase().replace(' ', '_') 							+ ".sec";						filename.setText(filen);					} 				} 			} 			public void actionPerformed(ActionEvent ev) {				String domainName = list.getSelectedItem();				if (domainName == null || domainName.equals("")) {					TahitiDialog						.alert(getMainWindow(), "Select a domain name in list")							.popupAtCenterOfParent();					return;				} 				String filen = filename.getText();				if (filen == null || filen.equals("")) {					TahitiDialog.alert(getMainWindow(), "Specify filename")						.popupAtCenterOfParent();					return;				} 				String owner = getOwnerName();				String workDir = FileUtils.getWorkDirectoryForUser(owner);				String secretFilename = workDir + File.separator + filen;				SharedSecret secret = secrets.getSharedSecret(domainName);				if (secret == null) {					TahitiDialog						.alert(getMainWindow(), "The shared secret does not exist")							.popupAtCenterOfParent();					return;				} 				try {					secret.save(secretFilename);				} catch (IOException excpt) {					TahitiDialog.alert(getMainWindow(), 									   "Cannot save").popupAtCenterOfParent();					return;				} 				TahitiDialog.message(getMainWindow(), "Exported", 									 "The shared secret of domain '" 									 + domainName 									 + "' is exported into a file '" 									 + secretFilename 									 + "'").popupAtCenterOfParent();				dispose();			} 		}		;		SharedSecrets secrets = SharedSecrets.getSharedSecrets();		if (secrets == null) {			TahitiDialog.alert(getMainWindow(), 							   "No shared secrets").popupAtCenterOfParent();			return;		} 		TahitiDialog d = new ExportSharedSecret(getMainWindow(), secrets);		d.popupAtCenterOfParent();	}	/*	 * Singletion method to get the instnace	 */	static NetworkConfigDialog getInstance(MainWindow parent) {		if (_instance == null) {			_instance = new NetworkConfigDialog(parent);		} else {			_instance.updateValues();		} 		return _instance;	}	private static String getOwnerName() {		com.ibm.aglet.system.AgletRuntime runtime = 			com.ibm.aglet.system.AgletRuntime.getAgletRuntime();		if (runtime == null) {			return null;		} 		return runtime.getOwnerName();	}	/*	 * Subscribe	 */	private int getStatusCode(Hashtable headers) {		int defValue = -1;		try {			String ret = (String)(headers.get("status-code"));			return ret == null ? defValue : Integer.parseInt(ret);		} catch (Exception e) {}		return defValue;	}	// TEMPRARY	private int getSubscribeStatus(String s) {		if (s.equalsIgnoreCase("yes")) {			return YES;		} else if (s.equalsIgnoreCase("no")) {			return NO;		} else if (s.equalsIgnoreCase("undefined")) {			return UNDEFINED;		} 		return UNDEFINED;	}	private void importSharedSecret() {		class ImportSharedSecret extends TahitiDialog 			implements ActionListener {			TextField filename;			ImportSharedSecret(Frame f) {				super(f, IMPORT_SHARED_SECRET, true);				add("North", new Label(IMPORT_SHARED_SECRET, Label.CENTER));				GridBagPanel p = new GridBagPanel();				add(p);				filename = new TextField(20);				GridBagConstraints cns = new GridBagConstraints();				cns.fill = GridBagPanel.HORIZONTAL;				cns.anchor = GridBagConstraints.WEST;				cns.gridwidth = GridBagConstraints.REMAINDER;				p.setConstraints(cns);				p.addLabeled("Filename", filename);				filename.addActionListener(this);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -