loginsettingdialog.java.svn-base

来自「开源项目openfire的完整源程序」· SVN-BASE 代码 · 共 707 行 · 第 1/3 页

SVN-BASE
707
字号
/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware;


import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.component.TitlePanel;
import org.jivesoftware.spark.component.WrappedLabel;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;

import javax.security.auth.Subject;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.security.Principal;
import java.util.Properties;

/**
 * Allows users to configure startup options.
 *
 * @author Derek DeMoro
 */
public class LoginSettingDialog implements PropertyChangeListener {
    private JOptionPane optionPane;
    private JDialog optionsDialog;

    private TitlePanel titlePanel;

    private JCheckBox autoDiscoverBox = new JCheckBox();

    private JLabel portLabel = new JLabel();
    private JTextField portField = new JTextField();

    private JLabel xmppHostLabel = new JLabel();
    private JTextField xmppHostField = new JTextField();

    private JLabel timeOutLabel = new JLabel();
    private JTextField timeOutField = new JTextField();

    private JLabel resourceLabel = new JLabel();
    private JTextField resourceField = new JTextField();

    private JCheckBox autoLoginBox = new JCheckBox();

    private JCheckBox useSSLBox = new JCheckBox();

    private JCheckBox compressionBox = new JCheckBox();

    private LocalPreferences localPreferences;

    private ProxyPanel proxyPanel;

    private JCheckBox useSSOBox = new JCheckBox();
    private JLabel ssoRealmLabel = new JLabel();
    private JTextField ssoRealmField = new JTextField();
    private JLabel ssoKDCLabel = new JLabel();
    private JTextField ssoKDCField = new JTextField();
    private JLabel ssoMethodFileLabel = new JLabel();
    private JRadioButton ssoMethodFileRadio = new JRadioButton();
    private JLabel ssoMethodDNSLabel = new JLabel();
    private JRadioButton ssoMethodDNSRadio = new JRadioButton();
    private JLabel ssoMethodManualLabel = new JLabel();
    private JRadioButton ssoMethodManualRadio = new JRadioButton();
    private JLabel ssoMethodLabel = new JLabel();
    private ButtonGroup ssoMethodRadio = new ButtonGroup();

    private JCheckBox debuggerBox = new JCheckBox();

    /**
     * Empty Constructor.
     */
    public LoginSettingDialog() {
        localPreferences = SettingsManager.getLocalPreferences();
        proxyPanel = new ProxyPanel();
    }

    /**
     * Invokes the OptionsDialog.
     *
     * @param owner the parent owner of this dialog. This is used for correct parenting.
     * @return true if the options have been changed.
     */
    public boolean invoke(JFrame owner) {
        // Load local localPref
        JTabbedPane tabbedPane = new JTabbedPane();

        portField.setText(Integer.toString(localPreferences.getXmppPort()));
        timeOutField.setText(Integer.toString(localPreferences.getTimeOut()));
        autoLoginBox.setSelected(localPreferences.isAutoLogin());
        useSSLBox.setSelected(localPreferences.isSSL());
        xmppHostField.setText(localPreferences.getXmppHost());
        resourceField.setText(localPreferences.getResource());

        if (localPreferences.getResource() == null) {
            resourceField.setText("spark");
        }

        final JPanel inputPanel = new JPanel();
        final JPanel ssoPanel = new JPanel();

        tabbedPane.addTab(Res.getString("tab.general"), inputPanel);
        tabbedPane.addTab(Res.getString("tab.proxy"), proxyPanel);
        tabbedPane.addTab("SSO", ssoPanel);

        inputPanel.setLayout(new GridBagLayout());
        ssoPanel.setLayout(new GridBagLayout());

        ResourceUtils.resLabel(portLabel, portField, Res.getString("label.port"));
        ResourceUtils.resLabel(timeOutLabel, timeOutField, Res.getString("label.response.timeout"));
        ResourceUtils.resButton(autoLoginBox, Res.getString("label.auto.login"));
        ResourceUtils.resButton(useSSLBox, Res.getString("label.old.ssl"));
        ResourceUtils.resLabel(xmppHostLabel, xmppHostField, Res.getString("label.host"));
        ResourceUtils.resButton(autoDiscoverBox, Res.getString("checkbox.auto.discover.port"));
        ResourceUtils.resLabel(resourceLabel, resourceField, Res.getString("label.resource"));
        ResourceUtils.resButton(compressionBox, "Use Co&mpression");
        ResourceUtils.resButton(useSSOBox, "&Use Single Sign-On (SSO) via GSSAPI");
        ResourceUtils.resButton(debuggerBox, "Start &Debugger on startup");

        inputPanel.add(autoDiscoverBox, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

        autoDiscoverBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateAutoDiscovery();
            }
        });

        autoDiscoverBox.setSelected(!localPreferences.isHostAndPortConfigured());
        updateAutoDiscovery();

        compressionBox.setSelected(localPreferences.isCompressionEnabled());

        final JPanel connectionPanel = new JPanel();
        connectionPanel.setLayout(new GridBagLayout());
        connectionPanel.setBorder(BorderFactory.createTitledBorder(Res.getString("group.connection")));

        connectionPanel.add(xmppHostLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        connectionPanel.add(xmppHostField, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 200, 0));

        connectionPanel.add(portLabel, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        connectionPanel.add(portField, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));

        inputPanel.add(connectionPanel, new GridBagConstraints(0, 1, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));

        inputPanel.add(resourceLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        inputPanel.add(resourceField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 100, 0));

        inputPanel.add(timeOutLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        inputPanel.add(timeOutField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));

        inputPanel.add(useSSLBox, new GridBagConstraints(0, 4, 2, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

        inputPanel.add(compressionBox, new GridBagConstraints(0, 5, 2, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
        inputPanel.add(debuggerBox, new GridBagConstraints(0, 6, 2, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

        // Create the title panel for this dialog
        titlePanel = new TitlePanel("Advanced Connection Preferences", "", SparkRes.getImageIcon(SparkRes.BLANK_24x24), true);

        // Setup SSO Panel

        // Load local preferences
        boolean isSSOEnabled = localPreferences.isSSOEnabled();
        boolean showAdvSSO = localPreferences.getSSOAdv();

        ssoPanel.add(useSSOBox, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

        final WrappedLabel wrappedLabel = new WrappedLabel();
        String principalName = null;
        try {
            principalName = getPrincipalName();
        }
        catch (Exception e) {
            // Ignore
        }


        if (ModelUtil.hasLength(principalName)) {
            wrappedLabel.setText("This will use the Desktop Account for \"" + principalName + "\" to login to the server.");
        }
        else {
            wrappedLabel.setText("Spark is unable to find the principal to use for Single Sign-On. This will prevent SSO from working.");
        }

        wrappedLabel.setBackground(Color.white);
        ssoPanel.add(wrappedLabel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));



        useSSOBox.setSelected(isSSOEnabled);
        ssoMethodFileRadio.setEnabled(isSSOEnabled);
        ssoMethodDNSRadio.setEnabled(isSSOEnabled);
        ssoMethodManualRadio.setEnabled(isSSOEnabled);
        ssoRealmField.setEnabled(isSSOEnabled);
        ssoKDCField.setEnabled(isSSOEnabled);

        if(showAdvSSO) {
            ssoMethodFileLabel.setText("Use krb5.conf or krb5.ini:");
            ssoPanel.add(ssoMethodFileLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
            ssoPanel.add(ssoMethodFileRadio, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

⌨️ 快捷键说明

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