Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Allow applet access to printer - once and for all

Allow applet access to printer - once and for all

Scheduled Pinned Locked Moved Java
javajavascriptsecurityhelpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Klazen
    wrote on last edited by
    #1

    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?

    L R A 3 Replies Last reply
    0
    • K Klazen

      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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • L Lost User

        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

        K Offline
        K Offline
        Klazen
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • K Klazen

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • K Klazen

            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?

            R Offline
            R Offline
            RB Chowdary
            wrote on last edited by
            #5

            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:

            1 Reply Last reply
            0
            • K Klazen

              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?

              A Offline
              A Offline
              Andrew Thommo
              wrote on last edited by
              #6

              > 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.

              M 1 Reply Last reply
              0
              • A Andrew Thommo

                > 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.

                M Offline
                M Offline
                Marc Schabb
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups