Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Latest commit

 

History

History
131 lines (99 loc) · 4.23 KB

working-with-user.md

File metadata and controls

131 lines (99 loc) · 4.23 KB

To perform any actions with users you always need an access token. For retrieving an access token please see Login and getting an access token.

Chapters:

Create a User

After you have created a new user you can save him with:

OsiamConnector oConnector = [Retrieving an OsiamConnector](create-osiam-connector.md)
AccessToken accessToken = [Retrieving an AccessToken](login-and-getting-an-access-token.md#retrieving-an-accesstoken)
User newUser = [create a new User](#user)
newUser = oConnector.createUser(newUser, accessToken);

Now the returned user object contains the ID and meta data of the newly created user.

Delete a User

To delete a user call:

OsiamConnector oConnector = [Retrieving an OsiamConnector](create-osiam-connector.md)
AccessToken accessToken = [Retrieving an AccessToken](login-and-getting-an-access-token.md#retrieving-an-accesstoken)
oConnector.deleteUser(<USER_UUID>, accessToken);

Update a User

The OSIAM Connector4Java provides a way to change user data. You are able to update just a single value, all of them, or anything in between. The following examples shows how you can update a user.

If you want to update a user you need to know their ID (UUID). Then you can create a new user based on the original user and change their attributes:

User newUser = new User.Builder(originalUser)
        .setActive(true)
        // Updating an email address
        .removeEmail(originalUser.emails[0])
        .addEmail(new Email.Builder(originalUser.emails[0])
                .setValue('[email protected]')
                .setPrimary(true)
                .build())
        // Adding an email address
        .addEmail(new Email.Builder()
                .setValue('[email protected]')
                .setType(Email.Type.HOME)
                .build())
        // Removing an email address
        .removeEmail(originalUser.emails[1])
        .build();

After this you just have to call the replaceUser method that will return the updated user:

User updatedUser = oConnector.replaceUser(originalUser.getId(), newUser, accessToken);

Retrieve a single User

To retrieve a single user you need his UUID (for example: 94bbe688-4b1e-4e4e-80e7-e5ba5c4d6db4):

User user = osiamConnector.getUser(<USER_UUID>, accessToken);

It is possible to filter the attributes of the returned resource by specifying the attributes to return as parameters to the method:

User user = osiamConnector.getUser(<USER_ID>, accessToken, "userName", "displayName", "meta.created");

(please consider the possible runtimeException which are explained in the Javadoc)

Retrieve the currently logged in user by their access token

To retrieve the user that the currently held access token belongs to, the getMe() method is avaiable:

// retrieves the complete currently logged in User.
User user = osiamConnector.getMe(accessToken);

It is possible to filter the attributes of the returned user by supplying the wanted attributes as parameters to the method:

User user = osiamConnector.getUser(<USER_ID>, accessToken, "userName", "displayName", "meta.created");

Retrieve all Users

If you want to retrieve all users you can call the following method:

List<User> users = oConnector.getAllUsers(accessToken);
int numberOfUsers = searchResult.getTotalResults();
for (User actUser : searchResult.Resources()) {
	//...
}

It is possible to filter the attributes of the returned users by supplying the attributes as parameters to the method:

List<User> users = oConnector.getAllUsers(accessToken, "userName", "meta.created");

Search for User

The Query class helps you to create an Query based on the needed filter and other attributes.

An example how to run a search for a user is shown below:

SCIMSearchResult<User> result = oConnector.searchUsers(query, accessToken);