Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling undefined username in the introspect response. #907

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions portals/devportal/src/main/webapp/services/login/introspect.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@
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));
if (username != null && !username.isEmpty()) {
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 {
log.warn("Username is undefined in the introspect response.");
}
} else {
log.warn("Something went wrong while introspecting the token " + tokenP1 + tokenP2);
log.error(introspectResult.body());
Expand Down
Loading