Skip to content

Commit

Permalink
fix:(jans-auth-server): fixed Client serialization/deserialization is…
Browse files Browse the repository at this point in the history
…sue #2946 (#3064)

* fix:(jans-auth-server): fixed Client serialization/deserialization bug #2946

* fix:(jans-auth-server): fixed Client serialization/deserialization bug #2946
  • Loading branch information
yuriyz authored Nov 23, 2022
1 parent 012a29e commit 31b5bfc
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

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 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 @@ -28,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 @@ -600,6 +602,7 @@ public void setIdTokenTokenBindingCnf(String idTokenTokenBindingCnf) {
this.idTokenTokenBindingCnf = idTokenTokenBindingCnf;
}

@JsonIgnore
public boolean isTokenBindingSupported() {
return StringUtils.isNotBlank(idTokenTokenBindingCnf);
}
Expand Down Expand Up @@ -707,11 +710,37 @@ 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;
}

/**
* 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);
Expand All @@ -723,6 +752,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);
Expand All @@ -745,6 +775,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);
Expand All @@ -756,6 +787,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);
Expand All @@ -778,6 +810,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);
Expand All @@ -789,6 +822,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);
Expand All @@ -813,6 +847,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);
Expand All @@ -825,6 +860,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);
Expand All @@ -849,6 +885,7 @@ public LocalizedString getTosUriLocalized() {
*
* @param tosUri The terms of service URL.
*/
@JsonIgnore
public void setTosUriLocalized(String tosUri) {
this.tosUri = tosUri;
this.tosUriLocalized.setValue(tosUri);
Expand All @@ -861,6 +898,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);
Expand Down Expand Up @@ -1421,14 +1459,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;
}
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 31b5bfc

Please sign in to comment.