NetworkDrive Module
Content
Introduction
A Module capable of writing files to network locations using the samba protocol.
Key Capabilities
Capability |
Description |
Network file writing |
Write a file to a network destination using the samba protocol. |
Network file reading |
Read a file from a network destination using the same information |
Encryption |
Passwords for network authentification are stored in encrypted form. Password for |
Module Setup & Configuration
In order to write files, you need to set up an instance of NetworkCredentials that e.g. stores the host password. As you propably do not want that
password to be stored in plain text, this module provides an encryption mechanism.
Use the module configuration in order to provide an encryption password. If set once, all passwords will be encrypted or decrypted using that password.
Config name |
Config value |
Server password encryption key |
/?~Ls9PaAN9Q%]]6 |
Example
Follow the steps provided below in order to write the desired file.
Frontend Use
-
Set your credential encryption password via module configuration
-
Create an instance of NetworkCredentials and provide host (e.g. 192.168.1.46), username and password for server athentification. In order to
provide a domain, use the format username@domain for the username attribute.
Note that the password will be encrypted using the password from module configuration. Also, the Dashboard will display "No data" for your
password even though it has been successfully saved. This is due to the implementation of the afterGetAll-method for NetworkCredentials. -
Create a NetworkOutFile object and set the reference for credentials, load up a file for content
-
Set the path attribute according to the samba share settings with desired file name (e.g. "sambashare/test.pdf")
The module will then invoke the write operation.
Backend Use
-
Follow instruction steps 1. - 4. as shown above
-
Set an encryption password in module config
-
You need to manually encrypt your password. The public class EncryptionHelper in com.apiomat.nativemodule.networkdrive does that for you
String password = networkCredentials.getPassword( );
try
{
/* Helper automatically reads encryption pasword from module config */
EncryptionHelper helper =
new
EncryptionHelper( password, request );
String encryptedPassword = helper.encrypt( );
networkCredentials.setPassword( encryptedPassword );
networkCredentials.save( );
}
catch
( Exception e )
{
NetworkDrive.AOM.logError( request.getApplicationName( ), e,
false
);
e.printStackTrace( );
}
-
Manually care for writing to the network destination. Use the class NetworkWriteHelper in com.apiomat.nativemodule.networkdrive and Stick to following example
NetworkWriteHelper helper =
new
NetworkWriteHelper( networkFile, request );
try
{
/* will internally use the encryption helper to decrypt server password for authentification */
helper.commit( );
}
catch
( IOException e )
{
NetworkDrive.AOM.throwException(
400
, e.getMessage( ) );
e.printStackTrace( );
}
Follow the steps provided below in order to read the desired file.
Frontend Use
-
Follow steps 1 and to as for writing files.
-
Create a NetworkInFile object and set the reference for credentials
-
Set the path attribute according to the samba share settings with desired file name (e.g. "sambashare/test.pdf")
The module will then invoke the read operation. You will find the file in the content attribute.
Backend Use
-
Follow steps 1. - 3. as shown above
-
Set an encrpytion password in the module configuration
-
Encrypt your credentials password as explained in Backend Use for writing files
-
Now use the NetwordReadHelper class to achieve your goal
NetworkReadHelper helper =
new
NetworkReadHelper( networkFile, request );
try
{
helper.commit( );
}
catch
( IOException e )
{
NetworkDrive.AOM.throwException(
400
, e.getMessage( ) );
e.printStackTrace( );
}
Limitations
If any information like path or credentials are missing, you will fail.
Other sources of error might be
-
failing authentification
-
server finding error
-
missing file read/write permission
If you encounter some error, doublecheck your data provided. Invoke the write process again with renewing
the path or content attributes.
Detailled Module Workflow
Module Config
In order to read or write files, you need to set up an instance of NetworkCredentials that e.g. stores the host password. As you propably do not want that password to be stored in clear text, this module provides an encryption mechanism.
Use the module configuration in order to provide an encryption password. If set once, all passwords will be encrypted or decrypted using that encryption password.
Classes
Class name |
Attributes |
Description |
NetworkCredentials |
host: server host name like "192.168.1.46" |
Container for server access credentials for a user in reusable form. |
NetworkFile |
credentials: reference to a NetworkCredentials object for |
Class for all information as like file to write or read, authentification |
NetworkInFile |
|
Subclass of NetworkFile for files being read from a samba share |
NetworkOutFile |
|
Subclass of NetworkFile for files being written to a samba share |
Sequence
After setting a reference from NetworkFile to NetworkCredentials and providing a file as NetworkFile's content, the module invokes the afterPut-method writing to the destination after providing for the path attribute.
Note that the Module automatically prepends the host attribute with "smb://" internally.