From b58339a4efe0faeb1ea910a5e8cec6174c79343b Mon Sep 17 00:00:00 2001 From: YuriyZ Date: Wed, 23 Nov 2022 14:03:37 +0200 Subject: [PATCH 1/2] fix:(jans-auth-server): fixed Client serialization/deserialization bug #2946 --- .../as/common/model/registration/Client.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java b/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java index 56b1b8cab81..8b635c92e68 100644 --- a/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java +++ b/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java @@ -6,6 +6,7 @@ package io.jans.as.common.model.registration; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import io.jans.as.model.common.*; @@ -600,6 +601,7 @@ public void setIdTokenTokenBindingCnf(String idTokenTokenBindingCnf) { this.idTokenTokenBindingCnf = idTokenTokenBindingCnf; } + @JsonIgnore public boolean isTokenBindingSupported() { return StringUtils.isNotBlank(idTokenTokenBindingCnf); } @@ -707,11 +709,32 @@ public LocalizedString getClientNameLocalized() { return clientNameLocalized; } + public void setClientNameLocalized(LocalizedString clientNameLocalized) { + this.clientNameLocalized = clientNameLocalized; + } + + public void setLogoUriLocalized(LocalizedString logoUriLocalized) { + this.logoUriLocalized = logoUriLocalized; + } + + public void setClientUriLocalized(LocalizedString clientUriLocalized) { + this.clientUriLocalized = clientUriLocalized; + } + + public void setPolicyUriLocalized(LocalizedString policyUriLocalized) { + this.policyUriLocalized = policyUriLocalized; + } + + public void setTosUriLocalized(LocalizedString tosUriLocalized) { + this.tosUriLocalized = tosUriLocalized; + } + /** * Sets the name of the Client to be presented to the user. * * @param clientName The name of the Client to be presented to the user. */ + @JsonIgnore public void setClientNameLocalized(String clientName) { this.clientName = clientName; this.clientNameLocalized.setValue(clientName); @@ -723,6 +746,7 @@ public void setClientNameLocalized(String clientName) { * @param clientName The name of the Client to be presented to the user. * @param locale The locale */ + @JsonIgnore public void setClientNameLocalized(String clientName, Locale locale) { if (StringUtils.isNotBlank(locale.toString())) { this.clientNameLocalized.setValue(clientName, locale); @@ -745,6 +769,7 @@ public LocalizedString getLogoUriLocalized() { * * @param logoUri The URL of a logo image for the Client where it can be retrieved. */ + @JsonIgnore public void setLogoUriLocalized(String logoUri) { this.logoUri = logoUri; this.logoUriLocalized.setValue(logoUri); @@ -756,6 +781,7 @@ public void setLogoUriLocalized(String logoUri) { * @param logoUri The URL of a logo image for the Client where it can be retrieved. * @param locale The locale */ + @JsonIgnore public void setLogoUriLocalized(String logoUri, Locale locale) { if (StringUtils.isNotBlank(locale.toString())) { this.logoUriLocalized.setValue(logoUri, locale); @@ -778,6 +804,7 @@ public LocalizedString getClientUriLocalized() { * * @param clientUri The URL of the home page of the Client. */ + @JsonIgnore public void setClientUriLocalized(String clientUri) { this.clientUri = clientUri; this.clientUriLocalized.setValue(clientUri); @@ -789,6 +816,7 @@ public void setClientUriLocalized(String clientUri) { * @param clientUri The URL of the home page of the Client. * @param locale The locale */ + @JsonIgnore public void setClientUriLocalized(String clientUri, Locale locale) { if (StringUtils.isNotBlank(locale.toString())) { this.clientUriLocalized.setValue(clientUri, locale); @@ -813,6 +841,7 @@ public LocalizedString getPolicyUriLocalized() { * * @param policyUri A URL location about how the profile data will be used. */ + @JsonIgnore public void setPolicyUriLocalized(String policyUri) { this.policyUri = policyUri; this.policyUriLocalized.setValue(policyUri); @@ -825,6 +854,7 @@ public void setPolicyUriLocalized(String policyUri) { * @param policyUri A URL location about how the profile data will be used. * @param locale The locale */ + @JsonIgnore public void setPolicyUriLocalized(String policyUri, Locale locale) { if (StringUtils.isNotBlank(locale.toString())) { this.policyUriLocalized.setValue(policyUri, locale); @@ -849,6 +879,7 @@ public LocalizedString getTosUriLocalized() { * * @param tosUri The terms of service URL. */ + @JsonIgnore public void setTosUriLocalized(String tosUri) { this.tosUri = tosUri; this.tosUriLocalized.setValue(tosUri); @@ -861,6 +892,7 @@ public void setTosUriLocalized(String tosUri) { * @param tosUri The terms of service URL. * @param locale The Locale */ + @JsonIgnore public void setTosUriLocalized(String tosUri, Locale locale) { if (StringUtils.isNotBlank(locale.toString())) { this.tosUriLocalized.setValue(tosUri, locale); @@ -1421,14 +1453,6 @@ public void setBackchannelUserCodeParameter(Boolean backchannelUserCodeParameter this.backchannelUserCodeParameter = backchannelUserCodeParameter; } - public String getDisplayName() { - return getClientName(); - } - - public void setDisplayName(String displayName) { - setClientName(displayName); - } - public String getDescription() { return description; } From ce2dfcd502bf76f4f803f0276d91b2725b3df766 Mon Sep 17 00:00:00 2001 From: YuriyZ Date: Wed, 23 Nov 2022 15:02:02 +0200 Subject: [PATCH 2/2] fix:(jans-auth-server): fixed Client serialization/deserialization bug #2946 --- .../as/common/model/registration/Client.java | 8 +++- .../registration/ClientSerializationTest.java | 38 +++++++++++++++++++ .../jans/orm/model/base/LocalizedString.java | 20 ++++++++-- 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 jans-auth-server/common/src/test/java/io/jans/as/common/model/registration/ClientSerializationTest.java diff --git a/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java b/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java index 8b635c92e68..cc61be694d3 100644 --- a/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java +++ b/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; import io.jans.as.model.common.*; import io.jans.as.model.crypto.signature.AsymmetricSignatureAlgorithm; import io.jans.as.model.register.ApplicationType; @@ -29,7 +30,7 @@ * @author Javier Rojas Blum * @version October 17, 2022 */ -@DataEntry(sortBy = {"displayName"}) +@DataEntry(sortBy = {"clientName"}) @ObjectClass(value = "jansClnt") @JsonInclude(JsonInclude.Include.NON_NULL) public class Client extends DeletableEntity implements Serializable { @@ -709,22 +710,27 @@ public LocalizedString getClientNameLocalized() { return clientNameLocalized; } + @JsonSetter public void setClientNameLocalized(LocalizedString clientNameLocalized) { this.clientNameLocalized = clientNameLocalized; } + @JsonSetter public void setLogoUriLocalized(LocalizedString logoUriLocalized) { this.logoUriLocalized = logoUriLocalized; } + @JsonSetter public void setClientUriLocalized(LocalizedString clientUriLocalized) { this.clientUriLocalized = clientUriLocalized; } + @JsonSetter public void setPolicyUriLocalized(LocalizedString policyUriLocalized) { this.policyUriLocalized = policyUriLocalized; } + @JsonSetter public void setTosUriLocalized(LocalizedString tosUriLocalized) { this.tosUriLocalized = tosUriLocalized; } diff --git a/jans-auth-server/common/src/test/java/io/jans/as/common/model/registration/ClientSerializationTest.java b/jans-auth-server/common/src/test/java/io/jans/as/common/model/registration/ClientSerializationTest.java new file mode 100644 index 00000000000..4ad3198493e --- /dev/null +++ b/jans-auth-server/common/src/test/java/io/jans/as/common/model/registration/ClientSerializationTest.java @@ -0,0 +1,38 @@ +package io.jans.as.common.model.registration; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.jans.as.model.util.Util; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.Locale; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; + +/** + * @author Yuriy Zabrovarnyy + */ +public class ClientSerializationTest { + + @Test + public void deserialization_whenSerialized_shouldGetCorrectValues() throws IOException { + Client c = new Client(); + c.setClientName("name"); + c.setClientNameLocalized("myLocalized"); + c.setClientNameLocalized("myLocalized_canada", Locale.CANADA); + c.setClientNameLocalized("myLocalized_canadaFR", Locale.CANADA_FRENCH); + + final ObjectMapper mapper = Util.createJsonMapper(); + mapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_EMPTY); + final String asJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(c); + + final Client client = mapper.readValue(asJson, Client.class); + assertNotNull(client); + assertEquals("myLocalized", client.getClientName()); + assertEquals("myLocalized", client.getClientNameLocalized().getValue()); + assertEquals("myLocalized_canada", client.getClientNameLocalized().getValue(Locale.CANADA)); + assertEquals("myLocalized_canadaFR", client.getClientNameLocalized().getValue(Locale.CANADA_FRENCH)); + } +} diff --git a/jans-orm/model/src/main/java/io/jans/orm/model/base/LocalizedString.java b/jans-orm/model/src/main/java/io/jans/orm/model/base/LocalizedString.java index 4b5e3a87da1..54c5e564078 100644 --- a/jans-orm/model/src/main/java/io/jans/orm/model/base/LocalizedString.java +++ b/jans-orm/model/src/main/java/io/jans/orm/model/base/LocalizedString.java @@ -6,11 +6,10 @@ package io.jans.orm.model.base; +import com.fasterxml.jackson.annotation.JsonIgnore; import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; -import io.jans.orm.util.StringHelper; - import java.io.Serializable; import java.util.*; import java.util.function.BiFunction; @@ -24,7 +23,7 @@ public class LocalizedString implements Serializable { private static final long serialVersionUID = -7651487701235873969L; - private final Map values; + private Map values; public static final String EMPTY_LANG_TAG = ""; public static final String LANG_SEPARATOR = ";"; @@ -46,22 +45,34 @@ public void setValue(String value, Locale locale) { values.put(getLanguageTag(locale), value); } + @JsonIgnore public String getValue() { return getValue(EMPTY_LANG_TAG); } + @JsonIgnore public String getValue(String languageTag) { return values.getOrDefault(languageTag, null); } + @JsonIgnore + public String getValue(Locale locale) { + return getValue(getLanguageTag(locale)); + } + public Map getValues() { return values; } + public void setValues(Map values) { + this.values = values; + } + public int size() { return values.size(); } + @JsonIgnore public Set getLanguageTags() { return values.keySet(); } @@ -76,7 +87,8 @@ public String removeLdapLanguageTag(String value, String ldapAttributeName) { .replace(LANG_SEPARATOR + LANG_PREFIX + LANG_JOINER, ""); } - private String getLanguageTag(Locale locale) { + @JsonIgnore + public static String getLanguageTag(Locale locale) { List keyParts = new ArrayList<>(); keyParts.add(locale.getLanguage()); keyParts.add(locale.getScript());