Skip to content

Commit

Permalink
feat(jans-auth-server): new configuration for userinfo has been added (
Browse files Browse the repository at this point in the history
  • Loading branch information
Milton-Ch authored Dec 20, 2022
1 parent 25cd1db commit 3ccc4a9
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SsaValidationConfig> getDcrSsaValidationConfigs() {
if (dcrSsaValidationConfigs == null) dcrSsaValidationConfigs = new ArrayList<>();
return dcrSsaValidationConfigs;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<String, String> dateFormatterPattern = new HashMap<>();

public Map<String, String> getDateFormatterPattern() {
return dateFormatterPattern;
}

public void setDateFormatterPattern(Map<String, String> dateFormatterPattern) {
this.dateFormatterPattern = dateFormatterPattern;
}
}
7 changes: 6 additions & 1 deletion jans-auth-server/server/conf/jans-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,10 @@
"Cache-Control": "max-age=0, no-store"
}
},
"blockWebviewAuthorizationEnabled": false
"blockWebviewAuthorizationEnabled": false,
"userInfoConfiguration": {
"dateFormatterPattern": {
"birthdate": "yyyy-MM-dd"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> 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));
}
Expand Down Expand Up @@ -449,4 +451,17 @@ public boolean validateRequesteClaim(GluuAttribute gluuAttribute, String[] clien

return false;
}

private Optional<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,10 @@
"forceOfflineAccessScopeToEnableRefreshToken" : false,
"redirectUrisRegexEnabled": false,
"useHighestLevelScriptIfAcrScriptNotFound": true,
"blockWebviewAuthorizationEnabled": false
"blockWebviewAuthorizationEnabled": false,
"userInfoConfiguration": {
"dateFormatterPattern": {
"birthdate": "yyyy-MM-dd"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -498,5 +498,10 @@
"Cache-Control": "max-age=0, no-store"
}
},
"blockWebviewAuthorizationEnabled": false
"blockWebviewAuthorizationEnabled": false,
"userInfoConfiguration": {
"dateFormatterPattern": {
"birthdate": "yyyy-MM-dd"
}
}
}

0 comments on commit 3ccc4a9

Please sign in to comment.