dasniko / quarkus-keycloak

Demos on how to secure a Quarkus service/app with proper Keycloak authentication & doing tests with Testcontainers-Keycloak project.
MIT License
19 stars 6 forks source link

Java startup error on KeycloakPolicyEnforcerRecorder optional get #1

Open Melchiorj opened 2 years ago

Melchiorj commented 2 years ago

Describe the bug

On maven start of quarkus:dev keycloak fails to start while attempting fetching information from an optional when building the keycloak policy enforcer (as per the log)

Expected Behaviour

Quarkus dev should start

Actual Behaviour

Listening for transport dt_socket at address: 5005
2022-05-13 09:13:33,828 WARN  [io.qua.kaf.cli.dep.DevServicesKafkaProcessor] (build-5) Docker isn't working, please configure the Kafka bootstrap servers property (kafka.bootstrap.servers).
2022-05-13 09:13:35,678 INFO  [org.kie.kog.cod.api.uti.AddonsConfigDiscovery] (build-67) Performed addonsConfig discovery, found: AddonsConfig{usePersistence=false, useTracing=false, useMonitoring=false, usePrometheusMonitoring=false, useKnativeEventing=false, useCloudEvents=false, useExplainability=false}
2022-05-13 09:13:36,986 WARN  [io.qua.dat.dep.dev.DevServicesDatasourceProcessor] (build-5) Please configure the datasource URL for the default datasource or ensure the Docker daemon is up and running.
2022-05-13 09:13:37,193 INFO  [org.kie.kog.cod.cor.uti.ApplicationGeneratorDiscovery] (build-67) Generator discovery performed, found [openapispecs, processes, rules, decisions, predictions]
2022-05-13 09:13:42,389 WARN  [org.kie.kog.cod.pro.ProcessCodegen] (build-67) There's already a generated file named org/kie/kogito/handlers/GlPostingService_glStatusInputRequest_4_Handler.java to be compiled. Ignoring.
2022-05-13 09:13:43,374 INFO  [org.kie.kog.cod.dec.DecisionValidation] (build-67) Initializing DMN DT Validator...
2022-05-13 09:13:43,375 INFO  [org.kie.kog.cod.dec.DecisionValidation] (build-67) DMN DT Validator initialized.
2022-05-13 09:13:43,377 INFO  [org.kie.kog.cod.dec.DecisionValidation] (build-67) Analysing decision tables in DMN Model 'DisposalSelectionRule' ...
2022-05-13 09:13:43,394 INFO  [org.kie.kog.cod.dec.DecisionValidation] (build-67)  analysis for decision table 'disposalName':
2022-05-13 09:13:43,397 INFO  [org.kie.kog.cod.dec.DecisionValidation] (build-67)   Decision Table Analysis of table 'disposalName' finished with no messages to be reported.
2022-05-13 09:13:52,411 INFO  [org.kie.kog.cod.api.uti.AddonsConfigDiscovery] (build-38) Performed addonsConfig discovery, found: AddonsConfig{usePersistence=false, useTracing=false, useMonitoring=false, usePrometheusMonitoring=false, useKnativeEventing=false, useCloudEvents=false, useExplainability=false}
2022-05-13 09:13:52,418 INFO  [org.kie.kog.qua.com.dep.KogitoQuarkusResourceUtils] (build-38) No Java source to compile
2022-05-13 09:13:52,649 WARN  [io.qua.resteasy] (build-82) Detected RESTEasy annotation org.jboss.resteasy.annotations.jaxrs.PathParam on method parameter com.cgi.afs360.rest.FairMarketValueRestService.GetLatestAssetMarketValuesByAssetRegisterNumber with no name. Either specify its name, or tell your compiler to enable debug info (-g) or parameter names (-parameters). This message is only logged for the first such parameter.
mai 13, 2022 9:14:02 DA MANHÃ io.quarkus.config
WARN: Unrecognized configuration key "%s" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
mai 13, 2022 9:14:03 DA MANHÃ org.hibernate.jpa.internal.util.LogHelper
INFO: HHH000204: Processing PersistenceUnitInfo [name: %s]
mai 13, 2022 9:14:03 DA MANHÃ org.hibernate.Version
INFO: HHH000412: Hibernate ORM core version %s
mai 13, 2022 9:14:03 DA MANHÃ org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons Annotations {%1$s}
mai 13, 2022 9:14:03 DA MANHÃ org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: %s
mai 13, 2022 9:14:03 DA MANHÃ org.hibernate.validator.internal.util.Version
INFO: HV000001: Hibernate Validator %s
mai 13, 2022 9:14:04 DA MANHÃ io.quarkus.runtime.ApplicationLifecycleManager run
ERROR: Failed to start application (with profile dev)
java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.get(Optional.java:148)
        at io.quarkus.keycloak.pep.runtime.KeycloakPolicyEnforcerRecorder.createPolicyEnforcer(KeycloakPolicyEnforcerRecorder.java:61)
        at io.quarkus.keycloak.pep.runtime.KeycloakPolicyEnforcerRecorder.setup(KeycloakPolicyEnforcerRecorder.java:31)
        at io.quarkus.deployment.steps.KeycloakPolicyEnforcerBuildStep$setup-1763533187.deploy_0(KeycloakPolicyEnforcerBuildStep$setup-1763533187.zig:119)
        at io.quarkus.deployment.steps.KeycloakPolicyEnforcerBuildStep$setup-1763533187.deploy(KeycloakPolicyEnforcerBuildStep$setup-1763533187.zig:40)
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:818)
        at io.quarkus.runtime.Application.start(Application.java:101)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:98)
        at java.base/java.lang.Thread.run(Thread.java:829)

mai 13, 2022 9:14:04 DA MANHÃ io.quarkus.deployment.dev.IsolatedDevModeMain firstStart
INFO: Attempting to start live reload endpoint to recover from previous Quarkus startup failure
mai 13, 2022 9:14:04 DA MANHÃ org.jboss.threads.Version <clinit>
INFO: JBoss Threads version %s

How to reproduce

Running mvn package -DskipTests quarkus:dev fails to start

Application Properties

# OIDC Configuration
quarkus.oidc.enabled=true
%prod.quarkus.oidc.auth-server-url=https://localhost:8543/realms/quarkus
quarkus.oidc.client-id=backend-service
quarkus.oidc.credentials.secret=secret
quarkus.oidc.tls.verification=none
quarkus.keycloak.devservices.realm-path=quarkus-realm.json
quarkus.oidc.token.issuer=any

# Enable Policy Enforcement
#quarkus.keycloak.policy-enforcer.enable=true
quarkus.keycloak.policy-enforcer.enable=true
quarkus.keycloak.policy-enforcer.lazy-load-paths=false

quarkus.keycloak.policy-enforcer.paths.health.path=/*  #api/public
quarkus.keycloak.policy-enforcer.paths.health.enforcement-mode=DISABLED

#quarkus.log.min-level=DEBUG
#quarkus.log.category."io.quarkus.oidc".level=DEBUG

Build tool - Output of mvn -v

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: C:\Program Files\apache-maven-3.8.5
Java version: 11.0.12, vendor: Red Hat, Inc., runtime: C:\Program Files\RedHat\java-11-openjdk-11.0.12-1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

GraalVM version

Not in use

Quarkus version

2.0.1 final

Melchiorj commented 2 years ago

Good morning, I've been following what information I could find on how to integrate keycloak with quarkus but I've been thus far unable to move past this step due to the problem described. Would you happen to have any idea on what's going on?

From the error log it appears as though I'm missing something in the configuration but I can't what.