Show TOC

User Management Functions for GroupsLocate this document in the navigation structure

Prerequisites

  • You have referenced the user management development component tc/je/usermanagement/api in your project.

    More information: Defining Development Component Dependencies .

  • For any functions that require write access to attributes, you have configured the relevant data sources of the user management engine (UME) for read-write access.

  • For the purpose of the example class, you have created a user with the user ID demo_user

Context

This section provides an example of how to add user management functions for groups. This section demonstrates the following functions:

  • Creating groups

  • Assigning users to groups

  • Editing group attributes

  • Searching for groups

  • Displaying groups

  • Deleting groups

Procedure

  1. Import the required interfaces: com.sap.security.api.* .
  2. Get the required factories.

    Use the following table to determine the factories you need.

    Factory

    When Required

    Method to Get

    IGroupFactory

    Always

    getGroupFactory()

    IPrincipalFactory

    To access group attributes not directly available through the group factory or to use simple search.

    getPrincipalFactory()

    IRoleFactory

    To assign groups to roles

    getRoleFactory()

    IUserFactory

    To assign users to roles

    getUserFactory()

  3. Add methods for the required functions.

Example

This code example provides a framework for you to plug in the example code from the group tasks in the sections that follow. This class imports the required interfaces, sets up the group management methods, and gets the required factories of the UME API.

package com.example;

import com.sap.security.api.*;

public class GroupTest {
	
	public static void main() {
		init();
		createGroup("demo_group", "This group is for demo purposes.");
		modifyGroup_setAssignment("demo_group", "demo_user");
		modifyGroup_additionalAttribute("demo_group", "com.example", "myAttributeName",
			"myValue");
		groupStandardSearch("com.example", "myAttributeName", "myValue");
		groupSimpleSearch("demo_group");
		showGroup("demo_group", "com.example", "myAttributeName");
		deleteGroup("demo_group");
		} 

	// TODO: Add the method for the group function you want to test.  	
	
	// --------------------------------------------------------------------------------
	
	/*
	 * You only need the user factory for group assignment.
	 * You only need the principal factory for reading and editing group attributes.
	 */
	
	static IUserFactory userFactory;  
	static IGroupFactory groupFactory;
	static IPrincipalFactory principalFactory; 	
	 	
	public static void init() {
		// Get the factories.
		userFactory = UMFactory.getUserFactory();
		groupFactory = UMFactory.getGroupFactory();
		principalFactory = UMFactory.getPrincipalFactory();
	}

}