private Connection connect() throws SQLException, CancelledException {

			String loginError = null;

			if (bds.getPassword() == null) {
				serverInfo.setUserInfo(bds);
			}

			connectionType = serverInfo.hasPassword() ? ConnectionType.SSL_Password_Authentication
					: ConnectionType.SSL_No_Authentication;
			try {
				// Specify SSL connection properties
				setSSLProperties();
				Connection c = bds.getConnection();
				successfulConnection = true;
				return c;
			}
			catch (SQLException e) {
				// TODO: Need to verify these
				if (e.getMessage().contains("password-based authentication") ||
					e.getMessage().contains("SCRAM-based") ||
					e.getMessage().contains("password authentication failed")) {
					if (serverInfo.hasPassword()) {
						loginError = "Access denied: " + serverInfo;
						Msg.error(this, loginError);
					}
					// Use Ghidra's authentication infrastructure
					connectionType = ConnectionType.SSL_Password_Authentication; // Try again with a password
					// fallthru to second attempt at getConnection
				}
				else if (e.getMessage().contains("SSL on") &&
					e.getMessage().contains("no pg_hba.conf entry")) {
					connectionType = ConnectionType.Unencrypted_No_Authentication; // Try again without any SSL
					bds.removeConnectionProperty("sslmode");
					bds.removeConnectionProperty("sslfactory");
					// fallthru to second attempt at getConnection
				}
				else {
					throw e;
				}
			}
			finally {
				Msg.debug(this, serverInfo + " getConnection: active=" + bds.getNumActive() +
					" idle=" + bds.getNumIdle());
			}

			while (true) {
				ClientAuthenticator clientAuthenticator = null;
				if (connectionType == ConnectionType.SSL_Password_Authentication) {
					clientAuthenticator = ClientUtil.getClientAuthenticator();
					if (clientAuthenticator == null) { // Make sure authenticator is registered
						throw new SQLException("No registered authenticator");
					}
					NameCallback nameCb = new NameCallback("User ID:", bds.getUsername());
					boolean allowUserIDEntry = true;
					if (!serverInfo.hasDefaultLogin()) {
						nameCb.setName(bds.getUsername());
						allowUserIDEntry = false;
					}
					PasswordCallback passCb = new PasswordCallback(" ", false); // force use of default prompting
					try {
						if (!clientAuthenticator.processPasswordCallbacks(
							"BSim Database Authentication", "BSim DB Server", serverInfo.toString(),
							allowUserIDEntry, nameCb, passCb, null, null, loginError)) {
							throw new CancelledException();
						}
						bds.setPassword(new String(passCb.getPassword()));
						// User may have specified new username, or this may return NULL
						if (serverInfo.hasDefaultLogin()) {
							bds.setUsername(nameCb.getName());
						}
					}
					finally {
						passCb.clearPassword();
					}
				}
				try {
					Connection c = bds.getConnection();
					successfulConnection = true;
					return c;
				}
				catch (SQLException e) {
					if ((clientAuthenticator instanceof DefaultClientAuthenticator) &&
						e.getMessage().contains("password authentication failed")) {
						// wrong password provided via popup dialog - try again
						loginError = "Access denied: " + serverInfo;
						continue;
					}
					connectionType = ConnectionType.SSL_No_Authentication;
					throw e;
				}
				finally {
					Msg.debug(this, serverInfo + " getConnection: active=" + bds.getNumActive() +
						" idle=" + bds.getNumIdle());
				}
			}
		}
Establish Postgres DB {@link Connection} performing any required authentication. 
@throws SQLException if connection or authentication error occurs 
@throws CancelledException if connection cancelled by user
Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimPostgresDBConnectionManager.java