268 eClient 101 Customization and Integration
Figure 12-4 Creating test user ID using the new privilege set
12.3 Checking for privileges in a JSP
This section describes how to check for privileges with the sample code provided
in the redbook. There are three pieces of code included and described here:
The sample code you can place in your JSP or servlet to query a custom
privilege.
XYZPrivsData.java, a simple Java class that defines a data structure used by
XYZPrivsMethods.java.
XYZPrivsMethods.java, a Java class that contains the code that can be called
by your custom eClient application to check to see if a custom privilege is set
or not.
Chapter 12. Using EIP custom privileges 269
12.3.1 Installing sample code
There are two ways to add XYZPrivsData.java and XYZPrivsMethods.java to
your eClient project: using WebSphere Studio Application Developer or using the
command line.
Using WebSphere Studio Application Developer
You can install the sample code using WebSphere Studio Application Developer:
1. Add the files XYZPrivsData.java and XYZPrivsMethods.java to the project.
a. Open the eClient project in WebSphere Studio Application Developer.
b. Select File -> Import.
c. Select File System, click Next.
d. Navigate to the directory containing the com directory with the source files.
The com directory should have subdirectory named XYZUtils which
should contain the Java files.
e. Browse to or enter eclient82\Java Source in the destination folder field.
f. Click Finish.
2. Copy IDMSearchToolbar-Privs.jsp to IDMSearchToolbar.jsp. You can do this
by copying it using the file system, or by cutting and pasting the code using
the WebSphere Studio Application Developer editor.
3. Restart the WebSphere test environment. Anytime the Java files are
changed, you must restart the WebSphere Studio Application Developer test
environment so the changes take effect.
Using command line
You can install the sample code using the command line:
1. Build the class files for each Java file.
2. Locate the eclient82.ear directory in the WebSphere installedApps directory.
3. Locate the eclient82.war\WEB-INF\classes directory
4. Create a com\XYZUtils directory under the classes directory
5. Copy the class files to that directory.
6. Copy IDMSearchToolbar-Privs.jsp to IDMSearchToolbar.jsp in the
eclient82.war directory.
7. Restart the WebSphere test environment. Anytime the Java files are
changed, you must restart the WebSphere Studio Application Developer test
environment so the changes take effect.
270 eClient 101 Customization and Integration
12.3.2 Checking custom privileges
In this section, we present the code snippet that checks custom privileges.
You can use the results of the query to control access to your custom
functionality as follows:
1. Add the following to the import statement:
com.XYZUtils.XYZPrivsData,
com.XYZUtils.XYZPrivsMethods
2. Add the source code shown in Example 12-1 to your JSP or servlet.
The sample code first checks to make sure you are using the federated
connector. If not, custom privilege is not supported. After that, it uses
getPrivDefs() to load all the privileges, and then uses isAuthorized() to check
whether the custom export privilege is set. See the comments within the code
for a detailed explanation.
Example 12-1 Code snippet to check custom export privilege
// XYZ_CHG_BEGIN
//
// Check to s ee if custom privileges are set. This code works for federated
// layer only.
boolean blnExport = true;
if (connection.getDsType().equalsIgnoreCase("FED"))
{
XYZPrivsMethods XYZPrivs = new XYZPrivsMethods();
// Load privilege IDs for XYZ_PRIV_GRP_MAIN
XYZPrivs.getPrivDefs(connection,XYZPrivs.XYZ_PRIV_GRP_MAIN);
// Check to see if current user has a specified privilege.
blnExport = XYZPrivs.isAuthorized(connection, XYZPrivs.XYZ_PRIV_EXPORT_DOCS
);
}
else
{
System.out.println("Custom privileges only supported with federated
connector");
}
System.out.println("Value of blnExport is " + blnExport );
12.3.3 Source file XYZPrivsData.java
The source code for this file is available with the redbook. This file contains only a
simple data structure that is used by XYZPrivsMethods.java. Example 12-2 on
page 271 shows the source code for XYZPrivsData.java.
Get eClient 101 Customization and Integration now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.