cancel
Showing results for 
Search instead for 
Did you mean: 

Adding cryption (GPG) workflow

pnnerveza
Champ in-the-making
Champ in-the-making
Hi there,

Help please. I'm trying to include a workflow of running a java script that will decrypt a file using GPG. My code is as follows;

[size=75]// find the backup folder - create if not already exists
var backupFolder = space.childByNamePath("Backup");
if (backupFolder == null && space.hasPermission("CreateChildren"))
{
   // create the folder for the first time
   backupFolder = space.createFolder("Backup");
}
if (backupFolder != null && backupFolder.hasPermission("CreateChildren"))
{
   // copy the doc into the backup folder
   var copy = document.copy(backupFolder);
   if (copy != null)
   {
      // change the name so we know it's a backup
      //copy.name = "Backup of " + copy.name;
      //copy.save();[/size]
      //set the variable for decryption   
path = copy.name;
cmd="gpg –no-secmem-warning –passphrase-fd 0 –batch –decrypt  "
      //execute decryption
Runtime.getRuntime().exec(cmd + path);
   }
}


The script was saved at "Script" space. Then i added a "run a script" using the script above in one of my spaces. But when i uploaded a file to the space, i encountered the error below;


A system error happened during the operation: Transaction didn't commit: Failed to execute script 'workspace://SpacesStore/e3198187-90a3-11db-ac28-f9382764acb5': ReferenceError: "Runtime" is not defined. (AlfrescoScript#20)


Will someone help me on this.

Thanks
1 REPLY 1

kevinr
Star Contributor
Star Contributor
For security reason direct access to JVM classes from JavaScript files is prohibited. As it wouldn't take a lot of imagination to come up with a easily executable script that - using java code - could perform all sorts of naughty operations on the server that a user with low Read level access shouldn't be able to perform.

If you need to execute custom java code, then you can extend the JavaScript API with your own objects - for example we have added custom objects for Logging and Session access. In 2.0 (or HEAD code from SVN) the JavaScript API is fully extending by config and doesn't require recompiling Alfresco:
http://wiki.alfresco.com/wiki/JavaScript_API#Adding_custom_Script_APIs

Thanks,

Kevin