Search code examples
keycloakkeycloak-serviceskeycloak-rest-api

Keycloak 20.0.3 : Unrecognized field "otpPolicyCodeReusable"


Try to update realResource with RealmRepresentation but when

 RealmRepresentation realmRepresentation = realmResource.toRepresentation();

I get

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "otpPolicyCodeReusable" (class org.keycloak.representations.idm.RealmRepresentation), not marked as ignorable (135 known properties: "userFederationMappers", "rememberMe", "duplicateEmailsAllowed", "adminEventsDetailsEnabled", "users", "clientOfflineSessionMaxLifespan", "webAuthnPolicyRequireResidentKey", "webAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister", "components", "otpPolicyType", "accessCodeLifespanUserAction", "id", "webAuthnPolicyAttestationConveyancePreference", "enabledEventTypes", "applications", "webAuthnPolicyPasswordlessSignatureAlgorithms", "eventsListeners", "ssoSessionMaxLifespanRememberMe", "defaultDefaultClientScopes", "webAuthnPolicyPasswordlessCreateTimeout", "clientOfflineSessionIdleTimeout", "notBefore", "publicKey", "smtpServer", "clientPolicies", "resetPasswordAllowed", "webAuthnPolicyAvoidSameAuthenticatorRegister", "accessTokenLifespanForImplicitFlow", "webAuthnPolicyPasswordlessUserVerificationRequirement", "clientScopes", "internationalizationEnabled", "defaultRole", "accessTokenLifespan", "passwordCredentialGrantAllowed", "federatedUsers", "applicationScopeMappings" [truncated]])
at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 1, column: 1870] (through reference chain: org.keycloak.representations.idm.RealmRepresentation["otpPolicyCodeReusable"])
   at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
   at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:1127)
   at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:2023)
   at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1700)
   at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1678)
   at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:319)
   at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:176)
   at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
   at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:2025)
   at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1175)
   at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.readFrom(ResteasyJackson2Provider.java:193)
   at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:101)
   at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:80)
   at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:217)
   ... 136 more 

I'm using Keycloak Server 20.0.3 and Keycloak Admin REST Client 20.0.3 same version.


Solution

  • I ran into the same issue with the otpPolicyCodeReusable field being unrecognised when attempting to import a realm into Keycloak version 18. From looking at the Keycloak documentation for version 18, it appears that the otpPolicyCodeReusable field has been either deprecated or removed.

    My solution was to simply remove that field from the realm resource, which was, in my case, a JSON file, and rerun the import. In your case, it looks like the realm resource is a Java object called realmResource. I am assuming that the otpPolicyCodeReusable field is also deprecated or removed in Keycloak version 20, in which case you would probably be able to just remove that field from the realmResource object and re-run your code.