Skip to content

Commit

Permalink
CLOUDTRUST-2335: fix bad regex parsing handling (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
lagess authored Feb 24, 2020
1 parent 493005b commit e496603
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public void testCreateUserEventReporting() throws InterruptedException {
UserRepresentation user = new UserRepresentation();
user.setUsername("test_user_creation");
Response rsp = keycloak.realm("test").users().create(user);
String loc = rsp.getHeaderString("Location");
String createdUserId = loc.substring(loc.lastIndexOf("/")+1);

assertThat(rsp.getStatus(), is(201));

// wait for the event to be reported
Expand All @@ -106,7 +109,7 @@ public void testCreateUserEventReporting() throws InterruptedException {
Gson g = new Gson();
ExtendedAdminEvent e = g.fromJson(jsonAsString, ExtendedAdminEvent.class);
assertThat(e.getAuthDetails().getUsername(), is("admin"));
assertThat(e.getDetails().get("user_id"), is(not(nullValue())));
assertThat(e.getDetails().get("user_id"), is(createdUserId));
assertThat(e.getDetails().get("username"), is("test_user_creation"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,11 @@ private ExtendedAdminEvent completeAdminEventAttributes(IdentifiedAdminEvent adm
String resourcePath = extendedAdminEvent.getResourcePath();
if (resourcePath != null && resourcePath.startsWith("users")) {
// parse userID
String pattern = ".*([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})";
String pattern = "^users/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(resourcePath);
m.matches();
String userId = m.group(1);
if (!Strings.isNullOrEmpty(userId)) {
if (m.matches()) {
String userId = m.group(1);
// retrieve user
UserModel user = keycloakSession.users().getUserById(userId,
keycloakSession.realms().getRealm(adminEvent.getRealmId()));
Expand Down

0 comments on commit e496603

Please sign in to comment.