quarkusio / quarkus-quickstarts

Quarkus quickstart code
https://quarkus.io
Apache License 2.0
1.95k stars 1.46k forks source link

Quarkus test fails in security-keycloak-authorization-quickstart tutorial when using own keycloak Realm init scripts ! #1058

Open hhutzler opened 2 years ago

hhutzler commented 2 years ago

Error: Script upload is disabled

Working Scenario In the security-keycloak-authorization-quickstart tutorial the quarkus realm gets loaded sucessfully by script quarkus-realm.json Application.properties entry: quarkus.keycloak.devservices.realm-path=quarkus-realm.json

In this script the keycloal versions is set to 6.0.0 ! $ grep -i version quarkus-realm.json "keycloakVersion" : "6.0.0",

Related Keycloak logs

13:40:55,999 INFO [org.keycloak.services] (ServerService Thread Pool -- 70) KC-SE 13:40:59,489 WARN [org.keycloak.models.utils.RepresentationToModel] (ServerService Thread Pool -- 70) Using deprecated 'credentials' format in JSON representation for user 'admin'. It will be removed in future versions 13:40:59,584 WARN [org.keycloak.models.utils.RepresentationToModel] (ServerService Thread Pool -- 70) Using deprecated 'credentials' format in JSON representation for user 'alice'. It will be removed in future versions 13:40:59,596 WARN [org.keycloak.models.utils.RepresentationToModel] (ServerService Thread Pool -- 70) Using deprecated 'credentials' format in JSON representation for user 'jdoe'. It will be removed in future versions 13:41:00,117 INFO [org.keycloak.services] (ServerService Thread Pool -- 70) KC-SERVICES0004: Imported realm quarkus from file /tmp/realm.json.

Run test
$ mvn clean test INFO] Results: [INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0

As we have already finished our Authorization Setup running on Keycloak 15.0.2 we exported that Realm to file RBAC-realm.json. Changing Application.properties entry: quarkus.keycloak.devservices.realm-path=RBAC-realm.json $ grep -i version RBAC-realm.json "keycloakVersion" : "15.0.2", After restarting Quarkus the keycloak import fails 3:49:38,909 INFO [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (ServerService Thread Pool -- 58) HHH000397: Using ASTQueryTranslatorFactory 13:49:39,443 INFO [org.keycloak.services] (ServerService Thread Pool -- 58) KC-SERVICES0050: Initializing master realm 13:49:43,407 WARN [org.keycloak.services] (ServerService Thread Pool -- 58) KC-SERVICES0005: Unable to import realm RBAC from file /tmp/realm.json.: java.lang.RuntimeException: Script upload is disabled at org.keycloak.keycloak-authz-policy-common@15.0.2//org.keycloak.authorization.policy.provider.js.JSPolicyProviderFactory.updatePolicy(JSPolicyProviderFactory.java:125) at org.keycloak.keycloak-authz-policy-common@15.0.2//org.keycloak.authorization.policy.provider.js.JSPolicyProviderFactory.onImport(JSPolicyProviderFactory.java:70) Of course all test fails because our Realm was not imported

Changing keycloakVersion to 6.0.0 in RBAC-realm.json did not help. This problem may be reated to the fact that Importing realm with script upload is disabled since keycloak 7.

Anyway is there an easy way to use quarkus test framework with our own import files ?

sberyozkin commented 2 years ago

@hhutzler Apologies, I've totally missed this issue. Have you had any progress since ? Indeed, as far as importing scripts is concerned, it will definitely not work with 18.0.0: https://www.keycloak.org/docs/latest/release_notes/index.html#the-deprecated-code-upload-script-code-feature-was-removed. Please see what the Keycloak team recommends