Git Product home page Git Product logo

Comments (17)

JFreakDK avatar JFreakDK commented on August 19, 2024 1

@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.

JFreakDK avatar JFreakDK commented on August 19, 2024 1

@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.

JFreakDK avatar JFreakDK commented on August 19, 2024 1

I can confirm that this worked. Thanks for fixing this.

from okta-sdk-java.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@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.

JFreakDK avatar JFreakDK commented on August 19, 2024

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.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@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&#39;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.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@JFreakDK Thanks for the info, I'll work on the fix.

from okta-sdk-java.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@JFreakDK I tried to reproduce this issue but I find this use case to be working fine.

  1. Added a Custom String array attribute (myStrArr) to user profile via console UI:

image

  1. 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:

image

Viewing the updated user's profile via console:

image

Please review this and let me know if you have any questions or if I am missing something.

from okta-sdk-java.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

Will go ahead and close this issue, feel free to reopen if needed.

from okta-sdk-java.

JFreakDK avatar JFreakDK commented on August 19, 2024

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.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@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);

image

from okta-sdk-java.

JFreakDK avatar JFreakDK commented on August 19, 2024

@arvindkrishnakumar-okta it looks like your user does not have a list property with values.

That is the case that is failing for me:
profile

from okta-sdk-java.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@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:

  1. 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);
  1. 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);

image

image

from okta-sdk-java.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@JFreakDK #932 should fix this.

from okta-sdk-java.

JFreakDK avatar JFreakDK commented on August 19, 2024

I don't see that #932 changes anything related to additional properties.

from okta-sdk-java.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

@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.

arvindkrishnakumar-okta avatar arvindkrishnakumar-okta commented on August 19, 2024

Release 13.0.1 is now available.

from okta-sdk-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.