User Provisioning – API

In this Lesson

You will learn about the APIs available for provisioning users.

Concepts

Soiree provides two types of APIs for user provisioning: one for defining the user and another for assigning groups to users.

  1. com.seronix.soiree.security.UserService
    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.

  2. com.seronix.pump.SoireeSecurityManager
    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.
    • SoireeSecurityManager.addGroupsToUser
    • SoireeSecurityManager.removeGroupsFromUser
    • SoireeSecurityManager.getGroupsForUser
    • SoireeSecurityManager.getRightsForUser
    • SoireeSecurityManager.getUsersProvisionedToProduct
    • SoireeSecurityManager.getUsersProvisionedToSolution
    • SoireeSecurityManager.getUsersProvisionedToGroup
    • SoireeSecurityManager.getUsersProvisionedToRight
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)

  1. Right click on the following link and download the file to your computer.

    UserServiceTest.java
  2. Copy the file to the test package



  3. The class makes calls to the UserService API to create and modify a user.



  4. Open the PartyServer definition in preparation for registering your class as a startup operation



  5. Expand the Server Startup Operations section
  6. Right click in the list and add the test.UserServiceTest service



  7. Set a breakpoint in UserServiceTest



  8. Start the server in Debug mode. The server will run your class and the debugger will stop at your breakpoint



  9. Step through the program until the process calls the createUser method
  10. 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 UR
    The with ur directive instructs the query to perform an Uncommitted Read. This allows the query to return data not yet committed to the database.
  11. Stop after each call to the user service and run the query again to see the changes in the database table.
  12. 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.



SoireeSecurityManager API Exercise

You will now use the SoireeSecurityManager API to add groups to the user.

  1. 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

  2. Restart the server
  3. Redisplay the user in the server console and notice the DeleteParty group has been added to the user



  4. Remove test.UserServiceTest from the Server Startup Operations section of the server definition.

That’s all for this lesson.