Repository navigation
KEYCLOAK-14665 initial spi interfaces with validator chain and UserAttributesReprese… - #7155
Conversation
fc47c68 to
ec36574
Compare
|
@bs-matil is this PR covering the whole epic here https://issues.jboss.org/browse/KEYCLOAK-2966 ? Or part of this? For now I'm adding the label missing, Jira, but please let me know if my assumption is completely wrong. |
|
@abstractj It's just doing first part of it. We should have a JIRA to describe what it is and associate this PR/commit with it. |
|
@bs-matil I ran out of time before hols' so won't be able to take a look at least before July I'm afraid. |
c15b483 to
12e4582
Compare
|
I just refactored all against the new attribute handling in the user model |
There was a problem hiding this comment.
This is needed because of the "chained action" approach in the registration. May it should be considered to adapt the registration flow in order to remove this switch so we can go here with configuration only.
e45e518 to
6536ab1
Compare
|
@pedroigor any news on that? Should I may refile the PR, the history is a bit cluttered. |
@bs-matil I'll be looking User Profile this week, starting today. Need to sync what was discussed/done so far before reviewing this PR or any other that is related. One thing though, from your comments it seems this PR is delivering what was defined as M1 in the design document. I agree that we can deal with validation later (including the PR from @thomasdarimont around validation) and focus on the core changes to support user profiles. Does it make sense for you? Btw, could you please rebase? |
|
@bs-matil, There are a lot of changes to formatting/cleanup and empty lines being removed that do not seem related to the changes you are doing. In order to make the reviewing process a bit easier and objective, could you please revert any change like that? |
54aeab7 to
c9b53b2
Compare
I'll work on this. |
rebase has been completed. tests pending. |
|
|
||
| public void singleAttribute(String name, String value) { | ||
| if (this.attributes == null) attributes = new HashMap<>(); | ||
| attributes.put(name, (value == null ? new ArrayList<String>() : Arrays.asList(value))); |
There was a problem hiding this comment.
I think we should not even set the attribute if the value is null or empty.
We can probably throw an IllegalArgumentException too in this case.
There was a problem hiding this comment.
the check does not check for attribute values but for the attribute list. If the list is not initialized (which is likely due to the nature of the Representation objects) this should IMHO nothing the user of this function has to deal with.
|
|
||
| public UserRepresentation singleAttribute(String name, String value) { | ||
| public void singleAttribute(String name, String value) { | ||
| if (this.attributes == null) attributes = new HashMap<>(); |
There was a problem hiding this comment.
The same here:
- Do not accept
nullvalues by either not updating the map or throwing anIllegalArgumentException.
There was a problem hiding this comment.
same here its not a value check
There was a problem hiding this comment.
Maybe we can make life easier for implementors if we change some methods like that:
default String getFirstAttributeValue(String attributeKey) {
List<String> values = getAttributes().getOrDefault(name, Collections.emptyList());
if (values.isEmpty()) {
return null;
}
return values.get(0);
}
default List<String> getAttribute(String attributeKey) {
return getAttributes().get(key);
}
So that you only need to override getId and getAttributes. The latter being the real source of data.
I'm also wondering if we should not have attributes in a separate structure similar to Attributes. One of the main points being that we can add more controls such as read/write flags without impacting the main UserProfile API.
There was a problem hiding this comment.
As I tried to explain in the other comment regards the interface of the userprofile. The current UserProfile interface is actually just an attributes interfaces (may a bad one) but I'm right now not sure how to go towards your solution. I will push what I understood soon..
There was a problem hiding this comment.
I think UserProfileUpdateHelper can be simpler if we just pass the attribute map instead of the UserModel. It would avoid having to create this anonymous class to work around the contract to only fetch attributes.
I'm also wondering why the logic on UserProfileUpdateHelper is not on the UserProfileProvider itself?
There was a problem hiding this comment.
Regards the position of user profile itself see other comment.
Regards the AttributeList.
This won't work because of the nature of the different UserModel implementations (e,g, for idpReview). Some just are not useable as simple attribute list. (Their interface for the attributes does not work consistently)
There was a problem hiding this comment.
The differences are reflected in the different user profile implementations
There was a problem hiding this comment.
I think we could have some methods here to create the UserProfileProvider instance without pushing too much to clients of the API. For instance:
Map<String, List<String>> newAttributes = // obtain attributes to update
UserProfileProviderFactory factory = // obtain factory from session
UserProfileProvider provider = factory.create(UserUpdateEvent.IdpReview, user.getAttributes(), newAttributes);
UserProfileValidationResult result = profileProvider.validate();
This can hide some implementation details such as the UserProfileContext implementation that should be used. As well as the different UserProfile implementations (if we really need all those impls). In fact, another approach to the API could be:
Map<String, List<String>> newAttributes = // obtain attributes to update
UserProfileProvider provider = // obtain provider from factory
UserProfileValidationResult result = profileProvider.validate(UserProfile.forIdpReview(userCtx), newAttributes);
So that the event would become irrelevant and we could check for the context based on the type of the UserProfile instance.
In addition to that, the user ID also works like any other attribute into the attribute map that is the real source of data and data structure we care about to perform the validations.
The Attributes API I gave as an example could also help to make this SPI more attribute oriented and simplify even more how clients pass over the attributes from the different places in Keycloak as well as using different sources.
I've also another idea for this SPI based on events. But I think it would demand changes that we probably don't want now to include a more generic and robust event system in Keycloak.
There was a problem hiding this comment.
@pedroigor I tried to go into this direction. It's not possible to do this on the SPI level as the interfaces would have to know the concrete types in the service impl. So I moved the factory like methods into the DefaultUserProfileContext
|
@bs-matil These are my initial thoughts, I hope they make sense for you. I'll hold a bit the review and wait for your feedback considering that some of my comments are related to the design of the SPI. |
There was a problem hiding this comment.
I understand the reason behind it I think. So that a UserProfile is marked as writable.
After reading through your code, looks like to me that the best would be if we had a single UserProfile implementation, with attributes encapsulated via a Attributes API so that the read/write capability could be controlled accordingly depending on the type of the event.
There was a problem hiding this comment.
I'm a bit confused to be honest. the current UserProfile interface is actually very close to an Attributes interface. So to move towards your solution I would rename UserProfile to UserAttributes and merge the StoredUserProfile methods into this interface. Then on all implementations I would add the write methods and throw Exceptions when they are called.
Is this even close to your idea? I will do so. But may I got you fully wrong here, I at least suspect that.
There was a problem hiding this comment.
Why create an attribute with a list of null values ?
There was a problem hiding this comment.
because for example this test expects that the handling of email is "" -> null while this is not the case anywhere else...
There was a problem hiding this comment.
I invested time in keeping the api of the validation as consistent as possible. But there are inconsistencies in the code
Thats why I initially put the user update method into the user profile. That would have enabled to override the behaviour for the old very inconsistent code path while having a clean new store method in the future.
But Stian argued against this as the profile should not care about storage but validation only. So I moved the code to this helper class and out of the SPI interface.
c9b53b2 to
93bb60b
Compare
93bb60b to
ebe9157
Compare
ebe9157 to
cc0f547
Compare
0365399 to
4b0bbae
Compare
I would wait now for additional feedback @pedroigor |
…e introduced to make getId override explicit
0b3446b to
6c85a0d
Compare
| */ | ||
| @Path("/applications/{clientId}") | ||
| @GET | ||
| @Produces(MediaType.APPLICATION_JSON) |
There was a problem hiding this comment.
@bs-matil I forgot to mention this change in my last review. Why did you add this endpoint for?
There was a problem hiding this comment.
looks like accidentally. Shall I open a PR for removal?
There was a problem hiding this comment.
Yes, please. Sorry about that. I added the comment but it got lost during the review ...
There was a problem hiding this comment.
Sorry too, I tought I will at least have one more time to squash and cleanup. Wasn't expecting a so fast merge after the history of this PR
This is the initial contribution for the Milestone M1 for the legacy profile as documented in https://github.com/keycloak/keycloak-community/blob/master/design/user-profile.md and relates to https://issues.jboss.org/browse/KEYCLOAK-14665
A specific Ticket will be created and added soon.
Contents: