protected void initializeDatabaseLookup(String passwordColumn, String userTable, String userNameColumn) throws IllegalAccessException, ClassNotFoundException, InstantiationException { DBUtil dbUtil = new DBUtil(getDatabaseURL(), getDatabaseUserName(), getDatabasePassword(), getDatabaseDriver()); DataSource dataSource = dbUtil.getDataSource(); jdbcRealm.setDataSource(dataSource); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("SELECT ").append(passwordColumn).append(" FROM ").append(userTable).append(" WHERE ") .append(userNameColumn).append(" = ?"); jdbcRealm.setAuthenticationQuery(stringBuilder.toString()); }
private void initializeDatabaseLookup() throws RuntimeException { try { this.dbUtil = new DBUtil(getDatabaseURL(), getDatabaseUserName(), getDatabasePassword(), getDatabaseDriver()); } catch (ClassNotFoundException e) { throw new RuntimeException("Error loading database driver. Driver class not found.", e); } catch (InstantiationException e) { throw new RuntimeException("Error loading database driver. Error instantiating driver object.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Error loading database driver. Illegal access to driver object.", e); } } }
/** * Creates a DBUtil object based on servlet context configurations. * * @return DBUtil object. * @throws Exception * If an error occurred while reading configurations or while creating database object. */ public static DBUtil getCredentialStoreDBUtil() throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, InstantiationException { String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); String userName = ServerSettings.getCredentialStoreDBUser(); String password = ServerSettings.getCredentialStoreDBPassword(); String driverName = ServerSettings.getCredentialStoreDBDriver(); StringBuilder stringBuilder = new StringBuilder("Starting credential store, connecting to database - "); stringBuilder.append(jdbcUrl).append(" DB user - ").append(userName).append(" driver name - ") .append(driverName); log.debug(stringBuilder.toString()); DBUtil dbUtil = new DBUtil(jdbcUrl, userName, password, driverName); dbUtil.init(); return dbUtil; }
public static CredentialReader getCredentialReader() throws ApplicationSettingsException, IllegalAccessException, InstantiationException { try { String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); String jdbcUsr = ServerSettings.getCredentialStoreDBUser(); String jdbcPass = ServerSettings.getCredentialStoreDBPassword(); String driver = ServerSettings.getCredentialStoreDBDriver(); return new CredentialReaderImpl(new DBUtil(jdbcUrl, jdbcUsr, jdbcPass, driver)); } catch (ClassNotFoundException e) { log.error("Not able to find driver: " + e.getLocalizedMessage()); return null; } }
public DBUtil getDbUtil () throws Exception { return new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver()); }
public CredentialStoreServerHandler() throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, InstantiationException { String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); String userName = ServerSettings.getCredentialStoreDBUser(); String password = ServerSettings.getCredentialStoreDBPassword(); String driverName = ServerSettings.getCredentialStoreDBDriver(); log.debug("Starting credential store, connecting to database - " + jdbcUrl + " DB user - " + userName + " driver name - " + driverName); dbUtil = new DBUtil(jdbcUrl, userName, password, driverName); sshCredentialWriter = new SSHCredentialWriter(dbUtil); certificateCredentialWriter = new CertificateCredentialWriter(dbUtil); credentialReader = new CredentialReaderImpl(dbUtil); }
public static void executeSQL(String sql) throws Exception { DBUtil dbUtil = new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver()); dbUtil.executeSQL(sql); }
public static void waitTillServerStarts() { DBUtil dbUtil = null; try { dbUtil = new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver()); } catch (Exception e) { // ignore } Connection connection = null; try { if (dbUtil != null) { connection = dbUtil.getConnection(); } } catch (Throwable e) { // ignore } while (connection == null) { try { Thread.sleep(1000); try { if (dbUtil != null) { connection = dbUtil.getConnection(); } } catch (SQLException e) { // ignore } } catch (InterruptedException e) { // ignore } } }