Comments (17)
@arvindkrishnakumar-okta the example above can recreate the issue.
The user you are getting needs a profile with a custom attribute with the data type: string array.
from okta-sdk-java.
@arvindkrishnakumar-okta your example is almost there. Create the user as described in step 1.
In step 2 do not update the array attribute but another attribute.
User fetchedUser = userApi.getUser(userId);
UserProfile profile = fetchedUser.getProfile();
profile.setFirstName("Test");
User replacedUsr = userApi.replaceUser(userId, fetchedUser, null);
println("Replaced User: " + replacedUsr);
from okta-sdk-java.
I can confirm that this worked. Thanks for fixing this.
from okta-sdk-java.
@JFreakDK Thanks for posting!
For updating user profile, it is recommended to use updateUserApi
- https://developer.okta.com/docs/reference/api/users/#update-user
Can you try the below?
User user = userApi.getUser(userId);
UserProfile profile = user.getProfile().city("Awesome City");
UpdateUserRequest request = new UpdateUserRequest().profile(profile);
User updatedUser = userApi.updateUser(userId, request, null);
Assert.isTrue(updatedUser.getProfile().getCity().equals("Awesome City"));
This example shows standard profile property, if you want to use it with a custom property (additional properties), be sure to add it to your Org via UI before using the API.
from okta-sdk-java.
The updateUser
API call has the same issue when the profile contains array properties.
{"errorCode":"E0000001","errorSummary":"Api validation failed: userProfile","errorLink":"E0000001","errorId":"<error-id>","errorCauses":[{"errorSummary":"Invalid value data type for property '<array property>'"},{"errorSummary":"Invalid value data type for property '<other array property>'"},{"errorSummary":"Invalid value data type for property '<third array property>'"}]}
If I convert the value of these array properties I can use both the updateUser
and replaceUser
.
I convert them using this method:
public static List<String> toList(UserProfile profile, String accessor) {
String accessorValue = (String) profile.getAdditionalProperties().get(accessor);
if (accessorValue != null && !accessorValue.equals("[]")) {
String[] accessorList = accessorValue.substring(1, accessorValue.length() - 1).split(", ");
List<String> stringList = Arrays.asList(accessorList);
return new ArrayList<>(stringList);
} else {
return new ArrayList<>();
}
}
from okta-sdk-java.
@JFreakDK Sorry but I'm a bit lost here on what you're trying to achieve with replaceUser()/updateUser().
Can you please post the complete sequence of API requests you're trying to use to help me reproduce the issue?
FWIW, the replaceUser
API's signature has changed in 11.0.0
.
/**
* Replace a User
* Replaces a user's profile and/or credentials using strict-update semantics
*
* @param userId (required)
* @param user (required)
* @param strict (optional)
* @return User
* @throws ApiException if fails to make API call
*/
public User replaceUser(String userId, User user, Boolean strict) throws ApiException {
return this.replaceUser(userId, user, strict, Collections.emptyMap());
}
from okta-sdk-java.
@JFreakDK Thanks for the info, I'll work on the fix.
from okta-sdk-java.
@JFreakDK I tried to reproduce this issue but I find this use case to be working fine.
- Added a Custom String array attribute (
myStrArr
) to user profile via console UI:
- Used below code to create a user and update the created user with a value for
myStrArr
profile attribute (SDK Version 12.0.2):
UpdateUserRequest updateUserRequest = new UpdateUserRequest();
UserProfile userProfile = new UserProfile();
userProfile.setNickName("Batman");
// Note: Custom user profile properties can be added with something like below, but
// the respective property must first be associated to the User schema.
// You can use the Profile Editor in your Org administrator UI or the Schemas API
// to manage schema extensions.
userProfile.getAdditionalProperties().put("myStrArr", new String[] {"Hello", "World"});
updateUserRequest.setProfile(userProfile);
userApi.updateUser(user.getId(), updateUserRequest, true);
User updatedUser = userApi.getUser(user.getId());
updatedUser instance above contains the updated profile attrbute values for myStrArr
.
Inspecting the updated user in debugger:
Viewing the updated user's profile via console:
Please review this and let me know if you have any questions or if I am missing something.
from okta-sdk-java.
Will go ahead and close this issue, feel free to reopen if needed.
from okta-sdk-java.
I tried to reproduce this issue again with this method:
private void testReplaceUser(UserApi userApi, String userId) {
var user = userApi.getUser(userId);
UserProfile profile = user.getProfile();
assert profile != null;
userApi.replaceUser(userId, user, null);
}
This causes this exception to be thrown:
ApiException{code=400, responseHeaders={...}, responseBody='{"errorCode":"E0000001","errorSummary":"Api validation failed: userProfile","errorLink":"E0000001","errorId":"oaealURtv_KS6q44SFeTLIFFQ","errorCauses":[{"errorSummary":"Invalid value data type for property 'propertyName'"}]}
'}
at org.openapitools.client.ApiClient.processResponse(ApiClient.java:957)
at org.openapitools.client.ApiClient.invokeAPI(ApiClient.java:1109)
at org.openapitools.client.api.UserApi.replaceUser(UserApi.java:2273)
at org.openapitools.client.api.UserApi.replaceUser(UserApi.java:2215)
from okta-sdk-java.
@JFreakDK Thats strange!
I just tried to do what you did and did not encounter the above issue you posted.
User fetchedUser = userApi.getUser(userId);
UserProfile profile = fetchedUser.getProfile();
profile.setFirstName("UpdatedFirstName");
User replacedUsr = userApi.replaceUser(userId, fetchedUser, null);
from okta-sdk-java.
@arvindkrishnakumar-okta it looks like your user does not have a list property with values.
That is the case that is failing for me:
from okta-sdk-java.
@JFreakDK can you elaborate on "list property with values"? Can you paste a screenshot of how that property is defined in your Org UI (property editor)?
I tried with array property and hHere is the sequence:
- Created a user with custom array property for profile:
User user = UserBuilder.instance()
.setEmail(email)
.setFirstName("Joe")
.setLastName("Coder")
.setPassword(password)
.setSecurityQuestion("Favorite security question?")
.setSecurityQuestionAnswer("None of them!")
.setCustomProfileProperty("myStrArr", new String[] {"Hello", "World"}) // pre-req: custom profile properties need to be set in your Org's Profile editor via Admin UI.
.setActive(true)
.addGroup(group.getId()) // add user to the newly created group
.buildAndCreate(userApi);
- Fetch the user and change the profile attribute and invoke replaceUser:
User fetchedUser = userApi.getUser(userId);
UserProfile profile = fetchedUser.getProfile();
profile.getAdditionalProperties().put("myStrArr", new String[] {"HelloUpdated", "WorldUpdated"});
User replacedUsr = userApi.replaceUser(userId, fetchedUser, null);
println("Replaced User: " + replacedUsr);
from okta-sdk-java.
@JFreakDK #932 should fix this.
from okta-sdk-java.
I don't see that #932 changes anything related to additional properties.
from okta-sdk-java.
@JFreakDK The PR addresses the issue where the additional property map value was incorrectly deserialized into a String value (we should retain it as an Object and not convert it into String while storing it). I've tested the PR locally.
Feel free to validate it once the fix has been merged to master (next release should be available in few days).
from okta-sdk-java.
Release 13.0.1 is now available.
from okta-sdk-java.
Related Issues (20)
- ClassNotFoundException with current dependencies in Gradle build HOT 4
- Okta Verify Fast Pass as an enrolled Factor is not returned HOT 8
- UserProfile equals() does not return true when objects are equal HOT 1
- Upgrade to 13.0.2 causes updateUser API to fail from attribute being mastered by a different system HOT 8
- `IdentityProviderApi` cannot properly deserialize `/ipds` responses HOT 1
- Create authorization server policy with type OAUTH_AUTHORIZATION_POLICY get error HOT 3
- IdP Discovery Policy not returned in listPolicyRules() HOT 2
- GroupsAPI - Custom group profile attributes missing HOT 3
- Several outdated dependencies
- OpenAPI spec missing some default role type HOT 3
- Invalid session HOT 3
- IdpPolicyRuleActionProvider needs the ability to set the provider id to be useful for creating IDP Routing Rules HOT 3
- Private Key is interpreted as PEMKeyPair instead of PrivateKeyInfo HOT 3
- Consistently thrown NoHttpResponseException's in 13.0.3 HOT 3
- UserApi#listUserGroups() doesn't support pagination HOT 4
- UserApi: listUserGroups() does not return more than 200 groups for a user HOT 1
- Question about thread safety of `PaginationUtil` HOT 2
- Support Apple as an IdentityProviderType HOT 3
- Update Application User returns E0000009 with no message HOT 1
- Jar for package in Maven corrupted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okta-sdk-java.