Java Agent and java Policy in Domino

Hi,I wanted to Capture screen ,and Save it to a fileso ,I use Robot class in java!

and modify to java.policy file:

domon\jvm\lib\security\java.policy

Can you help me!!!

Thanks very much!!

ERROR:

java.security.AccessControlException: access denied (java.awt.AWTPermission *)

at java.security.AccessControlContext.checkPermission(AccessControlContext.java:292)

at java.security.AccessController.checkPermission(AccessController.java:476)

at JavaAgent.NotesMain(JavaAgent.java:23)

at lotus.domino.AgentBase.runNotes(Unknown Source)

at lotus.domino.NotesThread.run(Unknown Source)

That Code:

import lotus.domino.*;

import javax.swing.*;

import java.awt.*;

import java.awt.Rectangle;

import java.io.File;

import java.awt.image.RenderedImage;

import java.awt.AWTException;

import java.io.IOException;

import javax.imageio.ImageIO;

import java.awt.AWTPermission;

import java.security.AccessController;

public class JavaAgent extends AgentBase {

public void NotesMain() {



	try {

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();

			

		// (您的程式碼移至此處) 

		

		AccessController.checkPermission(new AWTPermission("*"));

		Robot robot = new Robot();

		

		Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());

		JOptionPane.showMessageDialog(null,"Area");

		File target = new File("d:\\","test.jpg");

		saveImageToFile(robot.createScreenCapture(area),target);

		

		} catch(Exception e) 

	{

		JOptionPane.showMessageDialog(null,e);

		e.printStackTrace();

	}

}



public void saveImageToFile(RenderedImage renderedImage,File target){

	try {

		ImageIO.write(renderedImage,"jpg",target);

		} catch(IOException e)

		{

			System.err.println(e);

			}

		

}

}

Subject: Java Agent and java Policy in Domino

Hi,

Check out the following URL.

Basically you need to add the required Security setting in order for AWT to have access to the screen.

If you want to enable everything (for yourself) just add the following to the java.policy

grant{

  permission java.security.AllPermission;

}

… You may need to add that to the other grant lines. Also it won’t take effect until you restart the client. I wouldn’t recommend that setting though in a production environment.