Skip to content

Working with groups

David Moebius edited this page Apr 29, 2014 · 41 revisions

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.

The group that will be used by OSIAM and the java connector is org.osiam.resources.scim. Group. Detailed information about can be found at the scim-schema wiki.

Chapters:

Group

The OSIAM Connector4Java is working with org.osiam.resources.scim. Group Objects.

A new group can be created with his builder:

Group group = new Group.Builder(<DisplayName>)
                //...
                .build();

Some variables of a group are:

String displayName = group.getDisplayName();
Set<MultiValuedAttribute> members = group.getMembers();
//...

Create a Group

After you have created a new group you can save it with:

OsiamConnector oConnector = Retrieving an OsiamConnector

AccessToken accessToken = Retrieving an AccessToken

Group newGroup = create a new Group

newGroup = oConector.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:

OsiamConnector oConnector = Retrieving an OsiamConnector

AccessToken accessToken = Retrieving an AccessToken

oConector.deleteGroup(<GROUP_UUID>, accessToken);

Update a Group

The OSIAM connector4Java provides an easy an quick way to change group values or group members. It is easy to change data, even if, you want to add one user to all current groups.

The following examples show how you can use the update methods:

OsiamConnector oConnector = Retrieving an OsiamConnector

AccessToken accessToken = Retrieving an AccessToken

If you want to update a group you need to know its ID (UUID). Get the ID with:

Group existingGroup = get existing Group

Now you can create a UpdateGroup and change the attributes:

UpdateGroup updateGroup = creating an UpdateGroup;

After this you just have to call the UpdateGroup method which will return the complete updated group:

Group updatedGroup = oConnector.updateGroup(existingGroup.getId(), updateGroup, accessToken);

If you want to change the same attributes for several groups you can call the method several times with different group ID's and the same UpdateGroup Object:

Group updatedGroup01 = oConnector.updateGroup(groupId01, updateGroup, accessToken);
Group updatedGroup02 = oConnector.updateGroup(groupId02, updateGroup, accessToken);
Group updatedGroup03 = oConnector.updateGroup(groupId03, updateGroup, accessToken);

Retrieve a single Group

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

OsiamConnector oConnector = Retrieving an OsiamConnector

AccessToken accessToken = Retrieving an AccessToken

Group group = oConnector.getGroup(<GROUP_UUID>, accessToken);

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

Retrieve all Groups

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

OsiamConnector oConnector = Retrieving an OsiamConnector

AccessToken accessToken = Retrieving an AccessToken

SCIMSearchResult<Group> searchResult = oConnector.getAllGroups(accessToken);
int numberOfGroups = searchResult.getTotalResults();
for (Group actGroup : searchResult.Resources()) {
	//...
}
//...

Search for groups

If you want to search for existing groups you can do this either with the provided builder or by providing a search "where" string. In both cases you will get in return a SCIMSearchResult described in the section Retrieve all Groups.

Search for groups by search string

To run a search for a group the following method can be used:

SCIMSearchResult<Group> result = oConnector.searchGroups(queryString, accessToken);

You can run a search for groups by providing a string with all where- and group-criteria.

Note: The query string should be URL encoded!

(For a detailed example please have a look at Retrieve all Groups and replace the first line under //example code with this example.)

The following filter options are supported:

  • eq = equals
  • co = contains
  • sw = starts with
  • pr = present
  • gt = greater than
  • ge = greater equals
  • lt = less than
  • le = less equals

Some of the supported fields for searching a group:

  • id
  • displayName
  • meta.created
  • meta.lastModified
  • meta.location
  • meta.version
  • meta.resourceType

For a detailed list of all supported fields please have a look at the scim schema of Groups.

If you want to search for Users or Groups by String we recommend to use the StringQueryBuilder. Here you can also see some more examples.

Search for Groups by Query

The Query class is an easy way to build a query:

Query query = new Query.Builder(Group.class).filter(new Query.Filter(Group.class, Group_.displayName.equalTo("Group01")))
                .sortOrder(SortOrder.ASCENDING).build();

With the following string you can open and control statement you have built:

String whereStatement = query.toString();

A complete example how you can run for a search for groups is the described below:

OsiamConnector oConnector = Retrieving an OsiamConnector

AccessToken accessToken = Retrieving an AccessToken

Query.Filter filter = new Query.Filter(Group.class, Group_.Meta.created.lessThan(new Date()))
        .and(new Query.Filter(Group.class, Group_.displayName.equalTo("Group01")));
Query query = new Query.Builder(Group.class).filter(filter)
        .sortOrder(SortOrder.ASCENDING).build();
SCIMSearchResult<Group> result = oConnector.searchGroups(query, accessToken);

Braces

Braces are needed to create more complex querys by using a separate Query for the inner one:

Query.Filter innerFilter = new Query.Filter(Group.class, Group_.displayName.equalTo("group01"))
.or(Group_.displayName.equalTo("group02"));

Query.Filter mainQuery = new Query.Filter(Group.class, Group_.Meta.created.greaterThan(new Date()))
.and(innerFilter);

The result of this example will be:

filter=meta.created gt "2011-10-10 00:00:00" and (displayName eq "group01" or displayName eq "group02")