Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore unknown json properties from newer Keycloak versions #1266

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added
- Publish charts with github pages [#941](https://github.com/adorsys/keycloak-config-cli/issues/941)
- Support for Keycloak 26.1
- Ignore unknown json properties from newer Keycloak versions [#1265](https://github.com/adorsys/keycloak-config-cli/issues/1265)

### Fixed
- Fix Initial Credentials Causes Update [819](https://github.com/adorsys/keycloak-config-cli/issues/819)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package de.adorsys.keycloak.config.provider;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.adorsys.keycloak.config.exception.KeycloakProviderException;
import de.adorsys.keycloak.config.properties.KeycloakConfigProperties;
import de.adorsys.keycloak.config.util.ResteasyUtil;
Expand All @@ -28,6 +30,7 @@
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.jboss.resteasy.client.jaxrs.internal.BasicAuthentication;
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.slf4j.Logger;
Expand All @@ -44,6 +47,7 @@
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Form;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

/**
Expand Down Expand Up @@ -76,6 +80,7 @@ private KeycloakProvider(KeycloakConfigProperties properties) {
public Keycloak getInstance() {
if (keycloak == null || resteasyClient == null || keycloak.isClosed() || resteasyClient.isClosed()) {
resteasyClient = resteasyClientSupplier.get();
resteasyClient.register(JacksonProvider.class);
keycloak = createKeycloak();

checkServerVersion();
Expand Down Expand Up @@ -233,4 +238,20 @@ private void logout() {
public boolean isClosed() {
return keycloak == null || keycloak.isClosed();
}

/*
Similar to
https://github.com/keycloak/keycloak-client/blob/0ca751f23022c9295f2e7dc9fa72725e4380f4ed/admin-client/src/main/java/org/keycloak/admin/client/JacksonProvider.java
but without objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL).
JsonInclude.Include.NON_NULL will cause errors with some unit tests
in ImportClientsIT.
*/
public static class JacksonProvider extends ResteasyJackson2Provider {

public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) {
ObjectMapper objectMapper = super.locateMapper(type, mediaType);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper;
}
}
}
Loading