Allow applet access to printer - once and for all
-
Hey all, I'm having trouble getting an applet to use the printer. Every time, it pops a message stating "The applet has requested access to the printer. Do you want to allow this action?" I check yes to an option underneath stating to always allow access, however, it seems that there is a lack of communication going on here, because the same message pops up next time. I've read that this can be fixed by adding this line to the java policy security file (java.policy): permission java.lang.RuntimePermission "queuePrintJob"; But that solution doesn't work well for me, because I can't have everyone that uses my applet change their security files to avoid the annoying popup. The applet is signed, however, it's print method is being called directly from javascript and so I think there may be a bit of security tightening going on there causing the problem. Is there a checkbox or a setting somewhere I can have my users set, or is there something I can do on my end?
-
Hey all, I'm having trouble getting an applet to use the printer. Every time, it pops a message stating "The applet has requested access to the printer. Do you want to allow this action?" I check yes to an option underneath stating to always allow access, however, it seems that there is a lack of communication going on here, because the same message pops up next time. I've read that this can be fixed by adding this line to the java policy security file (java.policy): permission java.lang.RuntimePermission "queuePrintJob"; But that solution doesn't work well for me, because I can't have everyone that uses my applet change their security files to avoid the annoying popup. The applet is signed, however, it's print method is being called directly from javascript and so I think there may be a bit of security tightening going on there causing the problem. Is there a checkbox or a setting somewhere I can have my users set, or is there something I can do on my end?
The problem here is that applets run in the browser, and browsers are not allowed access to system resources without the express permission of the PC user. Otherwise their systems could be compromised by webpages changing things without their knowledge. I don't think there is any way round this issue.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
The problem here is that applets run in the browser, and browsers are not allowed access to system resources without the express permission of the PC user. Otherwise their systems could be compromised by webpages changing things without their knowledge. I don't think there is any way round this issue.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
True, which is why there is a security policy file, which prevents access as the default. However, you can get around it by adding that line to the file. I was wondering if there was an easier way to change it, rather than editing that policy file by hand.
-
True, which is why there is a security policy file, which prevents access as the default. However, you can get around it by adding that line to the file. I was wondering if there was an easier way to change it, rather than editing that policy file by hand.
Klazen wrote:
I was wondering if there was an easier way to change it
Not that I am aware of; and remember it would still require every user of your applet to change their own system.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
Hey all, I'm having trouble getting an applet to use the printer. Every time, it pops a message stating "The applet has requested access to the printer. Do you want to allow this action?" I check yes to an option underneath stating to always allow access, however, it seems that there is a lack of communication going on here, because the same message pops up next time. I've read that this can be fixed by adding this line to the java policy security file (java.policy): permission java.lang.RuntimePermission "queuePrintJob"; But that solution doesn't work well for me, because I can't have everyone that uses my applet change their security files to avoid the annoying popup. The applet is signed, however, it's print method is being called directly from javascript and so I think there may be a bit of security tightening going on there causing the problem. Is there a checkbox or a setting somewhere I can have my users set, or is there something I can do on my end?
Hello Klazen, by seeing your post i am sending this Qus. if you dont mind can you provide the code for printing the file from applet. Please help me............. :confused:
-
Hey all, I'm having trouble getting an applet to use the printer. Every time, it pops a message stating "The applet has requested access to the printer. Do you want to allow this action?" I check yes to an option underneath stating to always allow access, however, it seems that there is a lack of communication going on here, because the same message pops up next time. I've read that this can be fixed by adding this line to the java policy security file (java.policy): permission java.lang.RuntimePermission "queuePrintJob"; But that solution doesn't work well for me, because I can't have everyone that uses my applet change their security files to avoid the annoying popup. The applet is signed, however, it's print method is being called directly from javascript and so I think there may be a bit of security tightening going on there causing the problem. Is there a checkbox or a setting somewhere I can have my users set, or is there something I can do on my end?
> The applet is signed, however, it's print method is being called directly from javascript and so I think there may be a bit of security tightening going on there causing the problem. You are correct. Wrap the call in a doPriviliged() method and it should work (in a trusted applet) without further intervention. Messing with policy files is not something I would recommend even for development purposes.
-
> The applet is signed, however, it's print method is being called directly from javascript and so I think there may be a bit of security tightening going on there causing the problem. You are correct. Wrap the call in a doPriviliged() method and it should work (in a trusted applet) without further intervention. Messing with policy files is not something I would recommend even for development purposes.
We tried this fix and it seems to be causing further problems. Our implementation is:
try { final Doc doc = new SimpleDoc (docBytes, javax.print.DocFlavor.BYTE\_ARRAY.AUTOSENSE, null); AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws PrintException { DocPrintJob printerJob = selectedPrinter.getPrintService().createPrintJob();; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); printerJob.print(doc, aset); result.setStatus("SUCCESS"); return null; } }); } catch (Exception e) { e.printStackTrace(); result.setStatus("FAILED"); }
We're using the doPrivileged call with PrivilegedExceptionAction so that we can report the failure to the server to be reported. The problem is we are now seeing in the production logs that a small percentage of the print jobs fail with PrivilegedActionException, which we never saw before. We have not been able to reproduce this in our test environments, so in fact we don't really know whether the previous versions were failing or not - maybe we're just seeing the exceptions in the logs now, but they were always there.