public CloseableDataSource newDataSource(final AbstractJpaProperties jpaProperties) {
        val dataSourceName = jpaProperties.getDataSourceName();

        if (StringUtils.isNotBlank(dataSourceName)) {
            try {
                val dsLookup = new JndiDataSourceLookup();
                dsLookup.setResourceRef(false);
                val containerDataSource = dsLookup.getDataSource(dataSourceName);
                return new DefaultCloseableDataSource(containerDataSource);
            } catch (final DataSourceLookupFailureException e) {
                LOGGER.warn("Lookup of datasource [{}] failed due to [{}]. Back to JPA properties.", dataSourceName, e.getMessage());
            }
        }

        val bean = new HikariDataSource();
        FunctionUtils.doIfNotBlank(jpaProperties.getDriverClass(), __ -> bean.setDriverClassName(jpaProperties.getDriverClass()));

        val url = SpringExpressionLanguageValueResolver.getInstance().resolve(jpaProperties.getUrl());
        bean.setJdbcUrl(url);
        bean.setUsername(jpaProperties.getUser());
        bean.setPassword(jpaProperties.getPassword());

        val poolSettings = jpaProperties.getPool();
        FunctionUtils.doUnchecked(__ -> bean.setLoginTimeout((int) Beans.newDuration(poolSettings.getMaxWait()).toSeconds()));
        bean.setMaximumPoolSize(poolSettings.getMaxSize());
        bean.setMinimumIdle(poolSettings.getMinSize());
        bean.setIdleTimeout(Beans.newDuration(jpaProperties.getIdleTimeout()).toMillis());
        bean.setLeakDetectionThreshold(Beans.newDuration(jpaProperties.getLeakThreshold()).toMillis());
        bean.setInitializationFailTimeout(jpaProperties.getFailFastTimeout());
        bean.setIsolateInternalQueries(jpaProperties.isIsolateInternalQueries());
        bean.setConnectionTestQuery(jpaProperties.getHealthQuery());
        bean.setAllowPoolSuspension(poolSettings.isSuspension());
        bean.setAutoCommit(jpaProperties.isAutocommit());
        bean.setValidationTimeout(poolSettings.getTimeoutMillis());
        bean.setReadOnly(jpaProperties.isReadOnly());
        bean.setPoolName(StringUtils.defaultIfBlank(poolSettings.getName(), UUID.randomUUID().toString()));
        bean.setKeepaliveTime(Beans.newDuration(poolSettings.getKeepAliveTime()).toMillis());
        bean.setMaxLifetime(Beans.newDuration(poolSettings.getMaximumLifetime()).toMillis());
        bean.setSchema(jpaProperties.getDefaultSchema());
        bean.setConnectionTimeout(Beans.newDuration(jpaProperties.getConnectionTimeout()).toMillis());

        val dataSourceProperties = new Properties();
        dataSourceProperties.putAll(jpaProperties.getProperties());
        bean.setDataSourceProperties(dataSourceProperties);
        
        return new DefaultCloseableDataSource(bean);
    }
Get new data source, from JNDI lookup or created via direct configuration
of Hikari pool.
<p>
If properties specify a data source name, a lookup will be
attempted. If the DataSource is not found via JNDI then CAS will attempt to
configure a Hikari connection pool.
<p>
Since the datasource beans are {@link org.springframework.cloud.context.config.annotation.RefreshScope},
they will be a proxied by Spring
and on some application servers there have been classloading issues. A workaround
for this is to use activate data source proxying via settings and then the dataSource will be
wrapped in an application level class. If that is an issue, don't do it.
<p>
If user wants to do lookup as resource, they may include {@code java:/comp/env}
in {@code dataSourceName} and put resource reference in web.xml
otherwise {@code dataSourceName} is used as JNDI name.

@param jpaProperties the jpa properties
@return the data source
support/cas-server-support-jpa-util/src/main/java/org/apereo/cas/configuration/support/JpaBeans.java