-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Update composite roles on child role removal #11816
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| import org.keycloak.models.map.common.StringKeyConverter.UUIDKey; | ||
| import org.keycloak.models.map.storage.CriterionNotSupportedException; | ||
| import org.keycloak.models.map.storage.jpa.JpaModelCriteriaBuilder; | ||
| import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType; | ||
| import org.keycloak.models.map.storage.jpa.role.entity.JpaRoleEntity; | ||
| import org.keycloak.storage.SearchableModelField; | ||
|
|
||
|
|
@@ -61,6 +62,15 @@ public JpaRoleModelCriteriaBuilder compare(SearchableModelField<? super RoleMode | |
| return new JpaRoleModelCriteriaBuilder((cb, root) -> | ||
| cb.equal(root.get(modelField.getName()), value[0]) | ||
| ); | ||
| } else if (modelField == SearchableFields.COMPOSITE_ROLE){ | ||
| validateValue(value, modelField, op, String.class); | ||
|
|
||
| return new JpaRoleModelCriteriaBuilder((cb, root) -> | ||
| cb.isTrue(cb.function("@>", | ||
| Boolean.TYPE, | ||
| cb.function("->", JsonbType.class, root.get("metadata"), cb.literal("fCompositeRoles")), | ||
| cb.literal(convertToJson(value[0])))) | ||
|
Comment on lines
+68
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hmlnarik - probably not. At the same time I would assume that composite roles might soon move to its own table to follow along the discussion found here to allow adding or removing an entry to the composite roles without loading the rest of the entity: #11799 Depending on where that other PR will move to and how the performance improvements are, I wanted to call for a meeting on that topic to discuss how to handle situation where an attribute can contain a big collection of entries.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to keep this as is in this PR. Could you please file a GH issue that points to this discussion?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ); | ||
| } else { | ||
| throw new CriterionNotSupportedException(modelField, op); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized I am using a different comparison method here. I am using
==while everywhere else is theequalsmethod call. If I am not mistaken, both should work the way we want. Should I change this to use the equals method as well? Or it is okay to leave this as is?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, when thinking about it and reading[1], I believe we should be using
==instead ofequals. I'd create follow-up task to update it in all other places if we agree on it. I'll bring it up in the mtg.[1] https://docs.oracle.com/javase/specs/jls/se9/html/jls-8.html#jls-8.9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with changing it to
==as we want to have only one instance of eachSearchableField, however, SearchableFields are notenum. That is probably why there wasequalsmethod used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for using
==, the fields should be the same instances as the predefined ones.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#11843