-
Notifications
You must be signed in to change notification settings - Fork 0
Working with groups
To perform any actions with Groups you always need a access token. How you can retrieve a access token can be seen here.
The Group which will be used by OSIAM and the java connector is a org.osiam.resources.scim. Group. For more detailed information about this, please click here
Chapters:
- OsiamGroupService
- Group Object
- Retrieve a single Group
- Retrieve all Groups
- Search for groups
- by search string
- by Query
To get or search for groups you need to create an OsiamGroupService object.
AccessTocken accessToken = Retrieving an AccessToken
OsiamGroupService service = new OsiamGroupService.Builder("<OSIAM_SERVER_ADDRESS>").build();After a Group instance was retrieved you can access his parameters.
AccessTocken accessTocken = Retrieving an AccessToken
OsiamGroupService service = new OsiamGroupService
String displayName = group.getDisplayName();
//...To retrieve a single Group you need his id which is a UUID like 94bbe688-4b1e-4e4e-80e7-e5ba5c4d6db4.
AccessTocken accessTocken = Retrieving an AccessToken
OsiamGroupService service = new OsiamGroupService
Group group = service.getGroupByUUID(<GROUP_UUID>, accessToken);(beware of the possible runtimeException which are explained in the Javadoc)
If you want to retrieve all Groups you can call the following
AccessTocken accessTocken = Retrieving an AccessToken
OsiamGroupService service = new OsiamGroupService
QueryResult<Group> queryResult = service.getAllGroups(accessToken);
int numberOfGroups = queryResult.getTotalResults();
for (Group actGroup : queryResult.Resources()) {
//...
}
//...If you want to search 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 QueryResult described in the section Retrieve all Groups
by using the method
QueryResult<Group> result = service.searchGroups(whereString, accessToken);you can search for groups by providing a string with all where and grouping 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 are:
- 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 for groups.)
With the Query class you have an easy way to build a Query
Query query = new Query.Builder(Group.class).filter(new Query.Filter(Group.class).startsWith(Group_.displayName.equalTo("Group01")))
.sortOrder(SortOrder.ASCENDING).build();with
String whereStatement = query.toString();you can get and control the where statement you have been building.
A complete example how you can search for a Groups is the following
AccessTocken accessTocken = Retrieving an AccessToken
OsiamGroupService service = new OsiamGroupService
Query.Filter filter = new Query.Filter(Group.class).startsWith(Group_.meta.created.lessThan(new Date()))
.and(new Query.Filter(Group.class)
.startsWith(Group_.displayName.equalTo("Group01")));
Query query = new Query.Builder(Group.class).filter(filter)
.sortOrder(SortOrder.ASCENDING).build();
QueryResult<Group> result = service.searchGroups(query, accessToken);For more complex Querys you have to do this with braches you can do this with using a seperat Query for the inner query.
Query.Filter innerFilter = new Query.Filter(Group.class);
innerFilter.startsWith(Group_.displayName.equalTo("group01")).or(Group_.displayName.equalTo("group02"));
Query.Filter mainQuery = new Query.Filter(Group.class);
mainQuery.startsWith(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")