United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6664915 SecurityException using javax.print APIs when queuePrintJob permission is granted.
JDK-6664915 : SecurityException using javax.print APIs when queuePrintJob permission is granted.

Details
Type:
Bug
Submit Date:
2008-02-19
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
generic
Sub-Component:
2d
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
In some circumstances, when

- printing on windows using the javax.print APIs,
- and a security manager is present
- and queuePrintJob permission is granted,

then a SecurityException may still be thrown.

Running the program below demonstrates this

java -Djava.security.manager=default -Djava.security.policy=print.policy

// print.policy 
grant {
  permission java.lang.RuntimePermission "queuePrintJob";
};


// PrintSE.java
import javax.print.attribute.*;

public class PrintSE implements Printable {

    public static void main(String[] args) throws Exception {
        GraphicsEnvironment.getLocalGraphicsEnvironment();

        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
        if (service == null) {
            return;
        }
        SimpleDoc doc =
             new SimpleDoc(new PrintSE(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.print(doc, new HashPrintRequestAttributeSet());
    }

    public int print(Graphics g, PageFormat pf, int pg) {
       if (pg > 0) return NO_SUCH_PAGE;
       g.drawString("Test passes.", 100, 100);
       return PAGE_EXISTS;
   }
}

                                    

Comments
WORK AROUND

1. The exception occurs only the first time. The app can swallow it and re-try
2. This is specific to javax.print APIs, PrinterJob can be used instead.
3. Since to encounter this queuePrintJob permission must be granted, then it
may be possible to grant file read too.
                                     
2008-02-19
EVALUATION

The exception comes when listing fonts in the jre/lib/font directory in order
to register these fonts with GDI, so that GDI can use these fonts directly
when printing. The exception is specific to particular circumstances. 
See workaround section for workarounds
                                     
2008-02-19



Hardware and Software, Engineered to Work Together