Add support for custom user profile attributes#749
Merged
arvindkrishnakumar-okta merged 6 commits intooasv3from Aug 23, 2022
Merged
Add support for custom user profile attributes#749arvindkrishnakumar-okta merged 6 commits intooasv3from
arvindkrishnakumar-okta merged 6 commits intooasv3from
Conversation
|
|
||
| assertThat(updatedUser.lastUpdated, greaterThan(originalLastUpdated)) | ||
| assertThat(updatedUser.getProfile().getProperties().get("nickName"), equalTo("Batman")) | ||
| //assertThat(updatedUser.getProfile().getAdditionalProperties().get("key1"), equalTo("val1")) |
Contributor
Author
There was a problem hiding this comment.
Commented this because the ITs will be run in several Org cells as part of PDV runs. For this IT to run successfully, this custom profile property must first be added to the User schema via Console UI. Since this is not possible, we are disabling this test to prevent IT failures under such circumstances.
| // the respective property must first be associated to the User schema. | ||
| // You can use the Profile Editor in your Org's administrator UI or the Schemas API | ||
| // to manage schema extensions. | ||
| //userProfile.getAdditionalProperties().put("key1", "val1") |
Contributor
Author
There was a problem hiding this comment.
See below comment for reasoning behind why this line is commented out.
laura-rodriguez
approved these changes
Aug 16, 2022
There was a problem hiding this comment.
This LGTM, however, I suggest autogenerating the additionalProperties serialization instead of creating the serializer manually. SImilarly to what the codegen does with okhttp-gson:
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!UserProfile.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'UserProfile' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<UserProfile> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(UserProfile.class));
return (TypeAdapter<T>) new TypeAdapter<UserProfile>() {
@Override
public void write(JsonWriter out, UserProfile value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
obj.remove("additionalProperties");
// serialize additonal properties
if (value.getAdditionalProperties() != null) {
for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) {
if (entry.getValue() instanceof String)
obj.addProperty(entry.getKey(), (String) entry.getValue());
else if (entry.getValue() instanceof Number)
obj.addProperty(entry.getKey(), (Number) entry.getValue());
else if (entry.getValue() instanceof Boolean)
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
else if (entry.getValue() instanceof Character)
obj.addProperty(entry.getKey(), (Character) entry.getValue());
else {
obj.add(entry.getKey(), gson.toJsonTree(entry.getValue()).getAsJsonObject());
}
}
}
elementAdapter.write(out, obj);
}
@Override
public UserProfile read(JsonReader in) throws IOException {
JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
validateJsonObject(jsonObj);
// store additional fields in the deserialized instance
UserProfile instance = thisAdapter.fromJsonTree(jsonObj);
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
if (!openapiFields.contains(entry.getKey())) {
if (entry.getValue().isJsonPrimitive()) { // primitive type
if (entry.getValue().getAsJsonPrimitive().isString())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString());
else if (entry.getValue().getAsJsonPrimitive().isNumber())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber());
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean());
else
throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString()));
} else { // non-primitive type
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
}
}
}
return instance;
}
}.nullSafe();
}
}
arvindkrishnakumar-okta
added a commit
that referenced
this pull request
Oct 26, 2022
…776) * Regenerate and rewrite for OASv3 using `openapi-generator.tech` (#737) * minor refactor * minor refactor * fix Travis build failure * added circle ci config * added jdk18 to circle ci config * minor refactor * minor refactor * minor refactor * minor refactor * removed unwanted file * updated readme and migrating guides and other refactoring * [maven-release-plugin] prepare release okta-sdk-root-10.0.0-beta * [maven-release-plugin] prepare for next development iteration * Release pr 10.0.0 beta (#747) * [maven-release-plugin] prepare release okta-sdk-root-10.0.0-beta * [maven-release-plugin] prepare for next development iteration * Update README.md * Add support for custom user profile attributes (#749) * add support for custom user profile attributes * added license header on new files * fix build failure * refactored * refactored * refactored * [OASv3] - OAuth for Okta (#753) * wip - oauth for okta * fix unit test failure * fix unit test failure * OKTA-526761: Add Caching support (#768) * add caching * OKTA-537443: Add Groups ITs (#772) added GroupsIT * OKTA-537444: Add Policy ITs (#773) * added PoliciesIT (signon) * Regen sdk with latest oasv3 spec (#774) * added PoliciesIT (signon) * updated PolicyIT * regen and refactor sdk with latest oasv3 spec * minor update * fix build * cve fix and prep for oasv3 GA release (#777) * cve fix and prep for oasv3 GA release * removed unwanted yaml file * revert jakarta annotation back to 1.3.5 * updated migration guide * updated circle ci config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue(s)
Description
Category
Signoff