Repository: quarkusio/quarkus
Issue: Keycloak - path cache is not working

Get the latest version of [Quarkus Keycloack Authorization Example](https://github.com/quarkusio/quarkus-quickstarts/tree/master/security-keycloak-authorization-quickstart)

Start the sample:
`mvn compile quarkus:dev`

It works fine. Now terminate the application.

Now open the `application.properties` file and add the following line:
`quarkus.keycloak.policy-enforcer.path-cache.lifespan=3600000`

Start the application again and after a while you will see this exception:
```
2020-04-08 09:46:48,962 ERROR [io.qua.dev.DevModeMain] (main) Failed to start Quarkus: java.lang.RuntimeException: java.lang.ClassCastException: class io.quarkus.keycloak.pep.runtime.KeycloakPolicyEnforcerConfig$KeycloakConfigPolicyEnforcer cannot be cast to class java.util.Optional (io.quarkus.keycloak.pep.runtime.KeycloakPolicyEnforcerConfig$KeycloakConfigPolicyEnforcer is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @236fdf; java.util.Optional is in module java.base of loader 'bootstrap')
	at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:206)
	at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:95)
	at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:45)
	at io.quarkus.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:59)
	at io.quarkus.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:236)
	at io.quarkus.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:39)
	at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:131)
	at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:84)
	at io.quarkus.dev.DevModeMain.start(DevModeMain.java:113)
	at io.quarkus.dev.DevModeMain.main(DevModeMain.java:54)
Caused by: java.lang.ClassCastException: class io.quarkus.keycloak.pep.runtime.KeycloakPolicyEnforcerConfig$KeycloakConfigPolicyEnforcer cannot be cast to class java.util.Optional (io.quarkus.keycloak.pep.runtime.KeycloakPolicyEnforcerConfig$KeycloakConfigPolicyEnforcer is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @236fdf; java.util.Optional is in module java.base of loader 'bootstrap')
	at io.quarkus.deployment.configuration.BuildTimeConfigurationReader$ReadOperation.getGroup(BuildTimeConfigurationReader.java:421)
	at io.quarkus.deployment.configuration.BuildTimeConfigurationReader$ReadOperation.getGroup(BuildTimeConfigurationReader.java:412)
	at io.quarkus.deployment.configuration.BuildTimeConfigurationReader$ReadOperation.run(BuildTimeConfigurationReader.java:321)
	at io.quarkus.deployment.configuration.BuildTimeConfigurationReader.readConfiguration(BuildTimeConfigurationReader.java:241)
	at io.quarkus.deployment.ExtensionLoader.loadStepsFrom(ExtensionLoader.java:204)
	at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:90)
	at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:204)
	... 9 more
```
Seems that the problem is caused from the init of the following Optional class member:
`io.quarkus.keycloak.pep.runtime.KeycloakPolicyEnforcerConfig.KeycloakConfigPolicyEnforcer#pathCache`


Changed files:
extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerConfig.java
extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerAuthorizer.java

diff --git a/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerAuthorizer.java b/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerAuthorizer.java
index 9d5c81da478..ded80eccef3 100644
--- a/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerAuthorizer.java
+++ b/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerAuthorizer.java
@@ -150,16 +150,12 @@ private PolicyEnforcerConfig getPolicyEnforcerConfig(KeycloakPolicyEnforcerConfi
                     PolicyEnforcerConfig.EnforcementMode.valueOf(config.policyEnforcer.enforcementMode));
             enforcerConfig.setHttpMethodAsScope(config.policyEnforcer.httpMethodAsScope);
 
-            Optional<KeycloakPolicyEnforcerConfig.KeycloakConfigPolicyEnforcer.PathCacheConfig> pathCache = config.policyEnforcer.pathCache;
+            KeycloakPolicyEnforcerConfig.KeycloakConfigPolicyEnforcer.PathCacheConfig pathCache = config.policyEnforcer.pathCache;
 
-            if (pathCache.isPresent()) {
-                PolicyEnforcerConfig.PathCacheConfig pathCacheConfig = new PolicyEnforcerConfig.PathCacheConfig();
-
-                pathCacheConfig.setLifespan(pathCache.get().lifespan);
-                pathCacheConfig.setMaxEntries(pathCache.get().maxEntries);
-
-                enforcerConfig.setPathCacheConfig(pathCacheConfig);
-            }
+            PolicyEnforcerConfig.PathCacheConfig pathCacheConfig = new PolicyEnforcerConfig.PathCacheConfig();
+            pathCacheConfig.setLifespan(pathCache.lifespan);
+            pathCacheConfig.setMaxEntries(pathCache.maxEntries);
+            enforcerConfig.setPathCacheConfig(pathCacheConfig);
 
             enforcerConfig.setClaimInformationPointConfig(
                     getClaimInformationPointConfig(config.policyEnforcer.claimInformationPoint));
diff --git a/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerConfig.java b/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerConfig.java
index 939d5184992..1c16ed8890a 100644
--- a/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerConfig.java
+++ b/extensions/keycloak-authorization/runtime/src/main/java/io/quarkus/keycloak/pep/runtime/KeycloakPolicyEnforcerConfig.java
@@ -56,7 +56,7 @@ public static class KeycloakConfigPolicyEnforcer {
          * protected resources
          */
         @ConfigItem
-        public Optional<PathCacheConfig> pathCache;
+        public PathCacheConfig pathCache = new PathCacheConfig();
 
         /**
          * Specifies how the adapter should fetch the server for resources associated with paths in your application. If true,