2017-08-29 85 views
2

我正在使用https://github.com/thomasdarimont/spring-boot-keycloak-server-example來運行keycloak實例。我試圖從H2切換到PostgreSQL,會出現管理員帳戶創建屏幕,但在創建初始管理員帳戶失敗:Keycloak/Liquibase:錯誤:列「salt」的類型爲oid,但表達式的類型爲bytea

Hibernate: 
insert 
into 
    CREDENTIAL 
    (ALGORITHM, COUNTER, CREATED_DATE, DEVICE, DIGITS, HASH_ITERATIONS, PERIOD, SALT, TYPE, USER_ID, VALUE, ID) 
values 
    (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [1] as [VARCHAR] - [pbkdf2-sha256] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [2] as [INTEGER] - [0] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [3] as [BIGINT] - [1504025461373] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [4] as [VARCHAR] - [null] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [5] as [INTEGER] - [0] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [6] as [INTEGER] - [27500] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [7] as [INTEGER] - [0] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [8] as [VARBINARY] - [[[email protected]] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [9] as [VARCHAR] - [password] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [10] as [VARCHAR] - [32e0eb33-091b-4791-a923-4cc9fc976371] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [11] as [VARCHAR] - [CBJ4e+h56g1I0uxyexae7p5xJ2xLILGh8Hkx4t/jGSZ74XHbqDmGLW2vfPyIUl17puB+hihu3OpwNJSjT+LRgw==] 
2017-08-29 18:51:01.482 TRACE 7020 --- [io-20909-exec-2] o.h.type.descriptor.sql.BasicBinder  : binding parameter [12] as [VARCHAR] - [738017b1-ff7b-47cf-a2e9-7c9f6055f0aa] 
2017-08-29 18:51:01.498 WARN 7020 --- [io-20909-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 42804 
2017-08-29 18:51:01.498 ERROR 7020 --- [io-20909-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: column "salt" is of type oid but expression is of type bytea 
Hint: You will need to rewrite or cast the expression. 
Position: 168 

我已經適應如下的keycloak-server.json的connectionsJpa設置:

"connectionsJpa": { 
    "provider": "default", 
    "default": { 
     "url": "${env.KEYCLOAK_DATABASE_URL:jdbc:postgresql://server/testdb}", 
     "driver": "${keycloak.connectionsJpa.driver:org.postgresql.Driver}", 
     "driverDialect": "${keycloak.connectionsJpa.driverDialect:org.hibernate.dialect.PostgreSQLDialect}", 
     "user": "${keycloak.connectionsJpa.user:user}", 
     "password": "${keycloak.connectionsJpa.password:password}", 
     "initializeEmpty": true, 
     "migrationStrategy": "update", 
     "showSql": "${keycloak.connectionsJpa.showSql:true}", 
     "formatSql": "${keycloak.connectionsJpa.formatSql:true}", 
     "globalStatsInterval": "${keycloak.connectionsJpa.globalStatsInterval:-1}" 
    } 
}, 

看來,自Liquibase 3.5.2以來,blob類型生成PostgreSQL類型的oid,而不是bytea了。請參閱CORE-1863

任何有解決方案的人?

+0

我在此期間創建了https://issues.jboss.org/browse/KEYCLOAK-5396。 – Bernd

回答

1

問題似乎是,Liquibase 3.5.2或更高版本將導致public.credential.salt列使用oid類型創建,而Keycloak期望它是bytea。

解決方案是恢復到早期版本的Liquibase(我推薦3.4.1,因爲這是Keycloak通常使用的版本)。您可以通過在項目的主pom.xml中

<properties> 
    ...... 
    <liquibase.version>3.4.1</liquibase.version> 
</properties> 

添加liquibase版本的版本屬性在此之後不要忘記刪除舊Keycloak數據庫,以便Keycloak可以用適當的鹽類型時創建它這樣做你重新開始。

+0

真棒,工作。非常感謝! – Bernd

相關問題