To perform any actions with groups you always need an access token. For retrieving an access token please see [Login and getting an access token] (login-and-getting-an-access-token.md).
Chapters:
- Creating a Group
- Deleting a Group
- Update a Group
- Retrieve a single Group
- Retrieve all Groups
- Search for groups
- by search string
- by Query
After you have created a new group you can save it with:
``java OsiamConnector oConnector = Retrieving an OsiamConnector
AccessToken accessToken = Retrieving an AccessToken
Group newGroup = create a new Group
newGroup = oConnector.createGroup(newGroup, accessToken);
Now the returned Group Object also contains the ID and meta data of the newly
created group.
## Delete a Group
To delete a group call:
```java
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.deleteGroup(<GROUP_UUID>, accessToken);
The OSIAM connector4Java provides a way to change group data or group members. The following examples shows how you can update a group.
If you want to update a group you need to know its ID (UUID). Then you can create a new group based on the original group and change its attributes:
Group newGroup = new Group.Builder(originalGroup)
// Updating
.removeMember(originalGroup.members[0])
.addMember(new MemberRef.Builder(originalGroup.members[0])
.setValue('d869f486-29cc-11e6-a76a-e82aea766790')
.build())
// Adding
.addMember(new MemberRef.Builder()
.setValue('e0f07f9e-29cc-11e6-b251-e82aea766790')
.build())
// Removing
.removeMember(originalGroup.members[1])
.build();
After this you just have to call the replaceGroup
method that will return the updated group:
Group updatedGroup = oConnector.replaceGroup(originalGroup.getId(), newGroup, accessToken);
To retrieve a single Group you need her UUID (for example 94bbe688-4b1e-4e4e-80e7-e5ba5c4d6db4):
Group group = oConnector.getGroup(<GROUP_UUID>, accessToken);
(please consider the possible runtimeException which are explained in the Javadoc)
It is possible to filter the attributes of the returned resource by specifying the attributes to return as parameters to the method:
Group group = osiamConnector.getGroup(<GROUP_ID>, accessToken, "displayName", "meta.created");
If you want to retrieve all groups you can call the following method:
List<Group> searchResult = oConnector.getAllGroups(accessToken);
int numberOfGroups = searchResult.getTotalResults();
for (Group actGroup : searchResult.Resources()) {
//...
}
//...
It is possible to filter the attributes of the returned groups by supplying the attributes as parameters to the method:
List<Group> searchResult = oConnector.getAllGroups(accessToken, "displayName", "meta.created");
The Query class helps you to create an Query based on the needed filter and other attributes. (The examples in the page are for users. Please adapt them for groups)
A complete example how you can run a search for a user is described below:
Query query = [Create an Query](query.md)
SCIMSearchResult<Group> result = oConnector.searchGroups(query, accessToken);