loginmodules/password/authenticators/jdbc/src/main/java/org/beiter/michael/authn/jaas/loginmodules/password/authenticators/jdbc/JdbcPasswordAuthenticator.java
private Connection getDatabaseConnection()
            throws LoginException {

        Connection connection;
        if (StringUtils.isNotEmpty(dbProps.get().getJndiConnectionName())) {
            try {
                connection = ConnectionFactory.getConnection(dbProps.get().getJndiConnectionName());
            } catch (FactoryException e) {
                final String error = "Could not retrieve JNDI database connection";
                LOG.warn(error, e);
                throw Util.newLoginException(error, e);
            }
        } else {
            try {
                // connection spec is required
                if (connProps.get() == null) {
                    final String error = "Database connection pool configuration has not been provided or initialized";
                    LOG.warn(error);
                    throw new FactoryException(error);
                }

                // driver is required
                if (StringUtils.isBlank(connProps.get().getDriver())) {
                    final String error = "Invalid database driver (driver name is null or empty)";
                    LOG.warn(error);
                    throw new FactoryException(error);
                }

                // url is required
                if (StringUtils.isBlank(connProps.get().getUrl())) {
                    final String error = "Invalid database URL (URL is null or empty)";
                    LOG.warn(error);
                    throw new FactoryException(error);
                }

                connection = ConnectionFactory.getConnection(connProps.get());

            } catch (FactoryException e) {
                final String error = "Could not create pooled database connection";
                LOG.warn(error, e);
                throw Util.newLoginException(error, e);
            }
        }

        return connection;
    }
private Connection getDatabaseConnection()
            throws LoginException {

        Connection connection;
        if (StringUtils.isNotEmpty(dbProps.get().getJndiConnectionName())) {
            try {
                connection = ConnectionFactory.getConnection(dbProps.get().getJndiConnectionName());
            } catch (FactoryException e) {
                final String error = "Could not retrieve JNDI database connection";
                LOG.warn(error, e);
                throw Util.newLoginException(error, e);
            }
        } else {
            try {
                // connection spec is required
                if (connProps.get() == null) {
                    final String error = "Database connection pool configuration has not been provided or initialized";
                    LOG.warn(error);
                    throw new FactoryException(error);
                }

                // driver is required
                if (StringUtils.isBlank(connProps.get().getDriver())) {
                    final String error = "Invalid database driver (driver name is null or empty)";
                    LOG.warn(error);
                    throw new FactoryException(error);
                }

                // url is required
                if (StringUtils.isBlank(connProps.get().getUrl())) {
                    final String error = "Invalid database URL (URL is null or empty)";
                    LOG.warn(error);
                    throw new FactoryException(error);
                }

                connection = ConnectionFactory.getConnection(connProps.get());

            } catch (FactoryException e) {
                final String error = "Could not create pooled database connection";
                LOG.warn(error, e);
                throw Util.newLoginException(error, e);
            }
        }

        return connection;
    }
Obtain a database connection - either a JNDI connection (directly from the factory), or a pooled JDBC connection

@return a pooled database connection
@throws LoginException when the connection cannot be retrieved from JNDI or the connection pool, or the pool
cannot be created