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

Feature 287 Add attributes to an OrganizationMembership #290

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

rtufisi
Copy link
Collaborator

@rtufisi rtufisi commented Jan 4, 2025

No description provided.

@rtufisi rtufisi force-pushed the feature-287 branch 2 times, most recently from fd9648a to 3d6aca4 Compare January 5, 2025 07:02
@rtufisi rtufisi changed the title Feature 287 Add attributes to an OrganizationMembership @rtufisi Feature 287 Add attributes to an OrganizationMembership Jan 5, 2025
@@ -330,4 +414,17 @@ public Stream<IdentityProviderModel> getIdentityProvidersStream() {
return orgs.contains(getId());
});
}

private Predicate[] getSearchOptionPredicateArray(String value, CriteriaBuilder builder, From<?, UserEntity> from) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xgp maybe we could adapt our approach in the future to use the Keycloak default search filter org.keycloak.models.jpa.getSearchOptionPredicateArray. I think it covers more cases, and we will be consistent.
In the meantime the approach is not compatible with our test testSearchMembersWithMultipleNameParameter. If some clients are using it we will break their functionalities

private Predicate[] getSearchOptionPredicateArray(String value, CriteriaBuilder builder, From<?, UserEntity> from) {
value = value.trim().toLowerCase();

List<Predicate> orPredicates = new ArrayList<>();

if (value.length() >= 2 && value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
  // exact search
  value = value.substring(1, value.length() - 1);

  orPredicates.add(builder.equal(from.get(USERNAME), value));
  orPredicates.add(builder.equal(from.get(EMAIL), value));
  orPredicates.add(builder.equal(builder.lower(from.get(FIRST_NAME)), value));
  orPredicates.add(builder.equal(builder.lower(from.get(LAST_NAME)), value));
} else {
  value = value.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
  value = value.replace("*", "%");
  if (value.isEmpty() || value.charAt(value.length() - 1) != '%') value += "%";

  orPredicates.add(builder.like(from.get(USERNAME), value, ESCAPE_BACKSLASH));
  orPredicates.add(builder.like(from.get(EMAIL), value, ESCAPE_BACKSLASH));
  orPredicates.add(builder.like(builder.lower(from.get(FIRST_NAME)), value, ESCAPE_BACKSLASH));
  orPredicates.add(builder.like(builder.lower(from.get(LAST_NAME)), value, ESCAPE_BACKSLASH));
}

return orPredicates.toArray(Predicate[]::new);

}

@rtufisi
Copy link
Collaborator Author

rtufisi commented Jan 5, 2025

Screenshot from 2025-01-05 09-47-19

@rtufisi rtufisi marked this pull request as ready for review January 5, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant