Hi everybody,
This is my first steps in the integration of a Java program inside LotusScript using LS2J.
I’ve created a small test db with a first LS agent calling a Java class to zip a file on my c-drive → No problem (probably because using standard Java Libraries)
Then a step further, I need to create an LS agent that should secure a given PDF with a password (to avoid editing,…).
We’ve found on the web, JAVA libraries doing that and put them in C:\Program Files\Lotus\notes\jvm\lib\ext
bcmail-jdk14-135.jar
bcprov-jdk14-135.jar
PDFBox-0.7.3.jar
The result is : a ‘java.lang.SecurityException’ during the execution.
Environment : Notes Client 7.0.2
We did a lot of search on this forum, on the web but without success.
We have tried to update Java.Profile… same result
Any idea on what could be this problem ?
Thanks in advance,
Thierry Dufrasne
IT Specialist
IBM Belgium
The agent:
(Options)
Uselsx “*javacon” 'Which lets you use Java from LotusScript
Use “PDFUtilities” 'A Java library that holds a function to do zipping
Initialize
Sub Initialize
Dim js As JAVASESSION
Dim pdfClass As JAVACLASS
Dim pdfFileObject As JavaObject
Dim inputFile As String, outputFile As String, password As String, returnCode As String
Set js = New JAVASESSION
Set pdfClass = js.GetClass("services.weblectures.pdf.MDEncrypt")
Set pdfFileObject = pdfClass.CreateObject
inputFile = "C:\workdir\test.pdf"
outputFile = "C:\workdir\test_locked.pdf"
password = "Test"
returnCode = ""
returnCode = pdfFileObject.encrypt(password, inputFile, outputFile) 'Calling the lock function
If Not returnCode = "Ok" Then
Print "An Error occurred : " & returnCode
Else
Print "Locking went OK"
End If
End Sub
The Class
package services.weblectures.pdf;
import java.io.IOException;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.pdmodel.encryption.AccessPermission;
import org.pdfbox.pdmodel.encryption.StandardProtectionPolicy;
public class MDEncrypt {
public static void main(String[] args)
{
MDEncrypt encrypt = new MDEncrypt();
encrypt.encrypt(args[0], args[1], args[2]);
}
public String encrypt(String strOwnerPassword, String strInputFile, String strOutputFile)
{
AccessPermission ap = new AccessPermission();
int keyLength = 40;
PDDocument document = null;
try
{
ap.setCanModify(false);
document = PDDocument.load( strInputFile );
StandardProtectionPolicy spp =
new StandardProtectionPolicy(strOwnerPassword, "", ap);
spp.setEncryptionKeyLength(keyLength);
document.protect(spp);
document.save(strOutputFile);
return "Ok";
}
catch(Exception e)
{
return e.toString();
}
finally
{
try
{
document.close();
}
catch(IOException e)
{
return e.toString();
}
}
}
}