JHipster H2 DB Non-admin User

喜夏-厌秋 提交于 2021-02-11 12:33:39

问题


I am trying to run my spring-boot/liquibase/H2 database with a non-admin user and am having some problems understanding how to do this.

First off, I have seen some information here and tried to set up my application.yml this way.

datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:h2:mem:test
    username: USERLIMITED
    password: user_limited_password
liquibase:
    contexts: dev, faker
    user: THELIQUIBASEUSER
    password: THELIQUIBASEPASSWORD

Also put these sql statements in the changelog to run so that the user I want is created and given proper access controls:

<sql>DROP USER IF EXISTS USERLIMITED</sql>
<sql>CREATE USER USERLIMITED PASSWORD 'user_limited_password'</sql>
<sql>GRANT ALL ON APP TO USERLIMITED</sql>

When trying to start up the app, I get the following error:

2020-10-21 14:41:18.532 DEBUG 8704 --- [  restartedMain] c.c.config.LiquibaseConfiguration        : Configuring Liquibase
2020-10-21 14:41:18.617  WARN 8704 --- [    test-task-1] i.g.j.c.liquibase.AsyncSpringLiquibase   : Starting Liquibase asynchronously, your database might not be
ready at startup!
2020-10-21 14:41:20.226 ERROR 8704 --- [  restartedMain] com.zaxxer.hikari.pool.HikariPool        : Hikari - Exception during pool initialization.

org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-200]

What is interesting is if I change the LiquibaseConfiguration file to use synchronous DB configuration vs. the async by default I do not get an error.

// If you don't want Liquibase to start asynchronously, substitute by this:
SpringLiquibase liquibase = SpringLiquibaseUtil.createSpringLiquibase(liquibaseDataSource.getIfAvailable(), liquibaseProperties, dataSource.getIfUnique(), dataSourceProperties);
// SpringLiquibase liquibase = SpringLiquibaseUtil.createAsyncSpringLiquibase(this.env, executor, liquibaseDataSource.getIfAvailable(), liquibaseProperties, dataSource.getIfUnique(), dataSourceProperties);

Then if I go to the H2 console and perform a query to see my users I only have the one admin user (which should be a non-admin).

Trying to log in as the liquibase user that I set up in the yml

    user: THELIQUIBASEUSER
    password: THELIQUIBASEPASSWORD

is not there and I get the Wrong user name or password [28000-200] error.

This leads me to believe that it is something with how the application starts up and asynchronous task execution priority.

Any help is very much appreciated!

来源:https://stackoverflow.com/questions/64472287/jhipster-h2-db-non-admin-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!