This documentation is for WSO2 App Factory 2.0.0. View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

The sample is described in the following topics:


This sample demonstrates how to create and launch your own application that calls WSO2 Carbon user management APIs and saves/deletes users to/from the LDAP user stores of App Factory.


Set up App Factory using the instructions given in section Getting Started.

Executing the sample

  1. Log in to the App Factory portal, and create a new Web application by clicking Add New Application
  2. Install GIT in your environment.
  3. Copy the Repository URL that appears on the application's Overview page and create a folder in your machine to check out the code to.

  4. Using the command prompt, navigate to the location where you want to check out the code to and ch eck out the application's source code as follows:

    git clone <URL of the master repository copied earlier>
  5. The code is cloned inside a folder by the name of the application. Open the pom.xml file in the folder and copy the values of the following elements:

    • <groupId>
    • <artifactId>
    • <version>
    • <packaging>
  6. Copy the sample files found in  <AF_HOME>/samples/UserRealmSample/directory. You can also find the same content here: samples/UserRealmSample . Choose to replace all files if asked.
  7. After copying files, open the new pom.xml file in the folder and set the values of <groupId> , <artifactId> , <version> and <packaging> elements to the values you copied in step 5.
  8. Add, commit and push your changes to the remote repository using the following commands:

    git add <file or folder path>
    git commit -am "commit message"
    git push origin master

    By default, applications are automatically built and deployed when a commit happens.

  9. Go to the Repositories and Builds tab and click the Launch button to start the application. The application starts as follows:

    Shown below is how the sample userstore-manager.jsp file calls the user manager APIs.

    // get user realm from thread local carbon context
       UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
    // get user store manager
       UserStoreManager userStoreManager = userRealm.getUserStoreManager();
    // below sample use few methods of user store manager API. You can use all methods to build your application.
        String username = request.getParameter("username");
        String role = request.getParameter("role");
        String action = request.getParameter("action");
        if (action != null) {
            if (action.equals("deleteUser")) {
                out.println(username + " user is successfully deleted.");
            } else if (action.equals("deleteRole")) {
                out.println(role + " is role successfully deleted.");
            } else if (action.equals("addUser")) {
                userStoreManager.addUser(username, "password", null, null, null);
                out.println(username + " user is successfully added.");
            } else if (action.equals("addRole")) {
                userStoreManager.addRole(role, new String[]{username}, null);
                out.println(role + " role is successfully added.");

  10. You can add/delete users and roles to/from the system using this application. 

  • No labels