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

📄 ldapconfiguration.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        //-----------------------------
        
        //initialization of the JTextFields
        nameTextField = new JTextField(15);
        hostTextField = new JTextField(15);
        portTextField = new JTextField(6);
        baseDNTextField = new JTextField(15);
        usernameTextField = new JTextField(15);
        passwordTextField = new JPasswordField(15);
        acTypeTextField = new JTextField(10);
        //---------------------------------
        
        //setting the KeyListeners to the required JTextFields
        nameTextField.addKeyListener(this);
        hostTextField.addKeyListener(this);
        portTextField.addKeyListener(this);
        baseDNTextField.addKeyListener(this);
        usernameTextField.addKeyListener(this);
        passwordTextField.addKeyListener(this);
        acTypeTextField.addKeyListener(this);
        //---------------------------------
        
        //initialization of the other Components
        versionComboBox = new JComboBox();
        testConnButton = new JButton("Test");
        testConnButton.addActionListener(this);        
        anonCheckBox = new JCheckBox();
        anonCheckBox.addActionListener(this);
        testLdap = new LDAP_DIT();
        //---------------------------------
                
        //Setting the Layout Manager
        northEastPanel.setLayout(new GridBagLayout());
        southEastPanel.setLayout(new GridBagLayout());
        bottomWestPanel.setLayout(new GridBagLayout());
        eastPanel.setLayout(new BorderLayout());
        ldapConfigPanel.setLayout(new BorderLayout());
        //--------------------------
        
        //Fill in the Server Details Panel
        constraints.insets = new Insets(5,5,0,0);
        addComponent(nameLabel, northEastPanel, 0, 0, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(hostLabel, northEastPanel, 1, 0, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(portLabel, northEastPanel, 2, 0, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(versionLabel, northEastPanel, 2, 2, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(baseDNLabel, northEastPanel, 3, 0, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(nameTextField, northEastPanel, 0, 1, 3, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        addComponent(hostTextField, northEastPanel, 1, 1, 3, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        addComponent(portTextField, northEastPanel, 2, 1, 1, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        addComponent(versionComboBox, northEastPanel, 2, 3, 1, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        addComponent(baseDNTextField, northEastPanel, 3, 1, 3, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        //---------------------------------
        
        //Fill in the User Account Panel
        addComponent(usernameLabel, southEastPanel, 0, 0, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(usernameTextField, southEastPanel, 0, 1, 4, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        addComponent(passwordLabel, southEastPanel, 1, 0, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(passwordTextField, southEastPanel, 1, 1, 4, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        addComponent(anonCheckBox, southEastPanel, 2, 1, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(testConnButton, southEastPanel, 2, 4, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        //------------------------------
        
        //Fill in the Attribute Type Panel (Bottom West)
        addComponent(acTypeLabel, bottomWestPanel, 0, 0, 1, 1, GridBagConstraints.LINE_END, 0, 0, GridBagConstraints.NONE);
        addComponent(acTypeTextField, bottomWestPanel, 0, 1, 1, 1, GridBagConstraints.LINE_START, 1, 0, GridBagConstraints.HORIZONTAL);
        
        //Add the Server + Account Panels to one...
        eastPanel.add(northEastPanel, BorderLayout.NORTH);
        eastPanel.add(southEastPanel, BorderLayout.SOUTH);
        eastPanel.add(bottomWestPanel, BorderLayout.CENTER);
        //-----------------------------------------
        
        //Create the final panel
        ldapConfigPanel.add(westPanel, BorderLayout.EAST);
        ldapConfigPanel.add(eastPanel, BorderLayout.WEST);
        //----------------------
        
        return ldapConfigPanel;
    }
    
   /**
    *  Sets the text the component will show. If component parameter is not found 
    *  in the list of parameters, the method will call its super method to attempt
    *  to find the component there.
    *
    *  @param internalName         The internal name used in the program.
    *  @param internationalName    The international name to set the text to.
    */       
    public void setCaption(String internalName, String internationalName)
    {
        if (internalName.equals("NORTH_EAST_PANEL"))
        {
            northEastPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), internationalName));
        }
        else if (internalName.equals("SOUTH_EAST_PANEL"))
        {
            southEastPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), internationalName));
        }
        else if (internalName.equals("WEST_PANEL"))
        {
            westPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), internationalName));
        }
        else if (internalName.equals("DIRECTORY_NAME_LABEL"))
        {
            nameLabel.setText(internationalName);
        }
        else if (internalName.equals("HOST_LABEL"))
        {
            hostLabel.setText(internationalName);
        }        
        else if (internalName.equals("VERSION_LABEL"))
        {
            versionLabel.setText(internationalName);
        }
        else if (internalName.equals("LOGIN_LABEL"))
        {
            usernameLabel.setText(internationalName);
        }
        else if (internalName.equals("PASSWORD_LABEL"))
        {
            passwordLabel.setText(internationalName);
        }        
        else if (internalName.equals("PORT_LABEL"))
        {
            portLabel.setText(internationalName);
        }       
        else if (internalName.equals("ANON_LABEL"))
        {
            anonCheckBox.setText(internationalName);
        }            
        else if (internalName.equals("BASE_DN_LABEL"))
        {
            baseDNLabel.setText(internationalName);
        }              
        else if (internalName.equals("TEST_CONN_BUTTON"))
        {
            testConnButton.setText(internationalName);
        }
        else if (internalName.equals("AC_LDAP_TYPE"))
        {
            acTypeLabel.setText(internationalName);
        }
        else if (internalName.equals("BOTTOM_WEST_BORDER"))
        {
            bottomWestPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), internationalName));
        }
        else super.setCaption(internalName, internationalName);
    }
    
    /**
     * A simple method to populate the Drop down list with the version 
     * number. Was implemented in a loop so that the version numbers that
     * are stored in the '.properties' file will be loaded one by one. 
     * <p> 
     * Was implemented like this, so that if there are versions with a '.'
     * they will be loaded too.
     */
    public void populateVersions()
    {        
        String ver;
        
        for(int y = 1; ; y++) //then to load subpolicy editors
        {
            try
            {
                ver = rbl.getString("LDAPConfigVersion" + y);
                versionComboBox.addItem(ver);
            }
            catch(MissingResourceException mre) 
            {
                 break;
            }
        }
    }
    
    /**
     * This method can return true, if the Connection Name variable exists 
     * already. If The connection does not exist it will return false. 
     * This is used as a measure so that there will be no double entries.
     *
     * @param childToCheck   The element variable with the connection to check 
     *                       if already exists in the LDAP directory already.
     *
     * @return   a boolean which says if a connection name exists or not in the 
     *           'pe.cfg' file.
     */
    public boolean isInPolicy(Element childToCheck)
    {
        NodeList nlist1 = ((Element)getParentNode()).getElementsByTagName("LDAPDirectory");
        
        for (int i = 0; i < nlist.getLength() ; i++)
        {
            Element child = (Element)nlist1.item(i);
        
            if ((childToCheck.getAttribute("Name").equals(child.getAttribute("Name"))))
            {
                return true;
            }
        }        
        
        return false;
        
    }
    
    /**
     * Reads the Fields from the TextBoxes. Checks that the required entries 
     * to create a valid connection are not empty fields. Then adds the 
     * new Directory to the XML document.
     */
    public void addItem()
    {
        if (nameTextField.getText().equals("") || hostTextField.getText().equals("") 
            || portTextField.getText().equals("")) 
        {
            JOptionPane.showMessageDialog(xmlED, ldapConfigError1, errorHeader, JOptionPane.ERROR_MESSAGE);
            return;
        } 

        Element child = xmlED.DOM.createElement("LDAPDirectory"); 
        child.setAttribute("Name", nameTextField.getText());
        if (isInPolicy(child))
        {
            JOptionPane.showMessageDialog(xmlED, ldapConfigError2, errorHeader, JOptionPane.ERROR_MESSAGE);
            return;
        }
        child.setAttribute("Host", hostTextField.getText());
        child.setAttribute("Port", portTextField.getText());
        child.setAttribute("Version", (String)versionComboBox.getSelectedItem());
        
        if (!acTypeTextField.getText().intern().equals("")) child.setAttribute("ACType", acTypeTextField.getText());
        
        if (baseDNTextField.getText().equals("")) child.setAttribute("BaseDN", ""); 
        else child.setAttribute("BaseDN", baseDNTextField.getText()); 
       
        if (!anonCheckBox.isSelected())
        {
            child.setAttribute("Login", usernameTextField.getText());
            String pword = new String(passwordTextField.getPassword());
            child.setAttribute("Password", pword);
            //child.setAttribute("Password", passwordTextField.getText());
        }
        else 
        {
            child.setAttribute("Login", "");
            child.setAttribute("Password", "");
        }
        

⌨️ 快捷键说明

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