Skip to content

Commit

Permalink
fix:(jans-auth-server): fixed Client serialization/deserialization bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyz committed Nov 23, 2022
1 parent b58339a commit ce2dfcd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +23,7 @@ public class LocalizedString implements Serializable {

private static final long serialVersionUID = -7651487701235873969L;

private final Map<String, String> values;
private Map<String, String> values;

public static final String EMPTY_LANG_TAG = "";
public static final String LANG_SEPARATOR = ";";
Expand All @@ -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<String, String> getValues() {
return values;
}

public void setValues(Map<String, String> values) {
this.values = values;
}

public int size() {
return values.size();
}

@JsonIgnore
public Set<String> getLanguageTags() {
return values.keySet();
}
Expand All @@ -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<String> keyParts = new ArrayList<>();
keyParts.add(locale.getLanguage());
keyParts.add(locale.getScript());
Expand Down

0 comments on commit ce2dfcd

Please sign in to comment.