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

📄 ldapconfiguration.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
* Copyright (c) 2006, University of Kent
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without 
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this 
* list of conditions and the following disclaimer.
* 
* Redistributions in binary form must reproduce the above copyright notice, 
* this list of conditions and the following disclaimer in the documentation 
* and/or other materials provided with the distribution. 
*
* 1. Neither the name of the University of Kent nor the names of its 
* contributors may be used to endorse or promote products derived from this 
* software without specific prior written permission. 
*
* 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS  
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
* PURPOSE ARE DISCLAIMED. 
*
* 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
* POSSIBILITY OF SUCH DAMAGE.
*
* 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
* IN THE CIRCUMSTANCES.  IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
* SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
* SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
* GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
* TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
* IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
* SERIOUS FAULTS, IN THIS SOFTWARE.
*
* 5. This license is governed, except to the extent that local laws
* necessarily apply, by the laws of England and Wales.
*/

/*
 * LDAPConfiguration.java - 19/01/06
 */
package issrg.editor2.configurations;

import issrg.utils.LDAP_DIT;
import issrg.utils.xml.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.naming.NamingException;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * This class creates an appropriate LDAP Settings Panel (to be placed in the
 * Dialog) for all the fields that are required for an LDAP entry to be added 
 * to the list of available directories. 
 * <p> 
 * This Class extends NodeItemList as this would enable us to list the 
 * available connections in a list that has reference to some XML nodes. 
 * <p>
 * The connections will be stored in an XML file called 'pe.cfg'. Although 
 * this will be loaded from the <code>ConfigurationComponent</code> to verify 
 * that the 'pe.cfg' is a correct and valid file. 
 * <p>
 * The LDAPConfiguration class takes care of modifying the XML file, and 
 * adding/deleting/modifying of the XML file.
 * <p>
 * The JPanel this component produces can be seen in the 
 * <code>OptionsDialog</code> Dialog, as it is added on the LDAP Settings tab.
 *
 * @see issrg.editor2.ConfigurationComponent
 * @see issrg.editor2.OptionsDialog
 *
 * @author Christian Azzopardi
 */
public class LDAPConfiguration extends NodeItemList implements XMLChangeListener, KeyListener, ActionListener
{
    /**
     * Panels needed to place the component on, and get the GUI right. 
     */
    private JPanel northEastPanel, southEastPanel, eastPanel, westPanel, ldapConfigPanel, bottomWestPanel;
    
    /**
     * Labels that will accompany the JTextFields, and will inform the user
     * what input is required.
     */
    private JLabel nameLabel, hostLabel, versionLabel, usernameLabel, passwordLabel, 
                   baseDNLabel, portLabel, acTypeLabel;
    
    /**
     * TextFields which refer to the user's input.
     */
    private JTextField nameTextField, hostTextField, usernameTextField, 
                       portTextField, baseDNTextField, acTypeTextField;
    
    /**
     * Same as a TextField although the characters typed in are masked.
     */  
    private JPasswordField passwordTextField;
    
    /**
     * Drop down list with the LDAP Version numbers. 
     * For now theses are fixed from 1 to 3. And are loaded from the properties 
     * file.
     */  
    private JComboBox versionComboBox;

    /**
     * Checkbox that toggles input for User Name and Password.
     */  
    private JCheckBox anonCheckBox;
    
    /**
     * Button to initiate a test to the connections available in the listbox.
     */      
    private JButton testConnButton;

    /**
     * An LDAP_DIT component variable, that is not displayed anywhere on the 
     * component and is only used to open test connections and check if they
     * work or not. If no error returns from this component when logging in 
     * to the LDAP Dir, then the connection is good.
     */   
    private LDAP_DIT testLdap;
    
