public class security implements Testlet
{
public void test(TestHarness harness)
{
try {
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.getSystemEventQueue();
AWTEventListener listener = new TestEventListener();
Frame frame = new Frame();
Properties props = new Properties();
JobAttributes jobattrs = new JobAttributes();
PageAttributes pageattrs = new PageAttributes();
Permission[] listenToAllAWTEvents = new Permission[] {
new AWTPermission("listenToAllAWTEvents")};
Permission[] queuePrintJob = new Permission[] {
new RuntimePermission("queuePrintJob")};
Permission[] accessClipboard = new Permission[] {
new AWTPermission("accessClipboard")};
Permission[] accessEventQueue = new Permission[] {
new AWTPermission("accessEventQueue")};
TestSecurityManager sm = new TestSecurityManager(harness);
try {
sm.install();
// throwpoint: java.awt.Toolkit-addAWTEventListener
harness.checkPoint("addAWTEventListener");
try {
sm.prepareChecks(listenToAllAWTEvents);
toolkit.addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK);
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-removeAWTEventListener
harness.checkPoint("removeAWTEventListener");
try {
sm.prepareChecks(listenToAllAWTEvents);
toolkit.removeAWTEventListener(listener);
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getPrintJob(Frame, String, Properties)
harness.checkPoint("getPrintJob(3-arg)");
try {
sm.prepareHaltingChecks(queuePrintJob);
toolkit.getPrintJob(frame, "Test job", props);
harness.check(false);
}
catch (TestSecurityManager.SuccessException ex) {
harness.check(true);
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getPrintJob(Frame, String, JobAttributes, PageAttributes)
harness.checkPoint("getPrintJob(4-arg)");
try {
sm.prepareHaltingChecks(queuePrintJob);
toolkit.getPrintJob(frame, "Test job", jobattrs, pageattrs);
harness.check(false);
}
catch (TestSecurityManager.SuccessException ex) {
harness.check(true);
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getSystemClipboard
harness.checkPoint("getSystemClipboard");
try {
sm.prepareChecks(accessClipboard);
toolkit.getSystemClipboard();
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getSystemEventQueue
harness.checkPoint("getSystemEventQueue");
try {
sm.prepareChecks(accessEventQueue);
toolkit.getSystemEventQueue();
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");