Download Exploiting SAS Software Using JAVA Technology

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Exploiting SAS® Software Using Java TM Technology
Barbara Walters, SAS Institute Inc.
Presented by Donald J. Henderson, SAS Institute Inc.
Java programs are often delivered via the Interne!. In order to protect the
local machine from malicious programs, the Java language and the JVM
provide a secure environment for application execution. The secure
environment ensures that the client machine (the machine where the
browser is running) is not corrupted by the downloaded program and that
no information is stolen from the client machine.
Abstract
This paper describes how to use Java'M technology with SAS software.
SAS Institute currently offers several Java development tools that allow
applications to access SAS data and take advantage of SAS
computational capabilities. This paper describes how to use these class
libraries and address clienllserver configuration and performance issues.
Java security is based upon the "sandbox" model. The sandbox is the set
of resources (threads. socket connections, local files, etc.) that the
downloaded Java code is allowed to access. The code is restricted from
accessing resources outside of its sandbox. In executing Java applets,
each Web browser defines the limHs of the sandbox.
Introduction
Since Hs introduction in mid-I995, Java have become an integral part of
the World Wide Web. Java Is a rich programming language that enables
Web programmers to create sophisticated and responsive client/server
applications. Because Java is porIabie and secure. users of Web
applications can be confident that those applications will execute prope~y
and not corrupt their computers.
The Security Manager enforces the limits of the sandbox. For applets, the
Web browser controls the Security Manager. Each browser may put
different restrictions on applet behavior. The default "mils imposed by the
Security Manager are:
•
Classes cannot access the local file system
As part of the SASllntrNet" product. SAS InstHute provides three Java
components:
•
Classes cannot read environment variables
•
Classes cannot execute other programs on the local machine
•
Classes cannot make socket connections to machines other than
the machine from which they were downloaded.
•
•
•
SASISHARE'NET'M Driver for JDBC-a Java class library that
allows Java applications to access SAS data
JConnect-a Java class library that allows Java applications to
create a remote SAS session, submit SAS statements, and retrieve
results generated by the submitted statements
The Web browser provides the Java "core" libraries. These libraries
contain classes that are included with all Java-enabled browsers and may
not be downloaded over the network. The JDBe driver manager is an
example of a core library. It must be available on the local machine; it is
ineligible for download.
JTunnet-a feature that implements HTTP tunneling to extend the
flexibilHy of the SHARE'NET Driver and JConnect classes
By using these components, SAS programmers can make SAS
resources available to a much wider user community via the Web,
All Java classes are included in a ·package: The package is the
hierarchical name associated with the class. Any class whose package
name sta~s with java is considered a core class. The package name
for the JDBC driver manager is java. sql and is, therefore, one of the
core libraries.
Overview of Java
Java is an object-oriented programming language developed by Sun
Microsysterns, Inc. Java source code is compiled to a byte stream. which
is merely a long sequence of bytes. The byte stream is interpreted by the
Java Virtual Machine (JVM). Since Java is interpreted, the code will run
on any platform that has an Implementation of the JVM. This enables Java
programmers to write a single application that will run on many
platforms-the JVM ensures that the program executes properiy on the
receiving machine.
As Java code starts executing. Java classes that are not installed on the
local machine and are not core classes are dynamically downloaded from
a Web server. Classes are loaded as they are needed, so the number of
classes downloaded from the network can be kepi to a minimum.
Downloaded classes are subject to the restrictions imposed by the
Security Manager.
The following is an example of an apple! tag in an HTML document that
loads a Java class called testapplet. class.
Many Web browsers, such as Netscape Navigator and Microsoft's
Internet Explorer, include a version of the JVM as pa~ of the browser.
Applications written In Java that are accessed via an HTML page are
called app/ets. Because applets execute wHhin any JVM-enable Web
browser, they have become a very popular form of portable, secure, and
dynamically loaded Web-enabled application. Most of the topics in this
paper address the creation of Java apple!s as opposed to Java
applications
<applet
code-~testapplet.class"
width=600
height=425>
Figure 1: Sample applet tag
When the browser encounters the applet tag, ~ invokes the JVM and
passes t the name of the applet class. If the apple! class Haelf was
downloaded from the Web server, the SecurHy Manager restricts the
resources for all classes executed as part of the apple!.
Java provides libraries of classes that offer a rich set of functionality.
These include a library for graphical user interface (GUI) components
called AWT (Abstract Window Toolkit), an 110 library, and a network
access library. Java Developer's Kit (JDK) Release 1.1 provides a library
for the JDBC driver manager. These robraries are standard and are
included with the JVM.
WHh JDK 1.1, Java classes may contain digital Signatures. Applet
classes that are downloaded from the Web server and are not dig Hally
signed are considered "untrusted." JDK 1.1 provides a Security API that
allows special privileges for digHally signed apple!s, which are "trusted
371
applets." The production release of JOK 1.1 was made available in
February 1997. Unfortunately, neither Microsoft's Internet Explorer nor
Netscape Navigator have JOK 1.1 support as of the wrfting of this paper,
so the enhanced security manager cannot be addressed in this paper.
ResultSet resultset = statement.executeQuery
("'select columnone from my. table") ;
=-
while (resultset.next()
true)
String columnone, = resultset .getString (1 J.;
System.out.println("Results: ,. + columnOne);
SAS/SHARE*NET Driver for JDBCTM
The SAs/SHARE'NET Driver for JOBC is one of the Java components
provided in the SAS/lntrNet product. A class library that allows Java
applications to access SAS data, the SAS/SHARE'NET Driver uses Ihe
Java Database Connectivity (JOBC) API created by JavaSoft. JOBC is
similar to OOBC, but for the Java environment. Users do not need JOBC
drivers installed on their machines-<lrivers are dynamically downloaded
from a Web server as needed.
catch (SQLException e) {
System.out.println("Exception thrown:
+ e.getMessage(J;
U
Figure 2: Code to Create Objects (continued)
The JOBC API provides an Sal interface to databases. By USing JOBe,
applications and applets can establish a connection to a database server,
submH Sal statements, and obtain resutt sets. Applications can obtain
information about the database (database me tad a t a) and a particular
resutt set (resutt set met a d a t a).
In this code segment, the SAs/SHARE'NET server is running on the
machine named sharenetserver andportnurnber isthe
number olthe port assigned to the SAs/SHARE'NET server. The SOL
statement requests all of the rows for the column named e 0 1 u mnon e
in the table named my. t abl e.
Database metadata contains information about the characteristics of the
database and what data Hcontains. For example, through database
metadata, a program can determine which numeric or string operaticns
can be used in an Sal statement. The program can obtain a list of valid
data types supported by the database. II may ask the names of tables
available from a particular database server, the names of the columns
within those tables, and the type of data contained in each column.
An of the classes for the SAs/SHARE'NET Driver are contained in the
package named COM. 5 as. net. sh are net. The driver Is written
entirely in Java and may be dynamically downloaded from the Web server.
(Please keep in mind that the JOBC driver manager must be available on
the client machine. It may not be dynamically downloaded.)
Although drivers themselves can be downloaded over the network, the
JOBC driver manager must be available on the local machine. The JOBC
driver manager is included with JVMs based on JOK 1.1. JavaSoft
maintains information about JOBC and has the driver manager available
at ~s Web sHe. The SASJSHARE'NET Driver available for download from
SAS Institute's Web site conforms to the JOBC 1.1 API specification
from JavaSoft. (For the URls, see the References at the end of this
document.)
The name of the database metadata class is
java. sql. DatabaseMetaData.ltsupports.severalmethods,
including get S eh e rna s, and get T abl e s. ·Schemas· are
analogous to SAS libraries; "tables" are analogous to SAS data sets. The
SAS/SHARE'NET Driver cannot provide metadata information about a
foreign database such as Oracle. It can only provide this type of
information about the SAS databases.
The Da tab a s eM eta Da t a object can be created after a connection
has been established to the database (i.e., a
j a va. sql . Conne c t ion object has been created).
Using the SASISHAREWET Oriver for JOSe
Databases are accessed through a unique style of URL that is defined for
JOBC. Each database protocol has a unique URl registered with
JavaSoft for use wHh JDBC. The format of the URl for the
SAs/SHARE'NET Driver is
The result set metadata class
j a va. s q 1. Resul t SetMeta Da ta provides methods for
obtaining number of columns, column names, labels, and other
characteristics of a particular result set. The
Re suI t S e tMe t a Da t a object can be created from any
Resul tSet Object.
jdbc:sharenet:/lhost:port.
Figure 3 depicts a typical configuration for an untrusted applet accessing
a remote SAS/SHARE'NET server.
The name h 0 s t indicates the TCPJlP address of the machine where the
SASISHARE'NET server is running and po r t references the port
number assigned to the server.
The code in Figure 2 creales all of the objects required to submit an Sal
query and retrieve resuRs. (This code segment is simplified and will not
compile properly as is.)
Code example:
import
import
import
import
import
import
java.sql.Connection;
java.sql.Driver;
java.sql.ResultSet;
java.sql.ResultSetMetaData:
java.sql.SQLException;
java.sql.Statement;
try {
Driver driver = (DriverlClass.forName
(" COM.sas. net. sharenet. ShareNetDri ver")
.newlnstance();
Connection connection = driver.connect
("jdbc:sharenet:!!sharenetserver:portnumber"',
properties l ;
Statement statement
Figure 3: Untrusted Applet Accessing Remote Server
The Web browser on the client machine requests an HTMl document
from the Web server. The document arrives at the client machine and the
browser detects theapplet tag In the HTMl document. The browser
invokes the JVM and passes the name of the applet class to the JVM.
The applet class is then downloaded from the Web server and starts
executing.
=
connection.createStatement();
Figure 2: Code to Create Objects
The Java class loader requests the SASJSHARE'NET Driver class file
from the Web server. The driver class creates a
java. sql. Connection object that establiShes a socket
372
connection with the SASISHARE"NET server. It Is not a requirement that
JDSC drivers use a socket interface, but that Is the defau~ for our driver.
cmdprompt,
sascmd =- sascmd.
/* command prompt
portprompt,
The Connection object sends the SOL queries to the SASiSHARE"NET
server and the server sends ~ response via the socket interface. The
I;
Connection object communicates directly with the SASISHARE"NET
server.
String lines = tconnection.getLogLines(};
System.out.prlntln(llnes);
It is very important to note that the Web server and SASISHARE"NET
server are running on the same physical machine. If the applet is
untrusted and the SASISHARE"NET server is not located on the same
machine as the Web server, the socket connection is disallowed and a
Security Exception is thrown. This is a restriction imposed by the default
Java Security Manager, not a restriction imposed by our driver.
} catch (Exception e) {
System.out.println(e.getMessage());
I
Figure 4: Code to Start SAS Session wiith
TelnetConnectClient (continued)
Note: We provide a feature that implements HTIP tunneling to allow the
Web server and SASISHARE"NET server to reside on different
machines. For more information, see the"JTunnel" section in this paper.
The TelnetConnectCl ient communicates with either the
Telnet daemon or the SASJCONNECT spawner program on the remote
host. The TelnetConnectClient uses the variables passed to
the connect method to log in a user identified by userid and start a
SAS session using the sas cmd variable. The documentation provided
with the package will describe how each of the parameters is used.
The SASiSHARE"NET Driver for JOSC also supports access to foreign
databases such as Oracle. Sy setting properties for the Connection
object, a programmer can specify another database. The properties
named dbms and dbms_options allow the programmer to specify
the database and the options needed for connecting to that database.
The code segment in Figure 5 shows how to submit statements that
compute the mean value from column abc in data set xyz and create a
new data set called resul ts, obtain the list output, and print the list
output to standard out.
JConnect
Another component of the SASllntrNet product is JConnect. JConnect Is
a set of Java classes that allow an applet to create a remote SAS session,
submit SAS statements, and retrieve results. The classes also provide
support for downloading files and communicating with SCl objects (see
"Advanced JConnect Features").
Code Example:
String lines
=
new String
means data-xyz mean;
var abc;
(~'proc
The JConnect classes provide a subset of the functionality of a
SASICONNEC-r' client. Sample applets that use JConnect classes to
access a remote SAS session are available from the SAS Institute Web
site. (See the References" seelion for the site URL.)
output out=results;
run;'"');
tconnection.rsubmit(linesl;
Several different mechanisms are available to start a remote SAS
session. We provide a CGI program to start SAS on a remote system and
we provide a Java class that starts a SAS session using telnet. The Java
class that starts the SAS session is named
TelnetConnectClient.
String logLines
=
tconnection.getLogLines();
String listLines = tconnection.getListLines();
System.out.println(listLines);
Figure 5: Code to Create Data Set and Print Results
The code segment in Figure 4 shows how to create a SAS session using
the TelnetConnectClient class. The example code starts the
remote SAS session on the machine named myhos t and retrieves the
log lines generated by SAS software initialization.
Access to SAS data is provided through a Single User server. A method
getSingleUserServer starts the server in the remote session.
The Single User server is made available as a J DBC Connection object.
Code example:
The code segment in Figure 6 shows how to start a Single User server
and retrieve the contents of a data set.
import COM.sas.net.connect.TelnetConnectClient;
Code Example:
String
String
String
String
host = new String ("myhost");
loginprompt = new String ("logon:");
passwordprompt = new String("Password:");
port prompt = new String- C'" PORT=") ;
String cmdprompt = new String ("'rnyhost>U) ;
String sascrnd = new String("sas -dmr");
String userid = new String ("myid .... ) ;
java.sql.Connection suServer
=
tconnection.getSingleUserServer{);
Statement statement =
suServer.createStatement();
ResultSet resultset =
String password = new String (""password") ;
statement .·executeQuery
'''~select x from work. results") ;
try {
TelnetConnectClient tconnection
new TelnetConnectClient();
tconnection. connect (
host,
/* host
loginprompt,
1* login prompt
while {resultset.next{} == true)
String x = resultsetagetString(l);
userid,
/* login id
passwordprompt,
/~
password,
/* password
password prompt
*/
1* command to enter */
/* port prompt
*/
Figure 6: Code to Start Server Using TelnetconnectClient
*/
This example uses the TelnetConnectClient object named
tconnection to start the Single User server and return the
java. sql. Connection object. The
java. sql • Connection object is used to retrieve the contents of
the data set named WORK • RESULTS generated in the previous
*/
*/
~/
*/
example.
Figure 4: Code to Start SAS Session wiith TelnetConnectClient
The classes that provide remote computing services communicate with a
remote SAS session in a very similar manner to the SASISHARE"NET
Driver for JOSC. By starting the remote SAS session with the -OMR
option, the remote SAS session is listening on a particular port. The Java
classes establish a socket connection to that port and exchange
messages with the remote SAS session.
373
Figure 7 depicts an apple! communicating with a remote SAS session.
Since applet classes are assumed to be downloaded from the Web
server, the security restrictions apply and the remote SAS session must
run on the same machine as the Web server.
IClient machine
JTunnel
We find the requirement of having an Web server available on each
machine that has a SAs/SHARE'NET server or a remote SAS session to
be quite restrictive. In addition, many Intemet users are behind firewalls
that will not allow socket connections to machines outside of the firewall.
We provide a solution to both of these problems through 'HTTP
tunneling."
Iserver machine
'Tunneling" refers to the practice of encapsulating a communication
protocol within another protocol. By using a combination of CGI programs
and Java classes that provide HTTP protocol support, we are able to
encapsulate the proprietary protocol used by the SAS/SHARE'NET
Driver and remote SAS session in HTTP requests and HTTP responses.
In other words, the proprietary SAS protocol is wrapped in HTTP. We call
this feature JTunnel.
Web browser
Many lirewalls anow HTTP protocol to pass through. Since the SAS
protocol can be wrapped in HTTP, many userS that previously could not
access remote SAS services now can, if the applet makes use of HTTP
tunneling.
Figure 8 below depicts the components needed for HTTPtunneling.
The SAS connection object (either a Jconnect or SHARE'NET Driver
connection object) supports a property that is a URl to a CGI program
installed on the Web server machine. We refer to this CGI program as the
SAS Message Router (shrcgi). If this property is set, the connection
object will emit HTTP requests rather than use a socket connection. The
SAS Message Router passes the HTTP request to the SAS Protocol
Interpreter(shrproc). If the SAS Protocol Interpreter is not currently
running, the SAS Message Router starts it.
Figure 7: Applet Communicating with Remote SAS Session
Advanced JConnect Features
Two adVanced features of JConnect are the abDity to download files,
which enables integration of graphics, and the ability to communicate with
SCl objects.
The SAS Message Router is a CGI program that is run each time a
request is sent from the SAS connection object. It is not a persistent
process. The SAS Protocol Interpreter is a persistent process that
maintains connections to the remote SAS session (If JConnect is used) or
to the remote SHARE"NET Server (if the SHARE"NET Driver is used).
GraphiCS are provided by generating VRMl (Virtual Reaflty Modeling
language) files through graphics drivers and using the Java classes that
render VRML. The capability to download files alloWS JConnect to place
Into memory a VRMl file (created using SAs/GRAPH'" procedures), then
pass the file to a VRMl-enabied browser.
The SAS Protocol interpreter opens and maintains a socket connection to
the remote SAS session and sends the messages received in the HTTP
requests to the appropriate SAS session. The response from the remote
SAS session is received by the SAS Protocol Interpreter from the socket
connection. The SAS Protocollnterprater wraps the SAS response in an
HTTP response that is sent back to the SAS connection object via the
SAS Message Router.
In communicating with SCl objects, JConnect creates a remote SCl
object, calls methods on the Object, and retrieve the results from the
method can. For example: there Is an SCl object called
Ca tal og I n f 0 which supports a method called get Co n ten t s.
The method get Con ten t s accepts a character siring which is the
name of the catalog and retums an SCl list that contains the names of
the entries. By using JConnect, the applet (or application) can instantiate
Cat a log I n f 0 on the remoteSAS session and call
Stringl]entries-getContents("MY.CATALOG"I.
The Java applet (or application) can present the list to a user.
IClient machine
Because the SAS Protocol Interpreter is maintaining the socket
connections, the restriction of having the remote SAS session created on
the same machine as the Web server Is removed. The applet is sending
requests to the SAS Message Router, not directly to the remote SAS
session. The remote SAS session can be created on any machine with
which the SAS Protocol Interpreter can communicate.
IWeb server machine
IRemote machine
Figure 8: Components Needed for HTTP Tunneling
374
The configuration program associated with the SAS Protocol Interpreter
allows an administrator to tailor its capabilities. The configuration program
may include a list of machines that are allowed to provide SAS services to
Java applets or a list of machines that are not anowed to provide services
to applets. The administrator can conflQure the interpreter to only allow
certain commands to be used to start a SAS session and disallow all
others. The configuration program can also restrict the users that are
allowed to use the SAS Protocol Interpreter, and the Interpreter can be
configured to close a connection after a certain amount of time has
passed.
the stop () method has been called. Once informed that the applet will
stop shortly, the other threads can complete whatever work they are doing
and leave the applet in a state so can be successfully restarted.
a
The thread that is establishing the conneclion to the remote SAS session
can update the status field, so the user receives continucus feedback
concerning the applefs activities.
Well-behaved applets will establish conneclions during the start ()
method and close the connections during the stop () method. Applets
should release their resources wihen the stop () method has been
called.
Although we are using JTunnel to allow applets to communicate with a
machine other than the machine from which Ihe applet originated,
JTunnel does not circumvent the "sandbox" security model. The intent of
the security model is to protect the client machine and other machines
that the client machine may communicate with. JTunnel does not allow
the applet to connect to any random machine, n requires a configuration
file (created by an administrator) that contains the list of machines and
ports that are available to applets using JTunnel. Using the SAS Protocol
Interpreter, securny can be maintained while the administrator of the Web
server restricts which machines are eligible for connections on behalf of
an applet.
Using Archive Files
Java classes may be dynamically downloaded Individually from the Web
server or they may be bundled together in a Java Archive file (JAR file). If
the apple! requires a number of classes, n may take a significant amount
of time to download each class file individually. Instead the classes may
be bundled together to reduce download time. JAR files are a standard
part of JDK 1.1. At the time this paper was wroten, neither Netscape nor
Microsoft had a browser that supported JDK 1.1. However, both ofthese
browsers supported some type of archive file. For Netscape Navigator,
uncompressed zip files could be used to contain multiple Java class files;
Microsoft Internet Explorer used CAS files. The sample applets provided
by SAS Institute on its Web sne make use of archive files. They
significantly reduce the time n takes to start the applet and have n perform
useful work.
Tips for Constructing Well-behaved Applets
Developing clienliserver applications for the Web requires acute attention
to application behavior and performance issues. Here are some
suggestions for creating robust, high performance Java applets.
Using Multiple Threads Within an Applet
Irs Important for Java programmers to effectively manage the state of the
client, server, and connection objects during program execution. This can
be accomplished by using multiple threads to control the order and priorny
of program activities.
Summary
This paper described the Java classes provided by SAS Instaute. We
provide the SAS/SHARE"NET Driver for JDSC, a package that allows
applets to access SAS data, and JConnecl, a package that enables
remote SAS computing services. We also provide Java classes and
programs to support HTTP tunneling to alleviate some configuration
restrictions and provide access to users behind a firewall. In addition, we
provided some tips concerning apple! behavior to help the reader
construct wel~behaved applets.
The Java class java. applet .Applet is the bese class for Java
applets. It provides the following methods:
•
init ()
•
start ()
•
stop ()
•
destroy()
NOTE: At the time of this paper, the code is stiff under development. We
expect that results from further testing wiN change some of the
functionality desclibed here. For more u~to-date information, please visit
the SAS Web site Osted be/ow and foOow the product links.
These methods are called by the browser. The ini t () method is
called when the applet is first loaded; destroy () is called when the
applet is no longer needed. The start () method is called when the
applet is visible to the user; stop () is called when the applet is no
longer visible. Start () and stop () will be called multiple times as
the user switches between HTMl pages.
References
http://splash.javasoft.comfjdbc - Use this URL to review JDSC
information.
http://www.sas.comImdJweb - Use this URl to download a beta of the
SAs/SHARE"NET Driver for JDSC. SAS Instaute provides sample code
with the SAs/SHARE"NET Driver for JDSe.
The applet will not be painted (i.e., the GUI components will not be visible
to the user) until the ini t () method has exited. All of our sample
applets establish communication with a remote machine. Establishing the
conneclion may take a substantial amount of lime. We feel it is
unacceptable to wme applels that do not provide status information about
the state of a connection. Since the apple! will not provide visual feedback
until the ini t () method has completed, we do not establish
connections in the ini t () method.
SAS, SAS/CONNECT, SAS/lntrNet, SAS/GRAPH, and
SAs/SHARE"NET are registered trademarks or trademarks of SAS
Institute Inc. in the USA and other countries. Java and JDSC are
registered trademarks or trademarks of Sun Microsystems, Inc.
® indicates USA registration.
In all of our sample applets, in the ini t () method we create a
TextFieid called s ta t us that displays status information, lay out the
GUI (graphical user interface), and exit the method. The status area is
now visible to the user.
Author: Barbara Walters
SAS Instnute Inc.
SAS Campus Drive
Cary, NC 27513
(919) 677-8000 x6668
[email protected]
Next, the applet's start () method is called. Our sample applets
create a separate thread to establish the conneclion to the remote SAS
session. If the apple!'s main thread is used to create the conneclion and
the stop () method is called, the conneclion to the remote SAS
session may be left in some unknown state. Many conditions exist under
which the applet's stop () method may be called. If the main apple!
thread is performing some operation that changes the state of the applet
and the stop () method is called, the applet may be left in some
unrecoverable slate. If the applet is left in an unknown state, later the
start () method may not be able to successfully restart the applet.
Therefore, any work that is performed that changes the state of the applet
should be performed in some thread other than the main applet thread.
The applelthread cancommunicale with the other threads to inform them
375