Oracle Internet File System Developer's Guide Release 1.1 A75172-04 |
|
This chapter covers the following topics:
Note: Do not confuse Java Server Pages, commonly known as "JSPs," with the Oracle Corporation product called Java Stored Procedures. In the context of this chapter, "JSPs" refers to "Java Server Pages."
One of the advantages of storing documents in the Oracle Internet File System is that users can display dynamic data via the Web simply by entering a URL. For example, in an insurance form application, a user would be able to view an insurance form on the Web.
Java Server Pages (JSPs) are the recommended manner of creating web-based applications based on Oracle iFS. (In fact, the Oracle iFS Web interface uses JSPs.) JSPs display information on the Web by generating HTML documents to call Java Beans. Although JSPs provide a way for users to view and manipulate documents, providing a functionality parallel to that of renderers, using a JSP is not technically "rendering" because it does not involve calling a specific renderer.
Note: You can use either the Java Web Server or the Apache Web Server with Oracle iFS. The Java Web Server included with Oracle iFS 1.1 supports the 1.0 version of the JSP specification. Developers are advised to avoid the use of tag extensions defined by the 0.92 specification.
An insurance form application is used to demonstrate how to use JSPs. Assume that the following preparations have been completed so that there are custom InsuranceForm objects stored in the repository, ready to be displayed using a JSP:
Each application requires a set of files to provide basic security functions:
The sample code for these functions, login.jsp and logout.jsp, provides a reliable starting point for a login/logout mechanism.
For consistent behavior with multiple protocols and sharing login information with the Oracle iFS Web interface, we recommend using the basic approach to login/logout demonstrated in the sample code. Specifically, we recommend that when writing a JSP login facility, you implement the Oracle iFS Java API package oracle.ifs.adk.security.IfsHttpLogin.
For an example of a login JSP and its associated Java Bean, see:
InsuranceLogin.java implements the public interface IfsHttpLogin
.
These sample applications store the minimum login and session information needed by the system to carry user authentication from page to page. Depending on the requirements of your application, you may decide to create a more complex login to store user variables or more extensive session information.
For an example of a simple logout JSP, see "Sample Code: logout.jsp".
The real work of an application is done by one or more JSPs and their corresponding Java Beans:
For a sample JSP file, see "Sample Code: InsuranceForm.jsp". This sample shows a simple user interface; your application may require a more sophisticated user interface.
For a sample Java Bean file, see "Sample Code: InsuranceBean.java".
You must compile the Java Bean and then the JSP before Oracle iFS can call the JSP. Depending on your development environment, the JSP may be automatically compiled at runtime the first time it is invoked.
All compiled Java Beans must be stored in the directory $ORACLE_HOME/ifs/custom_classes
on the server where Oracle iFS is installed.
The Oracle iFS product comes with a starting-point directory structure. One of the folders in that structure is reserved for holding JSPs: $ORACLE_HOME/ifs/jsp-bin
. To have your JSP compile and execute properly in Oracle iFS, you must store the JSP in this folder. JSPs stored elsewhere will not be executed by the Oracle iFS JSP compiler.
Registering a JSP allows the JSP to be used as the default HTML renderer for the specified class.When a user clicks on a plain XML document, the system automatically calls the SimpleXmlRenderer supplied with Oracle iFS. When a user clicks on a custom document for which you have provided a JSP, Oracle iFS needs to know which JSP to use to display documents of this type. To provide this information to Oracle iFS, you must register a JSP before it can be used.
You can use Oracle iFS Manager or XML to register a JSP. Once a JSP has been registered, Oracle iFS automatically invokes that JSP when a user requests a document of a given class and MIME type. Behind the scenes, registering a JSP adds an entry to the existing JSPlookup PropertyBundle, associating a JSP with a specific class and MIME type. For an example, see "Registering a Java Server Page Using Oracle iFS Manager".
Note: Using the Jsplookup PropertyBundle mechanism will meet the requirements of most applications. If your application has complicated requirements in this area, you are free to use a custom method to trigger the use of specific code when a user accesses custom documents.
To associate a JSP with a specific class, Oracle iFS provides a lookup table mechanism called the "Jsplookup PropertyBundle." The Jsplookup PropertyBundle is automatically created during installation.
The Jsplookup PropertyBundle maps a specific class and MIME type to the corresponding JSP. In the best case, both document class and document MIME type are available. Depending on the specific document, however, sometimes only document class or MIME type are available. The Jsplookup PropertyBundle determines which JSP should be used with which class based on all available information about the class, assessed in this sequence:
HTTP authentication is used to control access to web sites. For example:
Assume, for example, that you have a web site with a "Members Only" section. You would want everyone to have access to the web site, but only people with a special password have access to the "Members Only" section.
The HTTP authentication mechanism causes the browser to pop up a dialog window. This dialog window accepts the following input from the user:
Once a valid value has been supplied, this user name/password information is kept with the current session, which allows this user access to all appropriate documents, based on the security provided by the associated ACLs. Note that this user's user name/password information is stored by the browser. Thus, if the user invokes additional instances of the browser, the authentication is also valid for these instances. Until the user exits from all instances of the browser, these access rights are not disabled. This behavior is browser-specific. For example, if a user authenticates using Netscape Communicator, that user does not need to authenticate for any more instances of Netscape Communicator, but will need to provide authentication for an instance of Internet Explorer.
In order to use HTTP authentication, you must substitute your own "index.html" for the default "index.html" in the root directory, so users will go to your web site rather than the Oracle iFS Web interface. When users log in through the Web interface, the Web interface authentication takes precedence over HTTP authentication.
Oracle iFS implements HTTP authentication using Access Control Lists (ACLs). Assume that you have a web site where you want to specify the following access for the "Members Only" section:
To access this restricted section, the user needs to click a "Members Only" button (members.gif
) displayed on the Home page.
To implement HTTP authentication for this web site according the scenario described above, follow this process.
index.html
file in the root (/) directory points to the Oracle iFS Web interface. As part of creating your web site, create a file called index.html
and replace the index.html
file in the root directory with the file that points to your web site.
This HTML page will serve as the HREF for members.gif
.
Assume this new ACL is named "HTTP_Auth." Assign the following rights:
index.html
document created in Step 1.
Now when a user enters the web site and clicks the "Members Only" button, the authentication dialog will be displayed. If the user provides the correct user name and password, that user will gain access to the "Members Only" section.
The Insurance Form application includes three JSPs:
Note: This example includes the recommended mechanism for providing a login facility to Oracle iFS, which is implementing the IfsHttpLogin
interface.
For a brief description of each sample file, see "Sample Files for the Insurance Form Application".
Place the folder tree containing the resulting .class
file in the directory $ORACLE_HOME/ifs/custom_classes
on the server where Oracle iFS is installed.
/public/examples/insuranceApp/src
.
index.html
into /public/examples/insuranceApp
.
CreateInsuranceForm.xml
into any convenient directory.
InsuranceForm.jsp
.
/public/examples/insuranceApp/claims
:
/ifs/jsp-bin
:
http://myIfsServer/public/examples/insuranceApp/src/login.jsp
logout.jsp
.
To run these examples, observe the following requirements:
.java
files.
CLASSPATH
environment variable:
/ifs/jsp-bin
.
This section includes sample code for running the Insurance Form application. The files included are:
This index.html
file is automatically invoked when a user, using a URL, navigates to the folder where this file resides.
<HTML> <!-- index.html --> <HEAD> <META HTTP-EQUIV=REFRESH CONTENT="0; URL=/public/examples/insuranceApp/src/login.jsp"> </META> </HEAD> <BODY> </BODY> </HTML>
This CreateInsuranceForm.xml
file creates a custom document type with two custom attributes, ClaimNumber and ClaimType.
<?xml version = '1.0' standalone = 'yes'?> <!-- CreateInsuranceForm.xml --> <ClassObject> <Name>InsuranceForm</Name> <Superclass Reftype ="name">Document</Superclass> <Attributes> <Attribute> <Name>ClaimNumber</Name> <DataType>Long</DataType> </Attribute> <Attribute> <Name>ClaimType</Name> <DataType>String</DataType> <DataLength>50</DataLength> </Attribute> </Attributes> </ClassObject>
These two files, claim1.xml
and claim2.xml
, are the document files that create two specific instances of the InsuranceForm class.
<?xml version = '1.0' standalone = 'yes'?> <!-- claim1.xml --> <InsuranceForm> <Name>Juana Angeles</Name> <ClaimNumber>35093</ClaimNumber> <ClaimType>Car Accident</ClaimType> <FolderPath>/public/examples/insuranceApp/claims</FolderPath> </InsuranceForm> <?xml version = '1.0' standalone = 'yes'?> <!-- claim2.xml --> <InsuranceForm> <Name>Kevin Chu</Name> <ClaimNumber>41111</ClaimNumber> <ClaimType>Car Accident</ClaimType> <FolderPath>/public/examples/insuranceApp/claims</FolderPath> </InsuranceForm>
This login.jsp
file is a JSP that provides for user login and validation. It calls the InsuranceLogin.java
file. Note that "IfsHttpLogin" is the default login Bean name used for the Oracle iFS Web interface.
<%@ page import = "ifsdevkit.sampleapps.insurance.InsuranceLogin" %> <%@ page import = "oracle.ifs.adk.security.IfsHttpLogin" %> <html><head> <jsp:useBean id="inslogin" scope="session" class="ifsdevkit.sampleapps.insurance.InsuranceLogin" /> <jsp:setProperty name="inslogin" property="*"/> <% String REDIRECT_PATH = "/public/examples/insuranceApp/claims"; boolean loggedIn = false; if (inslogin.getSession() != null && inslogin.getResolver() != null) { // Use existing insurance login loggedIn = true; } else { // No existing insurance login IfsHttpLogin login = (IfsHttpLogin) request.getSession(true).getValue("IfsHttpLogin"); if (login != null && login.getSession() != null && login.getResolver() != null) { // Use existing IfsHttpLogin login inslogin.init(login.getSession(), login.getResolver()); loggedIn = true; } } if (!loggedIn) { String username = request.getParameter("username"); String password = request.getParameter("password"); if (username != null && password != null) { // Login using username/password try { inslogin.init(username, password, "IfsDefault"); request.getSession(true).putValue("IfsHttpLogin", inslogin); loggedIn = true; } catch (Exception e) { %> <SCRIPT LANGUAGE="JavaScript1.2"> alert("The username or Password was not valid, please try again."); </SCRIPT> <% } } } if (loggedIn) { // Redirect to the directory where the claim files reside response.sendRedirect(REDIRECT_PATH); } else { %> <title>Insurance Demo App Login</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF"> <form METHOD=POST NAME="loginform" ACTION="login.jsp"> <table> <tr> <td><b>Username:</b></td> <td><input type="text" name="username" value=""></td> </tr> <tr> <td><b>Password:</b></td> <td><input type="password" name="password" value=""></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> <input type="submit" value="Log in"> </td> <td> <input type="reset" value="Reset"> </td> </tr> </table> </form> </body> </html> <% } %>
This sample file, InsuranceLogin.java
, creates the Java Bean that is called by login.jsp
, the corresponding JSP. This Java Bean implements the standard Oracle iFS login interface, IfsHttpLogin
.
/* --InsuranceLogin.java-- */ package ifsdevkit.sampleapps.insurance; import java.util.Locale; import javax.servlet.http.HttpSessionBindingEvent; import oracle.ifs.beans.DirectoryUser; import oracle.ifs.beans.FolderPathResolver; import oracle.ifs.beans.LibrarySession; import oracle.ifs.beans.LibraryService; import oracle.ifs.common.CleartextCredential; import oracle.ifs.common.ConnectOptions; import oracle.ifs.common.IfsException; import oracle.ifs.adk.security.IfsHttpLogin; /** * The login bean for the Insurance demo app. * <p> * This class provide the login info. The class implements the * <code>IfsHttpLogin</code> interface so it can share login data with other * login beans. * * @see IfsHttpLogin */ public class InsuranceLogin implements IfsHttpLogin { /** * The <code>LibrarySession</code>. */ private LibrarySession m_session; /** * The <code>FolderPathResolver</code>. */ private FolderPathResolver m_resolver; /** * Default constructor required by the jsp spec for the USEBEAN tag * * @exception IfsException */ public InsuranceLogin() throws IfsException { } /** * Make a connection to iFS * * @param username The username to be used for login. * * @param password The password to be used for login. * * @param server The server to be used for login. * * @exception IfsException if operation failed. */ public void init(String username, String password, String serviceName) throws IfsException { LibraryService service = new LibraryService(); CleartextCredential me = new CleartextCredential(username, password); ConnectOptions connection = new ConnectOptions(); connection.setLocale(Locale.getDefault()); connection.setServiceName(serviceName); m_session = service.connect(me, connection); m_resolver = new FolderPathResolver(m_session); m_resolver.setRootFolder(); DirectoryUser user = m_session.getDirectoryUser(); if (user.isAdminEnabled()) m_session.setAdministrationMode(true); } /** * Initialize the login bean. * <p> * The default constructor does not set the necessary fields so it needs * to be set instantiation. * * @param session The <code>LibrarySession</code> object. * * @param resolver The <code>FolderPathResolver</code> object. * */ public void init(LibrarySession session, FolderPathResolver resolver) { m_session = session; m_resolver = resolver; } /** * Return the login's session object. * * @return The <code>LibrarySession</code> object. */ public LibrarySession getSession() { return m_session; } /** * Return the login's path resolver. * * @return The <code>FolderPathResolver</code> object. */ public FolderPathResolver getResolver() { return m_resolver; } /** * Called when this object is bound to the HTTP session object. * * @param event The event when the object is bound to the Http session. */ public void valueBound(HttpSessionBindingEvent event) { // do nothing } /** * Called when this object is unbound from the HTTP session object. * * @param event The event when the object is unbound to the Http session. */ public void valueUnbound(HttpSessionBindingEvent event) { m_resolver = null; try { if (m_session != null) { m_session.disconnect(); } } catch (IfsException e) { e.printStackTrace(); } finally { m_session = null; // release the resources } } }
This sample file, logout.jsp
, is a JSP that provides for user logout and a graceful exit from the program.
<%@ page import = "ifsdevkit.sampleapps.insurance.InsuranceLogin" %> <%@ page import = "oracle.ifs.adk.security.IfsHttpLogin" %> <html><head> <% Object login = request.getSession(true).getValue("inslogin"); if (login != null) { // Remove insurance login request.getSession(true).removeValue("inslogin"); Object ifsLogin = request.getSession(true).getValue("IfsHttpLogin"); if (ifsLogin != null && ifsLogin == login) { // Only remove IfsHttpLogin if it is the same login bean // Remove IfsHttpLogin login request.getSession(true).removeValue("IfsHttpLogin"); } } %> <title>Insurance Demo App Logout</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF"> <form METHOD=POST NAME="logout" ACTION="login.jsp"> <table> <tr> <td><h3>You are now logged out.</h3></td> </tr> <tr> <td> </td> </tr> <tr> <td> <input type="submit" value="Log in"> </td> </tr> </table> </form> </body> </html>
To register a Java Server Page using Oracle iFS Manager, follow these steps:
To register a JSP, specify the following three attributes:
This sample file, RegisterJSP.xml
, registers a JSP, associating the JSP with a specific classname and MIME type.
To register a JSP using XML, write an XML file to update the JspLookup PropertyBundle, adding a mapping between a specific classname and MIME type (INSURANCEFORM.*/*
) and its associated JSP (InsuranceForm.jsp
).
<?xml version="1.0" standalone="yes"?> <!--RegisterJSP.xml--> <PROPERTYBUNDLE> <UPDATE RefType="valuedefault">JspLookup</UPDATE> <PROPERTIES> <PROPERTY ACTION="add"> <NAME>INSURANCEFORM.*/*</NAME> <VALUE DataType="String">/ifs/jsp-bin/InsuranceForm.jsp</VALUE> </PROPERTY> </PROPERTIES> </PROPERTYBUNDLE>
This sample file, InsuranceForm.jsp
, includes the following:
InsuranceBean.java
, which provides the information from the insurance form stored in the repository.
<HTML> <!-- InsuranceForm.jsp--> <%@ page import="ifsdevkit.sampleapps.insurance.InsuranceBean" %> <%@ page import="oracle.ifs.beans.LibrarySession" %> <%@ page import="oracle.ifs.beans.FolderPathResolver" %> <%@ page import="oracle.ifs.adk.security.IfsHttpLogin" %> <jsp:useBean id="ibean" scope="session" class="ifsdevkit.sampleapps.insurance.InsuranceBean" /> <jsp:useBean id="inslogin" scope="session" class="ifsdevkit.sampleapps.insurance.InsuranceLogin" /> <HEAD> <TITLE>Oracle iFS</TITLE> </HEAD> <BODY> <% LibrarySession sess = null; FolderPathResolver resolver = null; if (inslogin != null && inslogin.getSession() != null && inslogin.getResolver() != null) { sess = inslogin.getSession(); resolver = inslogin.getResolver(); } else // Not logged in the Insurance App but may be logged in other application. { IfsHttpLogin login = (IfsHttpLogin)request.getSession(true).getValue("IfsHttpLogin"); if (login != null && login.getSession() != null && login.getResolver() != null) { sess = login.getSession(); resolver = login.getResolver(); } } String path = request.getParameter("path"); if (path == null || sess == null || resolver == null) { response.sendRedirect("/ifs/jsp-bin/ifsdevkit/sampleapps/insurance/login.jsp"); } else { ibean.init(sess, resolver, path); %> <TABLE> <TR> <TH ALIGN="left">Name:</TH><TD ALIGN="left"><%= ibean.getName() %></TD> </TR> <TR> <TH ALIGN="left">ClaimType: </TH><TD ALIGN="left"> <%= ibean.getClaimType() %> </TD> </TR> <TR> <TH ALIGN="left">ClaimNumber: </TH><TD ALIGN="left"> <%= ibean.getClaimNumber() %> </TD> </TR> </TABLE> </BODY> </HTML> <% } %>
This sample code, InsuranceBean.java
, creates the JavaBean that is called by InsuranceForm.jsp
, the corresponding JSP. This JavaBean retrieves three attributes of the insurance form: Name, ClaimNumber, and ClaimType.
/*---InsuranceBean.java---*/ package ifsdevkit.sampleapps.insurance; import oracle.ifs.beans.ClassObject; import oracle.ifs.beans.DirectoryUser; import oracle.ifs.beans.FolderPathResolver; import oracle.ifs.beans.LibrarySession; import oracle.ifs.beans.PublicObject; import oracle.ifs.common.AttributeValue; import oracle.ifs.common.IfsException; public class InsuranceBean { /** * The name for the claim. */ protected String m_name; /** * The type of the claim. */ protected String m_claimType; /** * The claim number. */ protected Long m_claimNumber; /** * Constructor */ public InsuranceBean() { } /** * Initialize the bean and populate the necessary fields. * * @param session The <code>LibrarySession</code> object. * * @param resolver The <code>FolderPathResolver</code> object. * * @param path The path to the insurance object. * * @exception IfsException Thrown if operation failed. */ public void init(LibrarySession session, FolderPathResolver resolver, String path) throws IfsException { try { PublicObject insuranceObj = resolver.findPublicObjectByPath(path); ClassObject co = insuranceObj.getClassObject(); m_name = insuranceObj.getName(); AttributeValue av = insuranceObj.getAttribute("CLAIMTYPE"); if (!av.isNullValue()) { m_claimType = av.getString(session); } av = insuranceObj.getAttribute("CLAIMNUMBER"); if (!av.isNullValue()) { m_claimNumber = new Long(av.getLong(session)); } } catch (IfsException e) { e.printStackTrace(); throw e; } } /** * Return name for the claim. * * @return The claim name. */ public String getName() { return m_name; } /** * Return the claim type. * * @return The claim type in a <code>String</code>. */ public String getClaimType() { return m_claimType; } /** * Return the claim number. * * @return The claim number as a <code>Long</code>. */ public Long getClaimNumber() { return m_claimNumber; } }
|
Copyright © 2000 Oracle Corporation. All Rights Reserved. |
|