|
Client Services
JNetStart launches applications under a secure environment similar to Java applets.
The JNetStart client environment provides secure services that enables the user to read and write
local files and print documents under strict user control. Using the connection service the application
can obtain the connection to the Iris server that is used by JNetStart to load the application and invoke
user applications deployed on the server.
To build applications that use secure client services you must include in your
compile classpath either of these two jars:
- netstart_applet<ver>.jar
- netstart_frame<ver>.jar
where <ver> is the current version of JNetStart. Do not deploy these files with your
application, the client services API is available at runtime in both the JNetStart plugins and the JNetStart bootstrap applet.
File Service
To allow the application to read and write local files JNetStart provides a secure file chooser API.
The application must display the secure file chooser and obtain secure file proxies for the files selected by the user.
The file proxies provide access to the file input or output streams depending on the operation.
To write data to a local file the application must display a secure save file dialog
and obtain an OutputStream if the user confirms the operation:
import com.accendia.netstart.client.service.JSecureFileChooser;
...
JSecureFileChooser secureFileChooser = new JSecureFileChooser();
secureFileChooser.setAcceptAllFileFilterUsed( true );
secureFileChooser.setFilterExtensions( new String[]{ "txt" } );
secureFileChooser.setSelectedFile( "WriteDemo.txt" );
FileProxy[] selectedFiles = secureFileChooser.showSaveDialog( frame );
if( selectedFiles == null )
return;
FileProxy file = selectedFiles[0];
OutputStream output = null;
try
{
output = file.getOutputStream();
if( output == null )
{
String message = "Can not write to file " + file.getName();
JOptionPane.showMessageDialog( frame, message );
return;
}
// write to the output stream
writeMessage( output );
}
catch( IOException ex )
{
String message = "Failed to open file " + file.getName();
JOptionPane.showMessageDialog( frame, message );
return;
}
...
To read a local file the application must display a secure open file dialog
and obtain an InputStream if the user confirms the operation:
import com.accendia.netstart.client.service.JSecureFileChooser;
...
JSecureFileChooser secureFileChooser = new JSecureFileChooser();
secureFileChooser.setAcceptAllFileFilterUsed( true );
secureFileChooser.setFilterExtensions( new String[]{ "txt" } );
FileProxy[] selectedFiles = secureFileChooser.showOpenDialog( frame );
if( selectedFiles == null )
return;
FileProxy file = selectedFiles[0];
InputStream input = null;
try
{
input = file.getInputStream();
if( input == null )
{
String message = "Can not read file " + file.getName();
JOptionPane.showMessageDialog( frame, message );
return;
}
// read from the input stream
showEditor( input );
}
catch( IOException ex )
{
String message = "Failed to open file " + file.getName();
JOptionPane.showMessageDialog( frame, message );
return;
}
...
The user can prevent a rogue application from writing or reading the local files by
cancelling the secure file dialog. The application can read only the files explicitly selected
by the user in the secure file open dialog. The application can write only to local files selected
by the user in the secure file save dialog. The output file size is limited to 4GB.
Print Service
JNetStart provides a secure print API that allows the application to print to the local printer
under strict user control. The print API display the print dialog whenever the application
starts a print job:
import com.accendia.netstart.client.service.SecurePrinterJob;
...
SecurePrinterJob printerJob = SecurePrinterJob.getSecurePrinterJob();
// This call will open the standard Print Dialog
printerJob.print( new PrintableDemo(1) );
...
The code is similar for a Pageable document:
import com.accendia.netstart.client.service.SecurePrinterJob;
...
SecurePrinterJob printerJob = SecurePrinterJob.getSecurePrinterJob();
// This call will open the standard Print Dialog
printerJob.print( new PageableDemo( printerJob ) );
...
The user is protected from a rogue application by being able to cancel the print dialog.
Connection Service
JNetStart provides a connection API that allows the application to obtain the Iris connection context object and invoke
user applications deployed on the server. Reusing the same connection minimizes the number of client sockets
opened on the server and the client initialization is significantly faster than if the client would open a
second socket:
import com.accendia.netstart.client.service.ConnectionContext;
...
ConnectionContext connectionContext = ConnectionContext.getConnectionContext();
try
{
// get the server context
ServerContext serverContext = connectionContext.getServerContext();
// invoke applications deployed on the server
CommandInterface command = (CommandInterface)serverContext.getCommandProxy(
"application_name", "command_name" );
// release the server context if you don't plan to invoke the server
// so JNetStart may close the connection
connectionContext.releaseServerContext();
}
catch( IOException ex )
{
...
}
...
|