diff --git a/jans-auth-server/model/src/main/java/io/jans/as/model/configuration/AppConfiguration.java b/jans-auth-server/model/src/main/java/io/jans/as/model/configuration/AppConfiguration.java index 78be01e9fea..82580622ec5 100644 --- a/jans-auth-server/model/src/main/java/io/jans/as/model/configuration/AppConfiguration.java +++ b/jans-auth-server/model/src/main/java/io/jans/as/model/configuration/AppConfiguration.java @@ -14,6 +14,7 @@ import io.jans.as.model.jwk.KeySelectionStrategy; import io.jans.as.model.ssa.SsaConfiguration; import io.jans.as.model.ssa.SsaValidationConfig; +import io.jans.as.model.userinfo.UserInfoConfiguration; import io.jans.doc.annotation.DocProperty; import java.util.ArrayList; @@ -812,6 +813,9 @@ public class AppConfiguration implements Configuration { @DocProperty(description = "Enable/Disable block authorizations that originate from Webview (Mobile apps).", defaultValue = "false") private Boolean blockWebviewAuthorizationEnabled = false; + @DocProperty(description = "UserInfo Configuration") + private UserInfoConfiguration userInfoConfiguration; + public List getDcrSsaValidationConfigs() { if (dcrSsaValidationConfigs == null) dcrSsaValidationConfigs = new ArrayList<>(); return dcrSsaValidationConfigs; @@ -3096,4 +3100,12 @@ public Boolean getBlockWebviewAuthorizationEnabled() { public void setBlockWebviewAuthorizationEnabled(Boolean blockWebviewAuthorizationEnabled) { this.blockWebviewAuthorizationEnabled = blockWebviewAuthorizationEnabled; } + + public UserInfoConfiguration getUserInfoConfiguration() { + return userInfoConfiguration; + } + + public void setUserInfoConfiguration(UserInfoConfiguration userInfoConfiguration) { + this.userInfoConfiguration = userInfoConfiguration; + } } diff --git a/jans-auth-server/model/src/main/java/io/jans/as/model/userinfo/UserInfoConfiguration.java b/jans-auth-server/model/src/main/java/io/jans/as/model/userinfo/UserInfoConfiguration.java new file mode 100644 index 00000000000..8486d528a2d --- /dev/null +++ b/jans-auth-server/model/src/main/java/io/jans/as/model/userinfo/UserInfoConfiguration.java @@ -0,0 +1,24 @@ +package io.jans.as.model.userinfo; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import io.jans.doc.annotation.DocProperty; + +import java.util.HashMap; +import java.util.Map; + +@JsonIgnoreProperties( + ignoreUnknown = true +) +public class UserInfoConfiguration { + + @DocProperty(description = "List of key value, e.g. 'birthdate: 'yyyy-MM-dd', etc.") + private Map dateFormatterPattern = new HashMap<>(); + + public Map getDateFormatterPattern() { + return dateFormatterPattern; + } + + public void setDateFormatterPattern(Map dateFormatterPattern) { + this.dateFormatterPattern = dateFormatterPattern; + } +} diff --git a/jans-auth-server/server/conf/jans-config.json b/jans-auth-server/server/conf/jans-config.json index 6939b030bba..e3ac4e1af5a 100644 --- a/jans-auth-server/server/conf/jans-config.json +++ b/jans-auth-server/server/conf/jans-config.json @@ -450,5 +450,10 @@ "Cache-Control": "max-age=0, no-store" } }, - "blockWebviewAuthorizationEnabled": false + "blockWebviewAuthorizationEnabled": false, + "userInfoConfiguration": { + "dateFormatterPattern": { + "birthdate": "yyyy-MM-dd" + } + } } diff --git a/jans-auth-server/server/src/main/java/io/jans/as/server/userinfo/ws/rs/UserInfoRestWebServiceImpl.java b/jans-auth-server/server/src/main/java/io/jans/as/server/userinfo/ws/rs/UserInfoRestWebServiceImpl.java index c076c2839cd..070c7179f5a 100644 --- a/jans-auth-server/server/src/main/java/io/jans/as/server/userinfo/ws/rs/UserInfoRestWebServiceImpl.java +++ b/jans-auth-server/server/src/main/java/io/jans/as/server/userinfo/ws/rs/UserInfoRestWebServiceImpl.java @@ -69,12 +69,8 @@ import java.nio.charset.StandardCharsets; import java.security.PublicKey; import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.text.SimpleDateFormat; +import java.util.*; /** * Provides interface for User Info REST web services @@ -366,7 +362,13 @@ public String getJSonResponse(User user, AuthorizationGrant authorizationGrant, } else if (value instanceof Boolean) { jsonWebResponse.getClaims().setClaim(key, (Boolean) value); } else if (value instanceof Date) { - jsonWebResponse.getClaims().setClaim(key, ((Date) value).getTime() / 1000); + Date casteValue = (Date) value; + Optional optionalValue = getFormattedValueFromUserInfoConfiguration(key, casteValue); + if (optionalValue.isPresent()) { + jsonWebResponse.getClaims().setClaim(key, optionalValue.get()); + } else { + jsonWebResponse.getClaims().setClaim(key, casteValue.getTime() / 1000); + } } else { jsonWebResponse.getClaims().setClaim(key, String.valueOf(value)); } @@ -449,4 +451,17 @@ public boolean validateRequesteClaim(GluuAttribute gluuAttribute, String[] clien return false; } + + private Optional getFormattedValueFromUserInfoConfiguration(String key, Date value) { + String patternValue = appConfiguration.getUserInfoConfiguration().getDateFormatterPattern().get(key); + if (patternValue != null) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(patternValue); + return Optional.of(simpleDateFormat.format(value)); + } catch (Exception e) { + log.warn("Error during SimpleDateFormat instance: {}", e.getMessage()); + } + } + return Optional.empty(); + } } \ No newline at end of file diff --git a/jans-linux-setup/jans_setup/openbanking/templates/jans-auth/jans-auth-config.json b/jans-linux-setup/jans_setup/openbanking/templates/jans-auth/jans-auth-config.json index 27133f15ebf..e0825408292 100644 --- a/jans-linux-setup/jans_setup/openbanking/templates/jans-auth/jans-auth-config.json +++ b/jans-linux-setup/jans_setup/openbanking/templates/jans-auth/jans-auth-config.json @@ -395,5 +395,10 @@ "forceOfflineAccessScopeToEnableRefreshToken" : false, "redirectUrisRegexEnabled": false, "useHighestLevelScriptIfAcrScriptNotFound": true, - "blockWebviewAuthorizationEnabled": false + "blockWebviewAuthorizationEnabled": false, + "userInfoConfiguration": { + "dateFormatterPattern": { + "birthdate": "yyyy-MM-dd" + } + } } diff --git a/jans-linux-setup/jans_setup/templates/jans-auth/jans-auth-config.json b/jans-linux-setup/jans_setup/templates/jans-auth/jans-auth-config.json index 035932acae0..8c1ba0e9b88 100644 --- a/jans-linux-setup/jans_setup/templates/jans-auth/jans-auth-config.json +++ b/jans-linux-setup/jans_setup/templates/jans-auth/jans-auth-config.json @@ -498,5 +498,10 @@ "Cache-Control": "max-age=0, no-store" } }, - "blockWebviewAuthorizationEnabled": false + "blockWebviewAuthorizationEnabled": false, + "userInfoConfiguration": { + "dateFormatterPattern": { + "birthdate": "yyyy-MM-dd" + } + } }