Skip to content

Commit

Permalink
Merge pull request #531 from DinithHerath/main
Browse files Browse the repository at this point in the history
Remove domain(@carbon.super) of logged-in username when there is an external IDP
  • Loading branch information
npamudika authored Feb 1, 2024
2 parents 541bed7 + 4c9a63b commit c6a8988
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ public static String getServiceProviderTenantDomain(HttpServletRequest request)
}
}

public static boolean isEnableEmailUserName() {
boolean isEnableEmailUserName = Boolean.parseBoolean(CarbonUtils.getServerConfiguration().getFirstProperty("EnableEmailUserName"));
if (isEnableEmailUserName) {
return isEnableEmailUserName;
} else {
return false;
}
}

/**
* Deciding what to process as app context. <br>
* If the settings.json has the following definition, <br><br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@
log.debug("Introspection result json: " + introspectResult.body());
if (introspectResult.statusCode() == 200) {
boolean isEnableEmailUserName = Util.isEnableEmailUserName();
Map introspect = gson.fromJson(introspectResult.body(), Map.class);
String username = (String) introspect.get("username");
Pattern regPattern = Pattern.compile("(@)");
boolean found = regPattern.matcher(username).find();
int count = !found ? 0 : (int) username.chars().filter(ch -> ch == '@').count();
if (isEnableEmailUserName || (username.indexOf("@carbon.super") > 0 && count <= 1)) {
introspect.put("username", username.replace("@carbon.super", ""));
}
response.setContentType("application/json");
out.println(gson.toJson(introspect));
} else {
Expand Down

0 comments on commit c6a8988

Please sign in to comment.