Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6664915
Votes 0
Synopsis SecurityException using javax.print APIs when queuePrintJob permission is granted.
Category java:classes_2d
Reported Against
Release Fixed 7(b28), 6u10(b13) (Bug ID:2159278)
State 10-Fix Delivered, Verified, bug
Priority: 3-Medium
Related Bugs
Submit Date 19-FEB-2008
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;
   }
}
Posted Date : 2008-02-19 18:47:27.0
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.
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
Posted Date : 2008-02-19 18:47:27.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang