CSJCurrent de:Dateitransfer: Unterschied zwischen den Versionen

Aus Cryptshare Documentation
Wechseln zu:Navigation, Suche
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
 
-----
= Allgemeines =
= Allgemeines =
Transfers können synchron sowie asynchron über die API durchgeführt werden. Ein Transfer kann mehrere Dateien enthalten und wird anschließend auf den Cryptshare Server hochgeladen, verschlüsselt und den Empfängern zu Verfügung gestellt. Abhängig von den verwendeten Transfereinstellungen werden die Empfänger und der Absender nach der Bereitstellung des Transfers beanchrichtigt.
Transfers können synchron sowie asynchron über die API durchgeführt werden. Ein Transfer kann mehrere Dateien enthalten und wird anschließend auf den Cryptshare Server hochgeladen, verschlüsselt und den Empfängern zu Verfügung gestellt. Abhängig von den verwendeten Transfereinstellungen werden die Empfänger und der Absender nach der Bereitstellung des Transfers beanchrichtigt.
Zeile 46: Zeile 42:


=== Cryptshare Transfer vorbereiten ===
=== Cryptshare Transfer vorbereiten ===
 
// First create the Client instance
<pre>
// Create a WebServiceUri for your Cryptshare Server
// First create the Client instance
WebServiceUri serviceUri = new WebServiceUri("<nowiki>https://cryptshare.yourdomain.com</nowiki>");
// Create a WebServiceUri for your Cryptshare Server
WebServiceUri serviceUri = new WebServiceUri("https://cryptshare.yourdomain.com");
// Create a CryptshareConnection instance for your WebServiceUri
 
CryptshareConnection connection = new CryptshareConnection(serviceUri);
// Create a CryptshareConnection instance for your WebServiceUri
CryptshareConnection connection = new CryptshareConnection(serviceUri);
// Create the Client instance with the sender's email address,
 
// the CryptshareConnection, and the path to the verification store.
// Create the Client instance with the sender's email address,
Client client = new Client("john.adams@yourdomain.com", connection, Paths.get("C:\\temp\\client.store"));
// the CryptshareConnection, and the path to the verification store.
Client client = new Client("john.adams@yourdomain.com", connection, Paths.get("C:\\temp\\client.store"));
// Create a new Transfer object
 
Transfer transfer = new Transfer();
// Create a new Transfer object
Transfer transfer = new Transfer();
// Set the name of the sender
 
transfer.setSenderName("John Adams");
// Set the name of the sender
transfer.setSenderName("John Adams");
// Set the sender's phone number
 
transfer.setSenderPhone("234 5467");
// Set the sender's phone number
transfer.setSenderPhone("234 5467");
// Set the message text of the mail that is to be included in the transfer.
 
// The Transfer object's setMessage(..) method takes either an
// Set the message text of the mail that is to be included in the transfer.
// actual text string containing the email message, or an InputStream
// The Transfer object's setMessage(..) method takes either an
// which contains the email message text. If specifying an InputStream, the
// actual text string containing the email message, or an InputStream
// stream needs to be UTF-8 encoded, to ensure that the characters can be
// which contains the email message text. If specifying an InputStream, the
// read in and displayed correctly in the email message.
// stream needs to be UTF-8 encoded, to ensure that the characters can be
try (FileInputStream inputStream = new FileInputStream("C:\\temp\\message.txt")) {
// read in and displayed correctly in the email message.
// To illustrate, we'll use the message text from an input stream.
try (FileInputStream inputStream = new FileInputStream("C:\\temp\\message.txt")) {
// Your application may get this input stream from another process, for
// To illustrate, we'll use the message text from an input stream.
// instance, but in this example, we will just read it in from a file
// Your application may get this input stream from another process, for
// Set the input stream as the message. The method will read in
// instance, but in this example, we will just read it in from a file
// the text from the stream and automatically close the stream when it's done.
// Set the input stream as the message. The method will read in
transfer.setMessage(inputStream);
// the text from the stream and automatically close the stream when it's done.
} catch (Exception ex) {
transfer.setMessage(inputStream);
// there was an error reading the text file, so show an error message
} catch (Exception ex) {
System.err.println("Error reading the message file!");
// there was an error reading the text file, so show an error message
}
System.err.println("Error reading the message file!");
}
// Set the subject text of the mail that is to be included in the transfer.
 
transfer.setSubject("Subject of the Transfer");
// Set the subject text of the mail that is to be included in the transfer.
transfer.setSubject("Subject of the Transfer");
// Define the recipients
 
List<String> recipients = new ArrayList<String>();
// Define the recipients
recipients.add("jane.doe@abc.com");
List<String> recipients = new ArrayList<String>();
recipients.add("jack.smith@xyz.com");
recipients.add("jane.doe@abc.com");
recipients.add("jack.smith@xyz.com");
// Get the policy rule from the server for the given recipients, so we can
 
// check to make sure they are allowed
// Get the policy rule from the server for the given recipients, so we can
Policy policy = client.requestPolicy(recipients);
// check to make sure they are allowed
Policy policy = client.requestPolicy(recipients);
// Check to make sure the recipients are allowed and only add them
 
// to the transfer, if they are
// Check to make sure the recipients are allowed and only add them
if (policy.getFailedEmailAddresses() != null && !policy.getFailedEmailAddresses().isEmpty()) {
// to the transfer, if they are
for (String recipient : recipients) {
if (policy.getFailedEmailAddresses() != null && !policy.getFailedEmailAddresses().isEmpty()) {
if (!policy.getFailedEmailAddresses().contains(recipient)) {
for (String recipient : recipients) {
transfer.addRecipient(new Recipient(recipient));
if (!policy.getFailedEmailAddresses().contains(recipient)) {
} else {
transfer.addRecipient(new Recipient(recipient));
System.out.println("The recipient is invalid: " + recipient);
} else {
}
System.out.println("The recipient is invalid: " + recipient);
}
}
} else {
}
// all recipients are valid
} else {
List<Recipient> recipientList = recipients.stream().map(Recipient::new).collect(Collectors.toList());
// all recipients are valid
transfer.addRecipients(recipientList);
List<Recipient> recipientList = recipients.stream().map(Recipient::new).collect(Collectors.toList());
}
transfer.addRecipients(recipientList);
}
// If allowed by the policy, we can also send a confidential message to the
 
// recipients
// If allowed by the policy, we can also send a confidential message to the
if (policy.isAllowConfidentialMessage()) {
// recipients
transfer.setConfidentialSubject("Subject of the confidential message");
if (policy.isAllowConfidentialMessage()) {
transfer.setConfidentialMessage("This is the text of the confidential message.");
transfer.setConfidentialSubject("Subject of the confidential message");
}
transfer.setConfidentialMessage("This is the text of the confidential message.");
}
// Only continue if we have at least one valid recipient for the transfer
 
if (transfer.getRecipients() == null || transfer.getRecipients().isEmpty()) {
// Only continue if we have at least one valid recipient for the transfer
throw new Exception("No valid recipients defined, aborting transfer.");
if (transfer.getRecipients() == null || transfer.getRecipients().isEmpty()) {
}
throw new Exception("No valid recipients defined, aborting transfer.");
}
// Set the password mode that will be used for this transfer.
 
// Must be one of the password modes allowed by the policy.
// Set the password mode that will be used for this transfer.
// We will just pick the most secure mode allowed by the policy
// Must be one of the password modes allowed by the policy.
PasswordMode passwordMode;
// We will just pick the most secure mode allowed by the policy
Set<PasswordMode> allowedPasswordModes = policy.getAllowedStandardPasswordModes();
PasswordMode passwordMode;
if (allowedPasswordModes.contains(PasswordMode.GENERATED)) {
Set<PasswordMode> allowedPasswordModes = policy.getAllowedStandardPasswordModes();
passwordMode = PasswordMode.GENERATED;
if (allowedPasswordModes.contains(PasswordMode.GENERATED)) {
} else if (allowedPasswordModes.contains(PasswordMode.MANUAL)) {
passwordMode = PasswordMode.GENERATED;
passwordMode = PasswordMode.MANUAL;
} else if (allowedPasswordModes.contains(PasswordMode.MANUAL)) {
} else {
passwordMode = PasswordMode.MANUAL;
passwordMode = PasswordMode.NONE;
} else {
}
passwordMode = PasswordMode.NONE;
transfer.setPasswordMode(passwordMode);
}
transfer.setPasswordMode(passwordMode);
// If password mode is MANUAL, we have to set a password
 
if (passwordMode.equals(PasswordMode.MANUAL)) {
// If password mode is MANUAL, we have to set a password
// we have to manually set a password for this transfer
if (passwordMode.equals(PasswordMode.MANUAL)) {
transfer.setPassword("p4$$w0rd");
// we have to manually set a password for this transfer
}
transfer.setPassword("p4$$w0rd");
}
// Define if the file names should be shown in the recipient's
 
// notification email
// Define if the file names should be shown in the recipient's
transfer.setShowFilenames(true);
// notification email
transfer.setShowFilenames(true);
// Define if the sender should be notified when the recipients
 
// download the files
// Define if the sender should be notified when the recipients
transfer.setInformAboutDownload(true);
// download the files
transfer.setInformAboutDownload(true);
// Set the language for the recipient notification email
 
transfer.setRecipientLanguage(Locale.ENGLISH);
// Set the language for the recipient notification email
transfer.setRecipientLanguage(Locale.ENGLISH);
// Set the language for the sender notification email
 
client.setUserLanguage(Locale.ENGLISH);
// Set the language for the sender notification email
client.setUserLanguage(Locale.ENGLISH);
// Set the expiration date of the files
 