    /**
     * Loads the Resource Strings and Labels for everything to display correctly.
     */
    ResourceBundle rbl = ResourceBundle.getBundle("issrg/editor2/PEComponent_i18n");
    String errorHeader = rbl.getString("ErrorHeader"); //contains Error!
    String infoHeader = rbl.getString("InfoHeader"); //contains Info!
    String ldapConfigLabel1 = rbl.getString("LDAPConfigLabel1"); //contains Directory Name
    String ldapConfigLabel2 = rbl.getString("LDAPConfigLabel2"); //contains DNS Name
    String ldapConfigLabel3 = rbl.getString("LDAPConfigLabel3"); //contains Version
    String ldapConfigLabel4 = rbl.getString("LDAPConfigLabel4"); //contains Username
    String ldapConfigLabel5 = rbl.getString("LDAPConfigLabel5"); //contains Password
    String ldapConfigLabel6 = rbl.getString("LDAPConfigLabel6"); //contains Anonymous Bind
    String ldapConfigLabel7 = rbl.getString("LDAPConfigLabel7"); //contains Port
    String ldapConfigLabel8 = rbl.getString("LDAPConfigLabel8"); //contains Base DN
    String ldapConfigLabel9 = rbl.getString("LDAPConfigLabel9"); //contains AC LDAP Type:
    String ldapConfigPanel1 = rbl.getString("LDAPConfigPanel1"); //contains Server Details
    String ldapConfigPanel2 = rbl.getString("LDAPConfigPanel2"); //contains Account Details
    String ldapConfigPanel3 = rbl.getString("LDAPConfigPanel3"); //contains Available LDAP Directories
    String ldapConfigPanel4 = rbl.getString("LDAPConfigPanel4"); //contains Attribute Certificate Type
    String ldapConfigError1 = rbl.getString("LDAPConfigError1"); //contains Please Check the Name, Host and Version Fields!
    String ldapConfigError2 = rbl.getString("LDAPConfigError2"); //contains Directory Name Already Exists!
    String ldapConfigError3 = rbl.getString("LDAPConfigError3"); //contains Connection to
    String ldapConfigError4 = rbl.getString("LDAPConfigError4"); //contains Failed
    String ldapConfigSuccess1 = rbl.getString("LDAPConfigSuccess1"); //contains Successfully Connected to 
    String ldapConfigButton1 = rbl.getString("LDAPConfigButton1"); //contains Add DIR
    String ldapConfigButton2 = rbl.getString("LDAPConfigButton2"); //contains Delete DIR
    String ldapConfigButton3 = rbl.getString("LDAPConfigButton3"); //contains Replace
    String ldapConfigButton4 = rbl.getString("LDAPConfigButton4"); //contains Test Connection
    String testConnButtonLabel = rbl.getString("LDAPDialogButton3"); //contains Test Connection
    //------------------
    
    /** 
     * Creates a new instance of LDAPConfiguration. Constructs the 
     * NodeItemList and sets the values of the labels involved.
     *
     * @param that   the XML Editor that will store the XML Document
     *               and take care of firing its XML Events.
     */
    public LDAPConfiguration(XMLEditor that) 
    {
        super(that);
        
        //Set The Appropriate Labels from the Properties File
        setCaption("DIRECTORY_NAME_LABEL", ldapConfigLabel1);
        setCaption("HOST_LABEL", ldapConfigLabel2);
        setCaption("VERSION_LABEL", ldapConfigLabel3);
        setCaption("LOGIN_LABEL", ldapConfigLabel4);
        setCaption("PASSWORD_LABEL", ldapConfigLabel5);
        setCaption("ANON_LABEL", ldapConfigLabel6);
        setCaption("PORT_LABEL", ldapConfigLabel7);
        setCaption("BASE_DN_LABEL", ldapConfigLabel8);
        setCaption("NORTH_EAST_PANEL", ldapConfigPanel1);
        setCaption("SOUTH_EAST_PANEL", ldapConfigPanel2);
        setCaption("WEST_PANEL", ldapConfigPanel3);
        setCaption("ADD_BUTTON", ldapConfigButton1);
        setCaption("DELETE_BUTTON", ldapConfigButton2);
        setCaption("REPLACE_BUTTON", ldapConfigButton3);
        setCaption("TEST_CONN_BUTTON", testConnButtonLabel);
        setCaption("AC_LDAP_TYPE", ldapConfigLabel9);
        setCaption("BOTTOM_WEST_BORDER", ldapConfigPanel4);
        //---------------------------------------------------
        
        //fill in Versions JComboBox from international file
        populateVersions();
        //set the default value:
        versionComboBox.setSelectedItem("3");
        //--------------------------------------------------
    }
    
    /**
     * Method that creates a GUI Panel with the required fields to create
     * and modify an LDAP connection. 
     *
     * @return     a JPanel with all the entry fields for the LDAP Dialog.
     */
    public JPanel getContentPanel()
    {
        //initializations of JPanels to use
        westPanel = super.getContentPanel();     //NodeList Panel
        westPanel.setPreferredSize(new Dimension(300,200));
        northEastPanel = new JPanel();        
        southEastPanel = new JPanel();
        bottomWestPanel = new JPanel();
        eastPanel = new JPanel();
        ldapConfigPanel = new JPanel();
        //---------------------------------
        
        //initialization of the JLabels
        nameLabel = new JLabel();
        hostLabel = new JLabel();
        portLabel = new JLabel();
        versionLabel = new JLabel();
        baseDNLabel = new JLabel();
        usernameLabel = new JLabel();
        passwordLabel = new JLabel();
        acTypeLabel = new JLabel();

⌨️ 快捷键说明

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