7.3. Managing Users and Groups

7.3.1. Introduction

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

Both ERESOrganizer.jar (located in the ERES/lib directory) and ERESServer.jar (located in the ERES/WEB-INF/lib directory) need to be added to the CLASSPATH for any code using ERES Organizer. The following snippet shows how to connect to ERES Organizer:

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

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

All examples and code given in the manual assume that ERES 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 ERES Report API, the browser must have at least a 1.5 JVM plugin.

7.3.2. Users and Groups

You do not have to use the ERES 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);
      
[Note]Note

The code must log to ERES 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.3.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

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.3.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.3.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 ERES (rather than having to login twice, once for your application and the other for ERES).

To pass in the login information, you would need to pass the following parameters to authenticate.jsp (located in the root ERES 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="middle" align="right">User Name: </td>
                        <td align="left"><input type="text" name="username"></td>
                        </tr>

                        <tr>
                        <td width=80 valign="middle" 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 ERES directory and copy the contents to a empty .jsp page. Note that myLogin.html has to be created as well.

7.3.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 ERES 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 <ERES-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 the ServerCommands= line of the QB.properties INI file:

-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, then the original datasource will be used.

7.3.5. Javadoc

Javadoc for the entire API is provided along with ERES. It is located here (Reports and charts) and here (ES functions).

7.3.6. Summary

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

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