// (how long the files will be available for download)
// Set the expiration date of the files
// We'll just set it to the maximum allowed storage duration
// (how long the files will be available for download)
int storageDuration = policy.getStorageDuration();
// We'll just set it to the maximum allowed storage duration
Calendar cal = Calendar.getInstance();
int storageDuration = policy.getStorageDuration();
cal.add(Calendar.DAY_OF_MONTH, storageDuration);
Calendar cal = Calendar.getInstance();
transfer.setExpirationDate(cal.getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
cal.add(Calendar.DAY_OF_MONTH, storageDuration);
transfer.setExpirationDate(cal.getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
// Add the files for this transfer
 
// A TransferFile object has to be created for each file you would like to add to the transfer
// Add the files for this transfer
// Add a file from the file system, specified as a complete file path:
// A TransferFile object has to be created for each file you would like to add to the transfer
transfer.addFile(new TransferFile(Paths.get("C:\\temp\\transfer_file_01.txt")));
// Add a file from the file system, specified as a complete file path:
transfer.addFile(new TransferFile(Paths.get("C:\\temp\\transfer_file_01.txt")));
// Add a stream that contains the data for a file.
 
// Your application may have received this stream from another process, for instance,
// Add a stream that contains the data for a file.
// but for this example, we will just create an input stream from a file
// Your application may have received this stream from another process, for instance,
try {
// but for this example, we will just create an input stream from a file
File inputFile = new File("C:\\temp\\transfer_file_02.txt");
try {
FileInputStream inputStream = new FileInputStream(inputFile);
File inputFile = new File("C:\\temp\\transfer_file_02.txt");
long streamSize = inputFile.length();
FileInputStream inputStream = new FileInputStream(inputFile);
long streamSize = inputFile.length();
// Create the TransferFile object for this stream. You also need to specify
 
// a name for the file that will be created from the data of this stream, including
// Create the TransferFile object for this stream. You also need to specify
// a file extension, so that the recipient will be able to open it with the correct
// a name for the file that will be created from the data of this stream, including
// application, as well as the size of the stream. The stream will be closed
// a file extension, so that the recipient will be able to open it with the correct
// automatically, once it has been uploaded to the server.
// application, as well as the size of the stream. The stream will be closed
TransferFile streamFile = new TransferFile("MyAttachment.txt", inputStream, streamSize);
// automatically, once it has been uploaded to the server.
transfer.addFile(streamFile);
TransferFile streamFile = new TransferFile("MyAttachment.txt", inputStream, streamSize);
} catch (Exception ex) {
transfer.addFile(streamFile);
ex.printStackTrace();
} catch (Exception ex) {
}
ex.printStackTrace();
// Add another file from the file system
}
transfer.addFile(new TransferFile(Paths.get("C:\\temp\\transfer_file_03.txt")));
// Add another file from the file system
transfer.addFile(new TransferFile(Paths.get("C:\\temp\\transfer_file_03.txt")));
// Now we can use this transfer object to perform the transfer
 
// either synchronously or asynchronously
// Now we can use this transfer object to perform the transfer
  ...
// either synchronously or asynchronously
...
</pre>
 
-----
-----
= Transfer durchführen =
= Transfer durchführen =
Zeile 209: Zeile 201:


=== Durchführen eines synchronen Transfers ===
=== Durchführen eines synchronen Transfers ===
<pre>
  private static void performTransferSynchronous() {
private static void performTransferSynchronous() {
  // First create the Client instance
// First create the Client instance
  // Create a WebServiceUri for your Cryptshare Server  
// Create a WebServiceUri for your Cryptshare Server  
  WebServiceUri serviceUri = new WebServiceUri("<nowiki>https://cryptshare.server.com</nowiki>");
WebServiceUri serviceUri = new WebServiceUri("https://cryptshare.server.com");
 
  // Create a CryptshareConnection instance for your WebServiceUri
  CryptshareConnection connection = new CryptshareConnection(serviceUri);
 
  // Create the Client instance with the sender's email address,
  // the CryptshareConnection, and the path to the verification store.
  Client client = new Client("sender_email@server.com", connection, Paths.get("C:\\temp"));
    
    
// Create a CryptshareConnection instance for your WebServiceUri
  // Prepare the transfer object as described in the example above
CryptshareConnection connection = new CryptshareConnection(serviceUri);
  Transfer transfer = ...
    
    
// Create the Client instance with the sender's email address,
  // Perform a synchronous transfer with four event handlers.
// the CryptshareConnection, and the path to the verification store.
  // Method will block until the transfer is completed.
Client client = new Client("sender_email@server.com", connection, Paths.get("C:\\temp"));
  client.performTransfer(transfer,
    new UploadProgressChangedHandler(),
// Prepare the transfer object as described in the example above
    new UploadCompleteHandler(),
Transfer transfer = ...
    new UploadInterruptedHandler(),
    new UploadCancelledHandler(),
// Perform a synchronous transfer with four event handlers.
    1000);
// Method will block until the transfer is completed.
  }
client.performTransfer(transfer,
 
  new UploadProgressChangedHandler(),
  public class UploadProgressChangedHandler implements IUploadProgressChangedHandler {
  new UploadCompleteHandler(),
  @Override
  new UploadInterruptedHandler(),
  public void progressChanged(String currentFileNo, String currentFileName, double bytesUploaded, double bytesTotal, long bytesPerSecond) {
  new UploadCancelledHandler(),
  // This method is called repeatedly with the current upload data
  1000);
  // Our upload listener will just output the current progress to the console
}
  double percent = ((bytesUploaded / bytesTotal) * 100.0);
  System.out.println("Transfer progress ... " + ((int)percent) + "%");
public class UploadProgressChangedHandler implements IUploadProgressChangedHandler {
  }
@Override
  }
public void progressChanged(String currentFileNo, String currentFileName, double bytesUploaded, double bytesTotal, long bytesPerSecond) {
 
// This method is called repeatedly with the current upload data
  public class UploadCompleteHandler implements IUploadCompleteHandler {
// Our upload listener will just output the current progress to the console
  @Override
double percent = ((bytesUploaded / bytesTotal) * 100.0);
  public void uploadComplete(Map<String, String> urlMappings, Map<String, String> smtpMappings, String serverGenPassword, TransferError transferError,
System.out.println("Transfer progress ... " + ((int)percent) + "%");
  String trackingId) {
}
  // this method is called when all files of the transfer have been uploaded
}
  System.out.println("Upload completed!");
  }
public class UploadCompleteHandler implements IUploadCompleteHandler {
  }
@Override
 
public void uploadComplete(Map<String, String> urlMappings, Map<String, String> smtpMappings, String serverGenPassword, TransferError transferError,
  public class UploadInterruptedHandler implements IUploadInterruptedHandler {
String trackingId) {
  @Override
// this method is called when all files of the transfer have been uploaded
  public void uploadInterrupted(CryptshareException cryptshareException) {
System.out.println("Upload completed!");
  // this method is called when an exception occurs during the file upload
}
      System.out.println("An exception occurred during the upload: " + cryptshareException);
}
  }
  }
public class UploadInterruptedHandler implements IUploadInterruptedHandler {
 
@Override
  public class UploadCancelledHandler implements IUploadCancelledHandler {
public void uploadInterrupted(CryptshareException cryptshareException) {
  @Override
// this method is called when an exception occurs during the file upload
  public void cancelled() {
    System.out.println("An exception occurred during the upload: " + cryptshareException);
  // this method is called when the transfer has been cancelled  
}
  // using the cancelTransfer() method
}
  System.out.println("The transfer has been canceled!");
  }
public class UploadCancelledHandler implements IUploadCancelledHandler {
  }
@Override
public void cancelled() {
// this method is called when the transfer has been cancelled  
// using the cancelTransfer() method
System.out.println("The transfer has been canceled!");
}
}
</pre>


== Asynchron ==
== Asynchron ==
Zeile 281: Zeile 271:


=== Durchführen eines asynchronen Transfers ===
=== Durchführen eines asynchronen Transfers ===
<pre>
  private static void performTransferSynchronous() {
private static void performTransferSynchronous() {
  // First create the Client instance
// First create the Client instance
  // Create a WebServiceUri for your Cryptshare Server  
// Create a WebServiceUri for your Cryptshare Server  
  WebServiceUri serviceUri = new WebServiceUri("<nowiki>https://cryptshare.server.com</nowiki>");
WebServiceUri serviceUri = new WebServiceUri("https://cryptshare.server.com");
 
  // Create a CryptshareConnection instance for your WebServiceUri
  CryptshareConnection connection = new CryptshareConnection(serviceUri);
 
  // Create the Client instance with the sender's email address,
  // the CryptshareConnection, and the path to the verification store.
  Client client = new Client("sender_email@server.com", connection, Paths.get("C:\\temp"));
 
  // Prepare the transfer object as described in the example above
  Transfer transfer = ...
 
  // Perform an asynchronous transfer with a new anonymous TransferUploadListener instance
  // Method will return immediately
  client.beginTransfer(transfer,
    new UploadProgressChangedHandler(),
    new UploadCompleteHandler(),
    new UploadInterruptedHandler(),
    new UploadCancelledHandler(),
    1000);
  }
 
  public class UploadProgressChangedHandler implements IUploadProgressChangedHandler {
  @Override
  public void progressChanged(String currentFileNo, String currentFileName, double bytesUploaded, double bytesTotal, long bytesPerSecond) {
  // This method is called repeatedly with the current upload data
  // Our upload listener will just output the current progress to the console
  double percent = ((bytesUploaded / bytesTotal) * 100.0);
  System.out.println("Transfer progress ... " + ((int)percent) + "%");
  }
  }
 
  public class UploadCompleteHandler implements IUploadCompleteHandler {
  @Override
  public void uploadComplete(Map<String, String> urlMappings, Map<String, String> smtpMappings, String serverGenPassword, TransferError transferError,
  String trackingId) {
  // this method is called when all files of the transfer have been uploaded
  System.out.println("Upload completed!");
  }
  }
    
    
// Create a CryptshareConnection instance for your WebServiceUri
  public class UploadInterruptedHandler implements IUploadInterruptedHandler {
CryptshareConnection connection = new CryptshareConnection(serviceUri);
  @Override
  public void uploadInterrupted(CryptshareException cryptshareException) {
  // this method is called when an exception occurs during the file upload
      System.out.println("An exception occurred during the upload: " + cryptshareException);
  }
  }
    
    
// Create the Client instance with the sender's email address,
  public class UploadCancelledHandler implements IUploadCancelledHandler {
// the CryptshareConnection, and the path to the verification store.
  @Override
Client client = new Client("sender_email@server.com", connection, Paths.get("C:\\temp"));
  public void cancelled() {
  // this method is called when the transfer has been cancelled  
// Prepare the transfer object as described in the example above
  // using the cancelTransfer() method
Transfer transfer = ...
  System.out.println("The transfer has been canceled!");
  }
// Perform an asynchronous transfer with a new anonymous TransferUploadListener instance
  }
// Method will return immediately
client.beginTransfer(transfer,
  new UploadProgressChangedHandler(),
  new UploadCompleteHandler(),
  new UploadInterruptedHandler(),
  new UploadCancelledHandler(),
  1000);
}
public class UploadProgressChangedHandler implements IUploadProgressChangedHandler {
@Override
public void progressChanged(String currentFileNo, String currentFileName, double bytesUploaded, double bytesTotal, long bytesPerSecond) {
// This method is called repeatedly with the current upload data
// Our upload listener will just output the current progress to the console
double percent = ((bytesUploaded / bytesTotal) * 100.0);
System.out.println("Transfer progress ... " + ((int)percent) + "%");
}
}
public class UploadCompleteHandler implements IUploadCompleteHandler {
@Override
public void uploadComplete(Map<String, String> urlMappings, Map<String, String> smtpMappings, String serverGenPassword, TransferError transferError,
String trackingId) {
// this method is called when all files of the transfer have been uploaded
System.out.println("Upload completed!");
}
}
public class UploadInterruptedHandler implements IUploadInterruptedHandler {
@Override
public void uploadInterrupted(CryptshareException cryptshareException) {
// this method is called when an exception occurs during the file upload
    System.out.println("An exception occurred during the upload: " + cryptshareException);
}
}
public class UploadCancelledHandler implements IUploadCancelledHandler {
@Override
public void cancelled() {
// this method is called when the transfer has been cancelled  
// using the cancelTransfer() method
System.out.println("The transfer has been canceled!");
}
}
</pre>

Version vom 7. März 2022, 13:44 Uhr

Allgemeines

Transfers können synchron sowie asynchron über die API durchgeführt werden. Ein Transfer kann mehrere Dateien enthalten und wird anschließend auf den Cryptshare Server hochgeladen, verschlüsselt und den Empfängern zu Verfügung gestellt. Abhängig von den verwendeten Transfereinstellungen werden die Empfänger und der Absender nach der Bereitstellung des Transfers beanchrichtigt. Bevor ein Transfer durchgeführt werden kann, muss dieser, wie im Kapitel 'Transfer vorbereiten' beschrieben, vorbereitet werden. Anschließend kann der Transfer entweder synchron oder asynchron durchgeführt werden.

Transfer vorbereiten

Bevor ein Transfer abgesendet werden kann, muss dieser mit den folgenden Parametern vorbereitet werden:

  • Kontaktdaten des Absenders
    • Name
    • Telefonnummer
  • Das zu verwendende Passwortverfahren (optional)
  • Der Nachrichtentext für die Absenderbenachrichtigung (optional)
  • Die Empfänger-E-Mail-Adressen
  • Die Sprache der Benachrichtigung (optional)
  • Die gewünschte Liegezeit für den Transfer (optional)
  • Die zu übertragenden Dateien

Wird der Transfer nicht gestattet, da einige Empfänger dafür nicht zugelassen werden, so wird eine Exception geworfen. Um dies zu vermeiden, kann vor dem Transfer eine Policyüberprüfung durchgeführt werden.

Das Passwortverfahren

Bei dem für einen Transfer verwendeten Passwortverfahren muss es sich um ein erlaubtes Passwortverfahren handeln, das in der Policyregel definiert ist.

Manuelles Passwort - 'manual'

Beim Passwortverfahren PasswordMode.MANUAL müssen Sie explizit ein Passwort für den Transfer vergeben. Das Passwort kann mit den Funktionen aus dem Kapitel 'Passwortfunktionen' auf die aktuellen Sicherheitsanforderungen überprüft werden. Der Empfänger muss bei diesem Verfahren Kontakt mit dem Absender aufnehmen, um das Passwort zu erfahren.

Generiertes Passwort - 'generated'

Der Client fordert bei diesem Verfahren ein automatisch generiertes Passwort vom Server an, welches die geforderten Sicherheitsanforderungen erfüllt. Der Empfänger muss bei diesem Verfahren Kontakt mit dem Absender aufnehmen, um das Passwort zu erfahren.

Kein Passwort - 'none'

Bei diesem Verfahren muss keiner der Beteiligten ein Passwort für den Transfer angeben. Dies wird vom Server für den Anwender 'unsichtbar' gehandhabt.

Beachten Sie bitte, dass dieser Modus als der unsicherste Modus gilt und daher nur in ausgewählten Fällen verwendet werden sollte.

Die Benachrichtigungssprache

Die Benachrichtigungssprache kann für den Absender und die Empfänger separat über die entsprechende Locale angegeben werden. Sie können nur Sprachen angeben, welche auf dem Server auch als Sprachpaket installiert sind (siehe Kapitel 'Sprach-Ressourcen').

Der Benachrichtigungstext

Sie können für die Empfängerbenachrichtigung einen eigenen Betreff oder auch Inhalt verwenden. Das Transfer-Objekt stellt hierfür Setter für das message- und subject-Feld bereit, die jeweils mit einem String oder InputStream, der automatisch ausgelesen wird, gefüllt werden können. Der Text muss im UTF-8 Format angegeben werden. Der Nachrichteninhalt kann HTML-Markup enthalten, der Nachrichtenbetreff hingegen nicht.

Vertrauliche Nachricht

Sofern die Policyregel dies erlaubt, kann auf dieselbe Weise wie ein Benachrichtigungstext auch eine vertrauliche Nachricht zu dem Transfer hinzugefügt werden. Dies geschieht über die Setter für die Felder confidentialMessage und confidentialSubject, die wie die Benachrichtigung als String oder auch InputStream angegeben werden können. Für diese gelten dieselben Einschränkungen wie auch bei der Benachrichtigung. Die vertrauliche Nachricht wird zusammen mit den Transferdateien verschlüsselt und kann von den Empfängern beim Abruf des Transfers eingesehen werden.

Ablaufdatum

Wenn Sie ein Ablaufdatum für den Transfer angeben, stellen Sie sicher, dass dieses innerhalb der von der Policyregel maximal erlaubten Zeitspanne liegt. Der Transfer wird nur bis zum angegebenen Datum abrufbar sein.

Transfervorbereitungen abgeschlossen

Sobald ein Transfer Objekt wie im Beispiel vollständig vorbereitet wurde, so kann dieser Transfer entweder synchron oder asynchron verschickt werden. Mehr Informationen erhalten Sie in den nachfolgenden Kapiteln.


Cryptshare Transfer vorbereiten

// First create the Client instance
// Create a WebServiceUri for your Cryptshare Server
WebServiceUri serviceUri = new WebServiceUri("https://cryptshare.yourdomain.com");

// Create a CryptshareConnection instance for your WebServiceUri
CryptshareConnection connection = new CryptshareConnection(serviceUri);

// Create the Client instance with the sender's email address,
// the CryptshareConnection, and the path to the verification store.
Client client = new Client("john.adams@yourdomain.com", connection, Paths.get("C:\\temp\\client.store"));

// Create a new Transfer object
Transfer transfer = new Transfer();

// Set the name of the sender
transfer.setSenderName("John Adams");

// Set the sender's phone number
transfer.setSenderPhone("234 5467");

// Set the message text of the mail that is to be included in the transfer.
// The Transfer object's setMessage(..) method takes either an
// actual text string containing the email message, or an InputStream
// which contains the email message text. If specifying an InputStream, the
// stream needs to be UTF-8 encoded, to ensure that the characters can be
// read in and displayed correctly in the email message.
try (FileInputStream inputStream = new FileInputStream("C:\\temp\\message.txt")) {
	// To illustrate, we'll use the message text from an input stream.
	// Your application may get this input stream from another process, for
	// instance, but in this example, we will just read it in from a file
	// Set the input stream as the message. The method will read in
	// the text from the stream and automatically close the stream when it's done.
	transfer.setMessage(inputStream);
} catch (Exception ex) {
	// there was an error reading the text file, so show an error message
	System.err.println("Error reading the message file!");
}

// Set the subject text of the mail that is to be included in the transfer.
transfer.setSubject("Subject of the Transfer");

// Define the recipients
List<String> recipients = new ArrayList<String>();
recipients.add("jane.doe@abc.com");
recipients.add("jack.smith@xyz.com");

// Get the policy rule from the server for the given recipients, so we can
// check to make sure they are allowed
Policy policy = client.requestPolicy(recipients);

// Check to make sure the recipients are allowed and only add them
// to the transfer, if they are
if (policy.getFailedEmailAddresses() != null && !policy.getFailedEmailAddresses().isEmpty()) {
	for (String recipient : recipients) {
		if (!policy.getFailedEmailAddresses().contains(recipient)) {
			transfer.addRecipient(new Recipient(recipient));
		} else {
			System.out.println("The recipient is invalid: " + recipient);
		}
	}
} else {
	// all recipients are valid
	List<Recipient> recipientList = recipients.stream().map(Recipient::new).collect(Collectors.toList());
	transfer.addRecipients(recipientList);
}

// If allowed by the policy, we can also send a confidential message to the
// recipients
if (policy.isAllowConfidentialMessage()) {
	transfer.setConfidentialSubject("Subject of the confidential message");
	transfer.setConfidentialMessage("This is the text of the confidential message.");
}

// Only continue if we have at least one valid recipient for the transfer
if (transfer.getRecipients() == null || transfer.getRecipients().isEmpty()) {
	throw new Exception("No valid recipients defined, aborting transfer.");
}

// Set the password mode that will be used for this transfer.
// Must be one of the password modes allowed by the policy.
// We will just pick the most secure mode allowed by the policy
PasswordMode passwordMode;
Set<PasswordMode> allowedPasswordModes = policy.getAllowedStandardPasswordModes();
if (allowedPasswordModes.contains(PasswordMode.GENERATED)) {
	passwordMode = PasswordMode.GENERATED;
} else if (allowedPasswordModes.contains(PasswordMode.MANUAL)) {
	passwordMode = PasswordMode.MANUAL;
} else {
	passwordMode = PasswordMode.NONE;
}
transfer.setPasswordMode(passwordMode);

// If password mode is MANUAL, we have to set a password
if (passwordMode.equals(PasswordMode.MANUAL)) {
	// we have to manually set a password for this transfer
	transfer.setPassword("p4$$w0rd");
}

// Define if the file names should be shown in the recipient's
// notification email
transfer.setShowFilenames(true);

// Define if the sender should be notified when the recipients
// download the files
transfer.setInformAboutDownload(true);

// Set the language for the recipient notification email
transfer.setRecipientLanguage(Locale.ENGLISH);

// Set the language for the sender notification email
client.setUserLanguage(Locale.ENGLISH);

// Set the expiration date of the files
// (how long the files will be available for download)
// We'll just set it to the maximum allowed storage duration
int storageDuration = policy.getStorageDuration();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, storageDuration);
transfer.setExpirationDate(cal.getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());

// Add the files for this transfer
// A TransferFile object has to be created for each file you would like to add to the transfer
// Add a file from the file system, specified as a complete file path:
transfer.addFile(new TransferFile(Paths.get("C:\\temp\\transfer_file_01.txt")));

// Add a stream that contains the data for a file.
// Your application may have received this stream from another process, for instance,
// but for this example, we will just create an input stream from a file
try {
	File inputFile = new File("C:\\temp\\transfer_file_02.txt");
	FileInputStream inputStream = new FileInputStream(inputFile);
	long streamSize = inputFile.length();

	// Create the TransferFile object for this stream. You also need to specify
	// a name for the file that will be created from the data of this stream, including
	// a file extension, so that the recipient will be able to open it with the correct
	// application, as well as the size of the stream. The stream will be closed
	// automatically, once it has been uploaded to the server.
	TransferFile streamFile = new TransferFile("MyAttachment.txt", inputStream, streamSize);
	transfer.addFile(streamFile);
} catch (Exception ex) {
	ex.printStackTrace();
}
// Add another file from the file system
transfer.addFile(new TransferFile(Paths.get("C:\\temp\\transfer_file_03.txt")));

// Now we can use this transfer object to perform the transfer
// either synchronously or asynchronously
 ...

Transfer durchführen

Synchron

Ist der Transfer, wie im vorigen Kapitel beschrieben, vorbereitet, so kann dieser nun mittels der Methode #performTransfer(Transfer, ...diverse Callbacks) synchron bereitgestellt werden. Folgende Parameter müssen dabei angegeben werden:

  • Der vorbereitete Transfer
  • Diverse Callbacks zur Anzeige des Transferfortschritts

Da dies eine synchrone Operation ist, wird die Methode so lange 'blockieren', bis alle Dateien hochgeladen und der Transfer abgeschlossen ist.

Durchführen eines synchronen Transfers

 private static void performTransferSynchronous() {
 	// First create the Client instance
 	// Create a WebServiceUri for your Cryptshare Server 
 	WebServiceUri serviceUri = new WebServiceUri("https://cryptshare.server.com");
  
 	// Create a CryptshareConnection instance for your WebServiceUri
 	CryptshareConnection connection = new CryptshareConnection(serviceUri);
  
 	// Create the Client instance with the sender's email address, 
 	// the CryptshareConnection, and the path to the verification store.
 	Client client = new Client("sender_email@server.com", connection, Paths.get("C:\\temp"));
 
 	// Prepare the transfer object as described in the example above
 	Transfer transfer = ...
 
 	// Perform a synchronous transfer with four event handlers.
 	// Method will block until the transfer is completed.
 	client.performTransfer(transfer,
 					   new UploadProgressChangedHandler(),
 					   new UploadCompleteHandler(),
 					   new UploadInterruptedHandler(),
 					   new UploadCancelledHandler(),
 					   1000);
 }
 
 public class UploadProgressChangedHandler implements IUploadProgressChangedHandler {
 	@Override
 	public void progressChanged(String currentFileNo, String currentFileName, double bytesUploaded, double bytesTotal, long bytesPerSecond) {
 		// This method is called repeatedly with the current upload data
 		// Our upload listener will just output the current progress to the console
 		double percent = ((bytesUploaded / bytesTotal) * 100.0);
 		System.out.println("Transfer progress ... " + ((int)percent) + "%");
 	}
 }
 
 public class UploadCompleteHandler implements IUploadCompleteHandler {
 	@Override
 	public void uploadComplete(Map<String, String> urlMappings, Map<String, String> smtpMappings, String serverGenPassword, TransferError transferError,
 			String trackingId) {
 		// this method is called when all files of the transfer have been uploaded
 		System.out.println("Upload completed!");
 	}
 }
 
 public class UploadInterruptedHandler implements IUploadInterruptedHandler {
 	@Override
 	public void uploadInterrupted(CryptshareException cryptshareException) {
 		// this method is called when an exception occurs during the file upload
     	System.out.println("An exception occurred during the upload: " + cryptshareException);
 	}
 }
 
 public class UploadCancelledHandler implements IUploadCancelledHandler {
 	@Override
 	public void cancelled() {
 		// this method is called when the transfer has been cancelled 
 		// using the cancelTransfer() method
 		System.out.println("The transfer has been canceled!");
 	}
 }

Asynchron

Ist der Transfer, wie im vorigen Kapitel beschrieben, vorbereitet, so kann dieser nun mittels der Methode #beginTransfer(Transfer, ...diverse Callbacks) asynchron bereitgestellt werden. Folgende Parameter müssen dabei angegeben werden:

  • Der vorbereitete Transfer
  • Diverse Callbacks zur Anzeige des Transferfortschritts

Entgegen dem synchronen Upload wird diese Methode unmittelbar abgeschlossen, nachdem der Transfer in einem eigenen Thread gestartet wurde. Ist der Transfer abgeschlossen, so wird die Methode uploadComplete des übergebenen IUploadCompleteHandlers aufgerufen.

Einen Transfer abbrechen

Wenn ein bereits gestarteter Transfer abgebrochen werden soll, so können Sie die Methode cancelTransfer() des Clients verwenden. Diese Methode stoppt den aktuellen Dateiuploadprozess und bricht den Transfer ab. Ein Transfer kann nur dann abgebrochen werden, wenn sich dieser im Uploadprozess befindet. Sobald alle Dateien des Transfers auf den Server hochgeladen wurden, ist der Transfer vollständig und kann nicht mehr über die API abgebrochen werden. Möchten Sie den Transfer nicht mehr abrufbar machen, nutzen Sie die Funktion "Transfer zurückziehen".

Durchführen eines asynchronen Transfers

 private static void performTransferSynchronous() {
 	// First create the Client instance
 	// Create a WebServiceUri for your Cryptshare Server 
 	WebServiceUri serviceUri = new WebServiceUri("https://cryptshare.server.com");
  
 	// Create a CryptshareConnection instance for your WebServiceUri
 	CryptshareConnection connection = new CryptshareConnection(serviceUri);
  
 	// Create the Client instance with the sender's email address, 
 	// the CryptshareConnection, and the path to the verification store.
 	Client client = new Client("sender_email@server.com", connection, Paths.get("C:\\temp"));
 
 	// Prepare the transfer object as described in the example above
 	Transfer transfer = ...
 
 	// Perform an asynchronous transfer with a new anonymous TransferUploadListener instance
 	// Method will return immediately
 	client.beginTransfer(transfer,
 					   new UploadProgressChangedHandler(),
 					   new UploadCompleteHandler(),
 					   new UploadInterruptedHandler(),
 					   new UploadCancelledHandler(),
 					   1000);
 }
 
 public class UploadProgressChangedHandler implements IUploadProgressChangedHandler {
 	@Override
 	public void progressChanged(String currentFileNo, String currentFileName, double bytesUploaded, double bytesTotal, long bytesPerSecond) {
 		// This method is called repeatedly with the current upload data
 		// Our upload listener will just output the current progress to the console
 		double percent = ((bytesUploaded / bytesTotal) * 100.0);
 		System.out.println("Transfer progress ... " + ((int)percent) + "%");
 	}
 }
 
 public class UploadCompleteHandler implements IUploadCompleteHandler {
 	@Override
 	public void uploadComplete(Map<String, String> urlMappings, Map<String, String> smtpMappings, String serverGenPassword, TransferError transferError,
 			String trackingId) {
 		// this method is called when all files of the transfer have been uploaded
 		System.out.println("Upload completed!");
 	}
 }
 
 public class UploadInterruptedHandler implements IUploadInterruptedHandler {
 	@Override
 	public void uploadInterrupted(CryptshareException cryptshareException) {
 		// this method is called when an exception occurs during the file upload
     	System.out.println("An exception occurred during the upload: " + cryptshareException);
 	}
 }
 
 public class UploadCancelledHandler implements IUploadCancelledHandler {
 	@Override
 	public void cancelled() {
 		// this method is called when the transfer has been cancelled 
 		// using the cancelTransfer() method
 		System.out.println("The transfer has been canceled!");
 	}
 }