p2-inc / keycloak-orgs

Single realm, multi-tenancy for SaaS apps
https://phasetwo.io
Other
417 stars 72 forks source link

Realm import not working: [org.keycloak.services.resources.admin.RealmsAdminResource] (executor-thread-1) Conflict detected: #134

Closed diazoxide closed 1 year ago

diazoxide commented 1 year ago

In my self hosted environment, when I'm trying to import my exported realm, always happening this error:

image

After disabling p2 extension import successfully done.

Logs:

2023-10-10T08:33:22.756567459Z 2023-10-10 08:33:22,755 ERROR [org.keycloak.services.resources.admin.RealmsAdminResource] (executor-thread-1) Conflict detected: org.keycloak.models.ModelDuplicateException
2023-10-10T08:33:22.756609084Z  at org.keycloak.models.jpa.JpaRealmProvider.addClientRole(JpaRealmProvider.java:254)
2023-10-10T08:33:22.756613418Z  at org.keycloak.storage.RoleStorageManager.addClientRole(RoleStorageManager.java:205)
2023-10-10T08:33:22.756615501Z  at org.keycloak.models.cache.infinispan.RealmCacheSession.addClientRole(RealmCacheSession.java:735)
2023-10-10T08:33:22.756617668Z  at org.keycloak.models.cache.infinispan.RealmCacheSession.addClientRole(RealmCacheSession.java:730)
2023-10-10T08:33:22.756619918Z  at org.keycloak.models.jpa.ClientAdapter.addRole(ClientAdapter.java:620)
2023-10-10T08:33:22.756622001Z  at io.phasetwo.keycloak.resources.EventsResourceProviderFactory.addRoles(EventsResourceProviderFactory.java:89)
2023-10-10T08:33:22.756623959Z  at io.phasetwo.keycloak.resources.EventsResourceProviderFactory.addRealmAdminRoles(EventsResourceProviderFactory.java:83)
2023-10-10T08:33:22.756626001Z  at io.phasetwo.keycloak.resources.EventsResourceProviderFactory.realmPostCreate(EventsResourceProviderFactory.java:70)
2023-10-10T08:33:22.756628126Z  at io.phasetwo.keycloak.resources.EventsResourceProviderFactory.lambda$postInit$0(EventsResourceProviderFactory.java:39)
2023-10-10T08:33:22.756630251Z  at org.keycloak.services.DefaultKeycloakSessionFactory.publish(DefaultKeycloakSessionFactory.java:91)
2023-10-10T08:33:22.756632334Z  at org.keycloak.services.managers.RealmManager.fireRealmPostCreate(RealmManager.java:733)
2023-10-10T08:33:22.756634043Z  at org.keycloak.services.managers.RealmManager.importRealm(RealmManager.java:616)
2023-10-10T08:33:22.756635793Z  at org.keycloak.services.managers.RealmManager.importRealm(RealmManager.java:504)
2023-10-10T08:33:22.756637459Z  at org.keycloak.services.managers.RealmManagerProviderFactory.lambda$postInit$0(RealmManagerProviderFactory.java:54)
2023-10-10T08:33:22.756639168Z  at org.keycloak.services.DefaultKeycloakSessionFactory.publish(DefaultKeycloakSessionFactory.java:91)
2023-10-10T08:33:22.756649959Z  at org.keycloak.storage.ImportRealmFromRepresentationEvent.fire(ImportRealmFromRepresentationEvent.java:50)
2023-10-10T08:33:22.756652626Z  at org.keycloak.storage.datastore.LegacyExportImportManager.importRealm(LegacyExportImportManager.java:160)
2023-10-10T08:33:22.756654834Z  at org.keycloak.services.resources.admin.RealmsAdminResource.importRealm(RealmsAdminResource.java:143)
2023-10-10T08:33:22.756658084Z  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2023-10-10T08:33:22.756660209Z  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
2023-10-10T08:33:22.756662251Z  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2023-10-10T08:33:22.756664459Z  at java.base/java.lang.reflect.Method.invoke(Method.java:568)
2023-10-10T08:33:22.756666626Z  at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:154)
2023-10-10T08:33:22.756668834Z  at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:118)
2023-10-10T08:33:22.756671043Z  at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:560)
2023-10-10T08:33:22.756673251Z  at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:452)
2023-10-10T08:33:22.756675251Z  at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:413)
2023-10-10T08:33:22.756677084Z  at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
2023-10-10T08:33:22.756678918Z  at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:415)
2023-10-10T08:33:22.756680709Z  at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:378)
2023-10-10T08:33:22.756682459Z  at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:174)
2023-10-10T08:33:22.756684293Z  at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:131)
2023-10-10T08:33:22.756686043Z  at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:33)
2023-10-10T08:33:22.756687834Z  at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:429)
2023-10-10T08:33:22.756689584Z  at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:240)
2023-10-10T08:33:22.756691418Z  at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:154)
2023-10-10T08:33:22.756693251Z  at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
2023-10-10T08:33:22.756695084Z  at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:157)
2023-10-10T08:33:22.756696876Z  at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:229)
2023-10-10T08:33:22.756701834Z  at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:82)
2023-10-10T08:33:22.756718293Z  at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:147)
2023-10-10T08:33:22.756720709Z  at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.handle(VertxRequestHandler.java:84)
2023-10-10T08:33:22.756723043Z  at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.handle(VertxRequestHandler.java:44)
2023-10-10T08:33:22.756725376Z  at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
2023-10-10T08:33:22.756727876Z  at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
2023-10-10T08:33:22.756730043Z  at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)
2023-10-10T08:33:22.756732334Z  at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:58)
2023-10-10T08:33:22.756734543Z  at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:36)
2023-10-10T08:33:22.756736751Z  at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
2023-10-10T08:33:22.756738876Z  at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
2023-10-10T08:33:22.756741043Z  at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)
2023-10-10T08:33:22.756743168Z  at org.keycloak.quarkus.runtime.integration.web.QuarkusRequestFilter.lambda$createBlockingHandler$0(QuarkusRequestFilter.java:82)
2023-10-10T08:33:22.756745376Z  at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
2023-10-10T08:33:22.756747543Z  at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
2023-10-10T08:33:22.756749418Z  at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
2023-10-10T08:33:22.756751168Z  at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
2023-10-10T08:33:22.756752918Z  at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
2023-10-10T08:33:22.756754709Z  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2023-10-10T08:33:22.756756501Z  at java.base/java.lang.Thread.run(Thread.java:833)
2023-10-10T08:33:22.756758209Z 
xgp commented 1 year ago

@diazoxide Can you include the realm file you are trying to import? Please clean out any sensitive information.

xgp commented 1 year ago

This is because the role in the dump file is not being checked by the postInit of other ProviderFactories. I found the one that pertains to the specific error, but there may be others. @diazoxide Let me know if you have further problems.