In this Lesson
You will learn about the APIs available for provisioning users.
Soiree provides two types of APIs for user provisioning: one for defining the user and another for assigning groups to users.
This class provides the API for creating or modifying users.
You obtain a reference to the user service like this
UserService service = new UserService("PRODUCT ID GOES HERE");
You may then call any of the methods supported by the user service.
This class provides the API for managing the user’s groups. It uses static methods so you do not need to create an instance of the class to call its methods.
UserService API Exercise
In this exercise you will create a class which uses the API to create and modify a user. (You will run your class using the technique described here: Custom server startup operations)
- Right click on the following link and download the file to your computer.
- Copy the file to the test package
- The class makes calls to the UserService API to create and modify a user.
- Open the PartyServer definition in preparation for registering your class as a startup operation
- Expand the Server Startup Operations section
- Right click in the list and add the test.UserServiceTest service
- Set a breakpoint in UserServiceTest
- Start the server in Debug mode. The server will run your class and the debugger will stop at your breakpoint
- Step through the program until the process calls the createUser method
- Stop after each call to the user service and run the query again to see the changes in the database table.
- After the process runs to completion and commits the database connection you can sign on to the server console and see the user in the provisioning scene.
Stop after the call to createUser and use DBeaver (or your favorite query tool) to run this query to see the changes in the SoireeUser table
select * from SoireeUser with ur
WITH URThe with ur directive instructs the query to perform an Uncommitted Read. This allows the query to return data not yet committed to the database.
SoireeSecurityManager API Exercise
You will now use the SoireeSecurityManager API to add groups to the user.
- Add the following Java code immediately before the commitAllConnections() call.
//add DeleteParty group List<String> groupList = SoireeSecurityManager.getGroupsForUser(cp, service.getProductId(), 0, userId); groupList.add("com.example.party.group.DeleteParty"); SoireeSecurityManager.addGroupsToUser(cp, service.getProductId(), 0, userId, groupList); //add EditParty group groupList.add("com.example.party.group.EditParty"); SoireeSecurityManager.addGroupsToUser(cp, service.getProductId(), 0, userId, groupList); //remove EditParty groupList.clear(); groupList.add("com.example.party.group.EditParty"); SoireeSecurityManager.removeGroupsFromUser(cp, service.getProductId(), 0, userId, groupList);
The ending portion of the method should now look like this
- Restart the server
- Redisplay the user in the server console and notice the DeleteParty group has been added to the user
- Remove test.UserServiceTest from the Server Startup Operations section of the server definition.
That’s all for this lesson.