User and group administrator can be done programmatically via the API instead of always going to the EDAB home page. API calls are available to create, edit, and delete users and groups.
Both EDABOrganizer.jar
and EDABServer.jar
(in the <EDAB-installation-directory>/lib
directory) needs 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 it.
Also, note that if you have applets that use EDAB Report API, the browser must have JVM plugin at least version 1.5 or higher.
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 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.
Use this following method to create a new 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");
Use this following method to create a new group:
public void createGroup(String newGroup, String description, String[] users)
For example:
userGroupProperties.createGroup("testinggroup", "For testing purpose only", new String[]{"admin", "jDoe"});
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.
You can also delete any users/groups through the code in the same manner.
Use this following method to delete a user:
public void deleteUser(String[] users)
For example:
userGroupProperties.deleteUser(new String[] {"jdoe"});
Use this following method to delete a group:
public void deleteGroup(String[] groups)
For example:
userGroupProperties.deleteGroup(new String[] {"testinggroup"});
The above code deletes jdoe
user and testinggroup
group. Note that the user and group have to exist before they can be deleted.
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):
Page to be redirected to if login is successful.
Page to be redirected to if login is not successful.
username to be passed.
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 an empty .jsp
page. Note that myLogin.html
has to be created as well.
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 into 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 in. If it is a different user, the original datasource will be used.
Javadoc for the entire API is provided along with EDAB. It is located here (server functions).