This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 237388 - 7.4 does not remember the password correctly. Project that used to work under 7.1 breaks in 7.4
Summary: 7.4 does not remember the password correctly. Project that used to work under...
Status: RESOLVED INCOMPLETE
Alias: None
Product: db
Classification: Unclassified
Component: MySQL (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Libor Fischmeistr
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-20 23:35 UTC by ndev69
Modified: 2014-01-18 13:20 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ndev69 2013-10-20 23:35:27 UTC
I run into this problem so much with Netbeans. I had a program that worked but when I upgrade my IDE, which I have to do to keep up with other projects. Previous version projects break that did not used to be broke. Anyway, my software uses a website to verify licenses and then installs all the database connection wiring when run for the first time. This part of the program still works. However when the user quits the program and runs it a second time it always wants to know the password (which the user does not know) and even if I give him the password and tell him to check the remember password button it still does not remember the password from one run to the next. Once the password is entered it works until the program is exited then it wants the password again when you run the program the next time. This seems to be an ongoing problem because I have seen complaints about this in the past but nobody has taken the time to actually fix the problem. They just seem to explain what Netbeans does and that is it. Can someone actually FIX this problem?

This is the section of my code that does the hard wiring of the connection and saves it to disk.

            // setup database connection
            byte[] uncryptedPwd = cc.doFinal(StringUtils.hexStringToByteArray(passwd));
            JDBCDriver[] drivers = JDBCDriverManager.getDefault().getDrivers("com.mysql.jdbc.Driver");
            if (drivers == null || drivers.length <= 0)
            drivers = new JDBCDriver [] {JDBCDriver.create("MySql", "MySql (Connector/J driver)", jdbcdriver, new URL[] {new URL("nbinst:/ide/modules/ext/mysql-connector-java-5.1.23-bin.jar")})};
            //nbinst:/modules/ext/mysql-connector-java-5.1.6-bin.jar
            //jar:nbinst://org.netbeans.modules.db.drivers/modules/ext/mysql-connector-java-5.1.13-bin.jar!/
            String jdbcstr = "jdbc:mysql://" + dbhost + "/" + jdb;
            DatabaseConnection dbconn = DatabaseConnection.create(drivers[0], jdbcstr, jdbuser, null, new String(uncryptedPwd), true);
            ConnectionManager.getDefault().addConnection(dbconn);
            SQLConnectionManager.getDefault().setActiveConnection(dbconn);
            SQLConnectionManager.getDefault().remember();


SQLConnectionManager is just my own class that is built around the ConnectionManager and ConnectionManager events. The remember function just writes that connection name to my preferences for recall later. Below are the remember and recall functions that simply interface with the ConnectionManager

    /**
     * Recalls the information stored in the preference store and selects
     * the connection that was stored.
     */
    public void recall() {
        // read the name of the connection to recall
        Preferences prefs = NbPreferences.forModule(SQLConnectionManager.class);
        String defaultConnection = prefs.get("default", null);
        if (defaultConnection == null) return;

        // look for it in the list of available connections
        final ConnectionManager defaultMgr = ConnectionManager.getDefault();
        DatabaseConnection[] connections = defaultMgr.getConnections();
        if (connections.length > 0) {
            for (DatabaseConnection connection : connections) {
                if (connection.getName().equals(defaultConnection)) {

                    boolean reload = false;
                    String ps = connection.getPassword();
                    if (ps == null || ps.length() == 0) reload = true;
                    String us = connection.getUser();
                    if (us == null || us.length() == 0) reload = true;
                    // I call this to handle any loading or prep needed
                    // to load the connection. If the user did not store
                    // the password it will resolve here.
                    if (reload) defaultMgr.showConnectionDialog(connection);
                    else {
                       final DatabaseConnection conn = connection;
                       Thread t = new Thread() {
                            @Override
                            public void run() {
                                try { defaultMgr.connect(conn); }
                                catch (DatabaseException ex) {
                                    ex.printStackTrace(IOProvider.getDefault().getStdOut());
                                    this.interrupt();
                                } catch (IllegalStateException il) {
                                    il.printStackTrace(IOProvider.getDefault().getStdOut());
                                    this.interrupt();
                                }                                
                            }
                        };
                       t.start();
                       try { t.join(); }
                       catch (InterruptedException ex) { connection = null; }
                    }
                    setActiveConnection(connection);
                    break;
                }
            }
        }
    }

    /**
     * Remembers the currently selected <code>DatabaseConnection</code>
     * in a preference store. Uses the NBPreferences instead of the
     * standard Java preference store.
     */
    public void remember() {
        if (currentConnection == null) return;
        try {
            Preferences prefs = NbPreferences.forModule(SQLConnectionManager.class);
            prefs.put("default", currentConnection.getName());
            prefs.sync();
        } catch (BackingStoreException ex) {
            ex.printStackTrace(IOProvider.getDefault().getStdOut());
        }
    }
Comment 1 ndev69 2013-10-20 23:52:53 UTC
Sorry for the text I was not aware that word wrap was something
that has not been fixed either. What a way to run a RR.
Comment 2 matthias42 2013-11-02 23:43:26 UTC
Import info first: I'm not a netbeans developer!

I'll asume this is not a bug against netbeans ide, but against the netbeans plattform?!

At some point the passwords of the db connections were saved together with tne connections. As this is unsave and netbeans provides a keyring, that is currently used.

So you should check that the keyring modules are included in your setup. Your descroption sounds like a behaviour of a fallback keyring (saving the password for the duration of the session).

You could also reset the password when you "recall", as your usecase does not align with the normally intended behaviour. The password would then needed to be saved in another way.

Maybe this helps.
Comment 3 matthias42 2014-01-18 13:20:27 UTC
Closing as incomplete, as no further info was provided. From my analysis the wiring in the db module is sane (that is, password saving is delegated to keyring implementation).

You can get more information by:

- Running with the logger (JUL) org.netbeans.modules.db.explorer.DatabaseConnection on FINE (password saving and restore is protocolled there)
- Place breakpoints in:
  org.netbeans.modules.db.explorer.DatabaseConnection#restorePassword
  org.netbeans.modules.db.explorer.DatabaseConnection#storePassword
  org.netbeans.modules.db.explorer.DatabaseConnectionConvertor.AtomicWriter#write
  look for "storePassword")

As I already wrote I suspect missing dependencies.