Skip to content

Commit

Permalink
fix(FSADT1-1333): fixing client name on mail
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Jun 3, 2024
1 parent 70e097b commit ef35586
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ private static Map<String, String> processName(JwtAuthenticationToken principal)
Map<String, Object> payload = principal.getTokenAttributes();
Map<String, String> additionalInfo = new HashMap<>();

// Extract provider name
String providerName = getProvider(principal);

// Extract business name if exists
additionalInfo.put("businessName",
String.valueOf(payload.getOrDefault("custom:idp_business_name", StringUtils.EMPTY)));
Expand All @@ -162,14 +165,14 @@ private static Map<String, String> processName(JwtAuthenticationToken principal)
String lastName = String.valueOf(payload.getOrDefault("family_name", StringUtils.EMPTY));

// Determine if special handling for names is required
boolean useDisplayName = "bceidbusiness".equals(getProvider(principal)) || (firstName.isEmpty()
boolean useDisplayName = "bceidbusiness".equals(providerName) || (firstName.isEmpty()
&& lastName.isEmpty());
if (useDisplayName) {
String displayName = String.valueOf(payload.get("custom:idp_display_name"));
String[] nameParts =
displayName.contains(",") ? displayName.split(",") : displayName.split(" ");

if ("IDIR".equals(getProvider(principal)) && nameParts.length >= 2) {
if ("IDIR".equals(providerName) && nameParts.length >= 2) {
// For IDIR, split by comma and then by space for the first name as the value will be Lastname, Firsname MIN:XX
lastName = nameParts[0].trim();
firstName = nameParts[1].split(" ")[0].trim();
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/helpers/ForestClientUserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,25 @@ class ForestClientUserSession implements SessionProperties {
additionalInfo.lastName = payload.family_name;
}

if(payload["custom:idp_business_name"]){
additionalInfo.businessName = payload["custom:idp_business_name"];
}

if (
provider === "bceidbusiness" ||
(additionalInfo.firstName === "" && additionalInfo.lastName === "")
) {
const name = payload["custom:idp_display_name"];
const spaceIndex = name.indexOf(" ");
if (spaceIndex > 0) {
additionalInfo.lastName = this.splitAtSpace(
payload["custom:idp_display_name"]
)[0].replace(/,/g, "");
additionalInfo.firstName = this.splitAtSpace(
payload["custom:idp_display_name"]
)[1].replace(/,/g, "");
additionalInfo.businessName = payload["custom:idp_business_name"];
const nameParts: string[] = name.includes(",") ? name.split(",") : name.split(" ");

if (provider === "idir" && nameParts.length >= 2) {
// For IDIR, split by comma and then by space for the first name as the value will be Lastname, Firsname MIN:XX
additionalInfo.lastName = nameParts[0].trim();
additionalInfo.firstName = nameParts[1].split(" ")[0].trim();
} else if (nameParts.length >= 2) {
// For others, assume space separates the first and last names
additionalInfo.firstName = nameParts[0].trim();
additionalInfo.lastName = nameParts.slice(1).join(" ");
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/stub/mappings/fam.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"Location": "http://{{request.host}}:3000/dashboard",
"Set-Cookie": [
"CognitoIdentityServiceProvider.69u4hdmcoiuuhpmi59qmndhikk.LastAuthUser=abc123; sameSite=Lax; path=/; Expires={{now offset='10 years' format='EEE, d MMM yyyy HH:mm:ss'}} GMT; domain={{request.host}}",
"CognitoIdentityServiceProvider.69u4hdmcoiuuhpmi59qmndhikk.abc123.idToken=eyJhbGciOiJIUzI1NiJ9.eyJjdXN0b206aWRwX3VzZXJfaWQiOiJ1YXR0ZXN0IiwiY3VzdG9tOmlkcF9uYW1lIjoiYmNlaWRidXNpbmVzcyIsImN1c3RvbTppZHBfYnVzaW5lc3NfaWQiOiJhdXRvbWF0aW9uaW5jIiwiY3VzdG9tOmlkcF9kaXNwbGF5X25hbWUiOiJVYXQgVGVzdCIsImdpdmVuX25hbWUiOiJVYXQiLCJmYW1pbHlfbmFtZSI6IlRlc3QiLCJlbWFpbCI6InVhdHRlc3RAZ292LmJjLmNhIiwiaWRwX2J1c2luZXNzX25hbWUiOiJBdXRvbWF0aW9uIEluYyJ9.j8ok8GDYT2n2WMJJNAj0BcC5PRwJzGSkLKLZkOjyHtQ; sameSite=Lax; path=/; Expires={{now offset='10 years' format='EEE, d MMM yyyy HH:mm:ss'}} GMT; domain={{request.host}}"
"CognitoIdentityServiceProvider.69u4hdmcoiuuhpmi59qmndhikk.abc123.idToken=eyJhbGciOiJIUzI1NiJ9.eyJjdXN0b206aWRwX3VzZXJfaWQiOiJ1YXR0ZXN0IiwiY3VzdG9tOmlkcF9uYW1lIjoiYmNlaWRidXNpbmVzcyIsImN1c3RvbTppZHBfYnVzaW5lc3NfaWQiOiJhdXRvbWF0aW9uaW5jIiwiY3VzdG9tOmlkcF9kaXNwbGF5X25hbWUiOiJVYXQgVGVzdCIsImVtYWlsIjoidWF0dGVzdEBnb3YuYmMuY2EiLCJpZHBfYnVzaW5lc3NfbmFtZSI6IkF1dG9tYXRpb24gSW5jIn0.LH4CYOpezN0HACaBu9HzGg1nWLfIXr4pOpaprsVrNcQ; sameSite=Lax; path=/; Expires={{now offset='10 years' format='EEE, d MMM yyyy HH:mm:ss'}} GMT; domain={{request.host}}"
]
}
}
Expand Down

0 comments on commit ef35586

Please sign in to comment.