Chapter 7. Programming

7.1. Managing Users and Groups

7.1.1. Introduction

User and group administrator can be done programmatically via the API rather instead of always going to the EDAB home page. API calls are available to to create, edit, and delete users and groups.

Both EDABOrganizer.jar and EDABServer.jar (in the <EDAB-installation-directory>/lib directory) need to be added to the CLASSPATH for any code using EDAB Organizer. The following snippet shows how to connect to EDAB Organizer:

QbOrganizer.setServletRunner("http://localhost:8080");
QbOrganizer.setServletContext("EDAB/servlet");
QbOrganizer organizer = new QbOrganizer(null, "admin", "admin");
        

The above code sets the connection information to connect to EDAB Server and provides the username and password (in the above example, admin and admin) for EDAB Organizer.

All examples and code given in the manual assume that EDAB server is running locally (i.e., on your local machine) and on port 8080. You can change this by going to the source code (you can download the source code by clicking on the Full Source Code link in the corresponding chapter), editing the code to enter the new connection information, and recompiling the code.

Also, note that if you have applets that use EDAB Report API, the browser must have at least a 1.5 JVM plugin.

7.1.2. Users and Groups

You do not have to use the EDAB Admin console to create, edit, and/or delete user and group information. You can modify any user and/or group information via the API. Note that only the admin user can call the API methods.

To modify the user and group information, you must get a handle to UserGroupProperties using the following call:

UserGroupProperties userGroupProperties = new UserGroupProperties(organizer);
        

Please note that the code must log to EDAB as the admin user otherwise the user/group information will remain unchanged. Any username and/or group name must be in lowercase. Uppercase and mixed case names are converted to lower case automatically.

7.1.2.1. Creating Users and Groups

You would use the following method to create a user:

public void createUser(String userName, String fullName, String email, String password, String role, String securityLevel)
            

For example:

userGroupProperties.createUser("jdoe", "John Doe", "jDoe@somedomain.com", "123", IUser.ROLE_DESIGNER, "manager");
            

While the following method to create a group:

public void createGroup(String newGroup, String description, String[] users)
            

For example:

userGroupProperties.createGroup("testinggroup", "For testing purpose only", new String[]{"admin", "jDoe"});
            

Full Source Code

Result Screenshot

The above code creates a new user jdoe along with a new group testinggroup. The user profile information as well as group information is also passed via the code.

7.1.2.2. Deleting Users and Groups

You can also delete any users/groups through the code in the same manner.

You would use the following method to delete a user:

public void deleteUser(String[] users)
            

For example:

userGroupProperties.deleteUser(new String[] {"jdoe"});
            

While the following method to delete a group:

public void deleteGroup(String[] groups)
            

For example:

userGroupProperties.deleteGroup(new String[] {"testinggroup"});
            

Full Source Code

Result Screenshot

The above code deletes jdoe user and testinggroup group. Note that the user and group have to exist before they can be deleted.

7.1.3. Single Sign-On

You can also have your own custom login page (for example, login to your portal) and then pass the required information to EDAB (rather than having to login twice, once for your application and the other for EDAB).

To pass in the login information, you would need to pass the following parameters to authenticate.jsp (located in the root EDAB install directory):

origPage :

Page to be redirected to if login is successful.

loginPage :

Page to be redirected to if login is not successful.

username :

username to be passed.

password :

password to be passed.

The following example shows the possible contents of a jsp page that is passing the information to authenticate.jsp . Note that in the example, username and password is inputted although you can specify them before calling authenticate.jsp :

<html>

      <head>
      </head>
      <body>

            <form name="Login" action="authenticate.jsp" method="POST">

                  <input type="hidden" name="origPage" value="MenuPage.jsp">
                  <input type="hidden" name="loginPage" value="myLogin.html">

                  <table width=100% cellpadding=2 cellspacing=0>

                        <tr>
                        <td width=80 valign="center" align="right">User Name: </td>
                        <td align="left"><input type="text" name="username"></td>
                        </tr>

                        <tr>
                        <td width=80 valign="center" align="right">Password: </td>
                        <td align="left"><input type="password" name="password"></td>
                        </tr>

                  </table>

                  <input type="image" src="Web_Component/STARTUP/Login.gif" border=0></td>

            </form>

      </body>

</html>
        

The recommended way to run the above code is to go to the root EDAB directory and copy the contents to a empty .jsp page. Note that myLogin.html has to be created as well.

7.1.4. Login Listener

You can also create additional code that changes the datasource (only if the datasource is a database) of the report/chart, based on the user logged onto EDAB at the time. This code extends the LoginListener class and specifies the database connection information, based on the user.

Please note that after creating the code you need to change QB.properties (in the <EDAB-installation-directory>/WEB-INF/classes directory) and add the following argument to the ServerCommands= line:

-LoginListenerClass:<name of class file extending LoginListener>
        

The following code shows how to use the LoginListener class:

      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpSession;

      import quadbase.auth.WebLogin;
      import quadbase.auth.bean.Login;
      import quadbase.reportorganizer.ext.LoginListener;

      public class ExampleLoginListener extends LoginListener {

            public void setUserDatabaseConnection(HttpServletRequest req, String userName) throws Exception {

                  HttpSession session = req.getSession();
                  WebLogin wl = (WebLogin)session.getAttribute(Login.WEB_LOGIN);
                  if (wl == null || wl.getUser() == null) {

                        return;

                  }

                  String user = wl.getUser();
                  if (user.equalsIgnoreCase("user1"))
                  {

                        session.setAttribute(USER_DBURL, "someDatabaseURL1");
                        session.setAttribute(USER_DBDRIVER, "someDatabaseDriver1");
                        session.setAttribute(USER_DBUSERNAME, "someDatabaseUsername1");
                        session.setAttribute(USER_DBPASSWORD, "someDatabasePassword1");

                  } else if (user.equalsIgnoreCase("user2"))
                  {

                        session.setAttribute(USER_DBURL, "someDatabaseURL2");
                        session.setAttribute(USER_DBDRIVER, "someDatabaseDriver2");
                        session.setAttribute(USER_DBUSERNAME, "someDatabaseUsername2");
                        session.setAttribute(USER_DBPASSWORD, "someDatabasePassword2");

                  }

            }

      }
        

To use the above code, add the following to QB.properties (located in the /WEB-INF/classes directory) to the ServerCommands= line:

-LoginListenerClass:ExampleLoginScheduler
        

Make sure that ExampleLoginScheduler is in the CLASSPATH. The code will switch the datasource information to a different database, depending on whether user1 or user2 has logged on. If it is a different user, the original datasource will be used.

7.1.5. Javadoc

Javadoc for the entire API is provided along with EDAB. It is located here (server functions).

7.1.6. Summary

EDAB API provides an easy-to-use and powerful API that can be used in your custom code to administer and manager users and groups in EDAB.

Please note that the API requires a JDK 1.5 or above. The EDAB API has been tested on Windows, Solaris, Linux, AIX, HP, and Mac platforms.