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

📄 jxopenconwin.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
         * And the security levels.
         */
        public void actionPerformed(ActionEvent event)
        {
            if (!version.getSelectedItem().equals(DSMLV2))
            {
                dsmlService.setEnabled(false);
                dsmlService.setText("");
                dsmlService.setBackground(Color.lightGray);

                level.setEnabled(true);
                checkSecurityLevel();
            }
            else
            {
                dsmlService.setEnabled(true);
                dsmlService.setBackground(Color.white);

                level.setSelectedIndex(0);
                managerDN.setText("");
                password.setText("");
                checkSecurityLevel();
                level.setEnabled(false);

            }
        }
    }

    /**
     * Over-ride base 'doOK()' method to allow for setting the new 'DSML' protocol if selected...
     */
    public void doOK()
    {
        if (version.getSelectedItem().equals(DSMLV2))
            newCon.protocol = ConnectionData.DSML;
        else
            newCon.protocol = ConnectionData.LDAP;

        addExtraEnvironmentProperties();

        cachePassword();

        super.doOK();

    }

    private void addExtraEnvironmentProperties()
    {
        Properties props = JXplorer.getMyProperties();
        Enumeration keys = props.keys();
        while (keys.hasMoreElements())
        {
            String key = (String) keys.nextElement();
            // at the moment, we'll only add sun ldap and security env variables; there might be others we need later...
            if (key.startsWith("Context")
                    || key.startsWith("context")
                    || key.startsWith("com.sun.jndi.ldap") // more generic than com.sun.jndi.ldap.connect
                    || key.startsWith("java.security") // more generic than javax.security.sasl.qop
                    || key.startsWith("javax.security")) // more generic than javax.security.sasl.qop
            {
                newCon.putExtraProperty(key, props.getProperty(key));
            }
        }
    }

    /**
     * This resets some volitile parameters that might have changed
     * since the last time the user accessed the window.
     *
     * @param newclientcerts the client certificate keystore (optional if 'simple ssl' is used).
     * @param newcacerts     the trusted server certificate keystore (required for ssl)
     * @param newreferral    the jndi referral handling method ("follow" is default).
     * @param newaliasType   the jndi alias handling - whether aliases are searched or not.
     *                       (default is "searching");
     */
    public void reinit(String newclientcerts, String newcacerts,
                       String newreferral, String newaliasType)
    {
        newCon.clientcerts = newclientcerts;
        newCon.cacerts = newcacerts;
        newCon.referralType = newreferral;
        newCon.aliasType = newaliasType;

        if (jndiBroker == null)    //TE: bug 3222.
            newCon.tracing = jxplorer.jndiBroker.getTracing();
        else
            newCon.tracing = jndiBroker.getTracing();
    }

    /**
     * Sets title back to 'open ldap connection'/clears password...
     * but sets the title to 'Open LDAP/DSML Connection".
     */
    public void resetTitleAndPassword()
    {
        this.setTitle(CBIntText.get("Open LDAP/DSML Connection"));

        if (!JXplorer.getProperty("jxplorer.cache.passwords").equals("true"))
            password.setText("");
    }

    /**
     * This method is called when the user connection data
     * has been gathered and (roughly) checked.
     *
     * @param connectData the parsed connection data containing
     *                    host and port details, security info, etc.
     */
    public void connect(ConnectionData connectData)
    {
        // Queue the request on the broker's request list.  When completed, the request
        // will trigger the 'DataReady()' method below.

        try
        {
            jndiBroker = jxplorer.jndiBroker;

            // clear the GUI preparatory to the new data appearing.
            jxplorer.preConnectionSetup();

            // create a new data query and put it on the query stack for the connection thread.
            DataQuery query = jndiBroker.connect(connectData);

            query.addDataListener(this);

        }
                // the code above just sets up the connection call, and doesn't really
                // do anything that should cause an exception - the connection is
                // done in a different thread, and any exceptions should be caught
                // by the 'DataReady()' code below.

        catch (Exception e)
        {
            log.log(Level.WARNING, "Unexpected exception in JXOpenConWin.connect", e);
            e.printStackTrace();
        }
    }

    /**
     * This method is called when a new connection attempt is finished.
     * If successfull, the main, search and schema trees are updated
     * with theire data sources, and a successfull connection message
     * displayed to the user.  If unsuccessful, an error message is displayed.
     *
     * @param request the connection request data object.
     */

    //XXX remember that this method is being run by the directory connection thread -
    //XXX so it can use unthreaded jndiBroker directory methods with impunity.
    public void dataReady(DataQuery request)
    {
        if (!(request instanceof JNDIBroker.DataConnectionQuery))
        {
            log.warning("Incorrect data for connection - cannot connect");
            return;
        }

        if (request.hasException() == false)  // apparently we have a valid connection to play with!
        {
            if (jxplorer.postConnectionSetup((JNDIBroker.DataConnectionQuery) request))
            {
                setVisible(false);

                ((JNDIBroker.DataConnectionQuery) request).conData.clearPasswords();

                dispose();
            }
            else
            {
                jxplorer.disconnect();
            }
        }
        else    // request registered an error in jdniBroker
        {
            // do we want a nice error box?  I think we do!
            new CBErrorWin(this, "Error opening connection:\n" + request.getException().getMessage(), request.getException()); // automatically visible one-shot.

            log.log(Level.WARNING, "Error opening connection ", request.getException());
            request.clearException();
            setTitle(CBIntText.get("Couldn't Connect" + ": " + "Try Again"));
            dispose();	//TE: don't remove this...for some reason if an incorrect port etc is entered on Linux - JX crashes!
            setVisible(true);
            userMessage.setText(CBIntText.get("Couldn't Open ") + request.getExtendedData("url"));
            jxplorer.disconnect();
            request.squelch();  // we're done here.
        }
    }

    /**
     * overload the getURL method of the base class to use the new url field.
     *
     * @return the correct, parsed URL.
     */
    protected String getURL() throws NumberFormatException, URISyntaxException
    {
        String url = super.getURL();
        if (version.getSelectedItem().equals(DSMLV2)) // dsml may require an extra 'service' bit to add to the url...
        {
            String dsml = dsmlService.getText();
            if (dsml.startsWith("/"))               // trim any starting slash - we add it back just below.
                dsml = dsml.substring(1);

            if (url.startsWith("ldap://"))          // trim the ldap: protocol prefix - this is usually set by CBOpenConWin...
                url = url.substring(7);

            url = "http://" + url + "/" + dsml;     // construct the full dsml url...
        }
        log.fine("connecting with url: " + url);
        return url;
    }
}

⌨️ 快捷键说明

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