Search in sources :

Example 56 with PrivilegedAction

use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.

the class FileDialogFilter method init.

private void init(FileDialog target) {
    //new Dialog(target, target.getTitle(), false);
    fileDialog = target;
    this.title = target.getTitle();
    this.mode = target.getMode();
    this.target = target;
    this.filter = target.getFilenameFilter();
    savedFile = target.getFile();
    savedDir = target.getDirectory();
    // Shouldn't save 'user.dir' to 'savedDir'
    // since getDirectory() will be incorrect after handleCancel
    userDir = (String) AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            return System.getProperty("user.dir");
        }
    });
    installStrings();
    gbl = new GridBagLayout();
    gblButtons = new GridBagLayout();
    gbc = new GridBagConstraints();
    fileDialog.setLayout(gbl);
    // create components
    buttons = new Panel();
    buttons.setLayout(gblButtons);
    actionButtonText = (target.getMode() == FileDialog.SAVE) ? saveButtonText : openButtonText;
    openButton = new Button(actionButtonText);
    filterButton = new Button(filterLabelText);
    cancelButton = new Button(cancelButtonText);
    directoryList = new List();
    fileList = new List();
    filterField = new TextField();
    selectionField = new TextField();
    boolean isMultipleMode = AWTAccessor.getFileDialogAccessor().isMultipleMode(target);
    fileList.setMultipleMode(isMultipleMode);
    // the insets used by the components in the fileDialog
    Insets noInset = new Insets(0, 0, 0, 0);
    Insets textFieldInset = new Insets(0, 8, 0, 8);
    Insets leftListInset = new Insets(0, 8, 0, 4);
    Insets rightListInset = new Insets(0, 4, 0, 8);
    Insets separatorInset = new Insets(8, 0, 0, 0);
    Insets labelInset = new Insets(0, 8, 0, 0);
    Insets buttonsInset = new Insets(10, 8, 10, 8);
    // add components to GridBagLayout "gbl"
    Font f = new Font(Font.DIALOG, Font.PLAIN, 12);
    Label label = new Label(pathLabelText);
    label.setFont(f);
    addComponent(label, gbl, gbc, 0, 0, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
    // Fixed 6260650: FileDialog.getDirectory() does not return null when file dialog is cancelled
    // After showing we should display 'user.dir' as current directory
    // if user didn't set directory programatically
    pathField = new TextField(savedDir != null ? savedDir : userDir);
    pathChoice = new Choice() {

        public Dimension getPreferredSize() {
            return new Dimension(PATH_CHOICE_WIDTH, pathField.getPreferredSize().height);
        }
    };
    pathPanel = new Panel();
    pathPanel.setLayout(new BorderLayout());
    pathPanel.add(pathField, BorderLayout.CENTER);
    pathPanel.add(pathChoice, BorderLayout.EAST);
    //addComponent(pathField, gbl, gbc, 0, 1, 2,
    //             GridBagConstraints.WEST, (Container)fileDialog,
    //             1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
    //addComponent(pathChoice, gbl, gbc, 1, 1, GridBagConstraints.RELATIVE,
    //            GridBagConstraints.WEST, (Container)fileDialog,
    //           1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
    addComponent(pathPanel, gbl, gbc, 0, 1, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
    label = new Label(filterLabelText);
    label.setFont(f);
    addComponent(label, gbl, gbc, 0, 2, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
    addComponent(filterField, gbl, gbc, 0, 3, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
    label = new Label(foldersLabelText);
    label.setFont(f);
    addComponent(label, gbl, gbc, 0, 4, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
    label = new Label(filesLabelText);
    label.setFont(f);
    addComponent(label, gbl, gbc, 1, 4, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
    addComponent(directoryList, gbl, gbc, 0, 5, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 1, GridBagConstraints.BOTH, leftListInset);
    addComponent(fileList, gbl, gbc, 1, 5, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 1, GridBagConstraints.BOTH, rightListInset);
    label = new Label(enterFileNameLabelText);
    label.setFont(f);
    addComponent(label, gbl, gbc, 0, 6, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
    addComponent(selectionField, gbl, gbc, 0, 7, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
    addComponent(new Separator(fileDialog.size().width, 2, Separator.HORIZONTAL), gbl, gbc, 0, 8, 15, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, separatorInset);
    // add buttons to GridBagLayout Buttons
    addComponent(openButton, gblButtons, gbc, 0, 0, 1, GridBagConstraints.WEST, (Container) buttons, 1, 0, GridBagConstraints.NONE, noInset);
    addComponent(filterButton, gblButtons, gbc, 1, 0, 1, GridBagConstraints.CENTER, (Container) buttons, 1, 0, GridBagConstraints.NONE, noInset);
    addComponent(cancelButton, gblButtons, gbc, 2, 0, 1, GridBagConstraints.EAST, (Container) buttons, 1, 0, GridBagConstraints.NONE, noInset);
    // add ButtonPanel to the GridBagLayout of this class
    addComponent(buttons, gbl, gbc, 0, 9, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, buttonsInset);
    fileDialog.setSize(400, 400);
    // Update choice's popup width
    XChoicePeer choicePeer = (XChoicePeer) pathChoice.getPeer();
    choicePeer.setDrawSelectedItem(false);
    choicePeer.setAlignUnder(pathField);
    filterField.addActionListener(this);
    selectionField.addActionListener(this);
    directoryList.addActionListener(this);
    directoryList.addItemListener(this);
    fileList.addItemListener(this);
    fileList.addActionListener(this);
    openButton.addActionListener(this);
    filterButton.addActionListener(this);
    cancelButton.addActionListener(this);
    pathChoice.addItemListener(this);
    pathField.addActionListener(this);
    // b6227750 FileDialog is not disposed when clicking the 'close' (X) button on the top right corner, XToolkit
    target.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            handleCancel();
        }
    });
    // 6259434 PIT: Choice in FileDialog is not responding to keyboard interactions, XToolkit
    pathChoice.addItemListener(this);
}
Also used : PrivilegedAction(java.security.PrivilegedAction)

Example 57 with PrivilegedAction

use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.

the class CPrinterJob method print.

@Override
public void print(PrintRequestAttributeSet attributes) throws PrinterException {
    // NOTE: Some of this code is copied from RasterPrinterJob.
    // this code uses javax.print APIs
    // this will make it print directly to the printer
    // this will not work if the user clicks on the "Preview" button
    // However if the printer is a StreamPrintService, its the right path.
    PrintService psvc = getPrintService();
    if (psvc == null) {
        throw new PrinterException("No print service found.");
    }
    if (psvc instanceof StreamPrintService) {
        spoolToService(psvc, attributes);
        return;
    }
    setAttributes(attributes);
    // throw exception for invalid destination
    if (destinationAttr != null) {
        validateDestination(destinationAttr);
    }
    /* Get the range of pages we are to print. If the
         * last page to print is unknown, then we print to
         * the end of the document. Note that firstPage
         * and lastPage are 0 based page indices.
         */
    int firstPage = getFirstPage();
    int lastPage = getLastPage();
    if (lastPage == Pageable.UNKNOWN_NUMBER_OF_PAGES) {
        int totalPages = mDocument.getNumberOfPages();
        if (totalPages != Pageable.UNKNOWN_NUMBER_OF_PAGES) {
            lastPage = mDocument.getNumberOfPages() - 1;
        }
    }
    try {
        synchronized (this) {
            performingPrinting = true;
            userCancelled = false;
        }
        //Add support for PageRange
        PageRanges pr = (attributes == null) ? null : (PageRanges) attributes.get(PageRanges.class);
        int[][] prMembers = (pr == null) ? new int[0][0] : pr.getMembers();
        int loopi = 0;
        do {
            if (EventQueue.isDispatchThread()) {
                // This is an AWT EventQueue, and this print rendering loop needs to block it.
                onEventThread = true;
                printingLoop = AccessController.doPrivileged(new PrivilegedAction<SecondaryLoop>() {

                    @Override
                    public SecondaryLoop run() {
                        return Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
                    }
                });
                try {
                    //  it wait and block this thread.
                    if (printLoop(false, firstPage, lastPage)) {
                        // Start a secondary loop on EDT until printing operation is finished or cancelled
                        printingLoop.enter();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                // Fire off the print rendering loop on the AppKit, and block this thread
                //  until it is done.
                // But don't actually block... we need to come back here!
                onEventThread = false;
                try {
                    printLoop(true, firstPage, lastPage);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (++loopi < prMembers.length) {
                firstPage = prMembers[loopi][0] - 1;
                lastPage = prMembers[loopi][1] - 1;
            }
        } while (loopi < prMembers.length);
    } finally {
        synchronized (this) {
            // NOTE: Native code shouldn't allow exceptions out while
            // printing. They should cancel the print loop.
            performingPrinting = false;
            notify();
        }
        if (printingLoop != null) {
            printingLoop.exit();
        }
    }
// Normalize the collated, # copies, numPages, first/last pages. Need to
//  make note of pageRangesAttr.
// Set up NSPrintInfo with the java settings (PageFormat & Paper).
// Create an NSView for printing. Have knowsPageRange return YES, and give the correct
//  range, or MAX? if unknown. Have rectForPage do a peekGraphics check before returning
//  the rectangle. Have drawRect do the real render of the page. Have printJobTitle do
//  the right thing.
// Call NSPrintOperation, it will call NSView.drawRect: for each page.
// NSView.drawRect: will create a CPrinterGraphics with the current CGContextRef, and then
//  pass this Graphics onto the Printable with the appropriate PageFormat and index.
// Need to be able to cancel the NSPrintOperation (using code from RasterPrinterJob, be
//  sure to initialize userCancelled and performingPrinting member variables).
// Extensions available from AppKit: Print to PDF or EPS file!
}
Also used : PageRanges(javax.print.attribute.standard.PageRanges) PrivilegedAction(java.security.PrivilegedAction) java.awt.print(java.awt.print) javax.print(javax.print) sun.print(sun.print)

Example 58 with PrivilegedAction

use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.

the class SubjectDelegator method delegatedContext.

/* Return the AccessControlContext appropriate to execute an
       operation on behalf of the delegatedSubject.  If the
       authenticatedAccessControlContext does not have permission to
       delegate to that subject, throw SecurityException.  */
public AccessControlContext delegatedContext(AccessControlContext authenticatedACC, Subject delegatedSubject, boolean removeCallerContext) throws SecurityException {
    if (System.getSecurityManager() != null && authenticatedACC == null) {
        throw new SecurityException("Illegal AccessControlContext: null");
    }
    // Check if the subject delegation permission allows the
    // authenticated subject to assume the identity of each
    // principal in the delegated subject
    //
    Collection<Principal> ps = getSubjectPrincipals(delegatedSubject);
    final Collection<Permission> permissions = new ArrayList<>(ps.size());
    for (Principal p : ps) {
        final String pname = p.getClass().getName() + "." + p.getName();
        permissions.add(new SubjectDelegationPermission(pname));
    }
    PrivilegedAction<Void> action = new PrivilegedAction<Void>() {

        public Void run() {
            for (Permission sdp : permissions) {
                AccessController.checkPermission(sdp);
            }
            return null;
        }
    };
    AccessController.doPrivileged(action, authenticatedACC);
    return getDelegatedAcc(delegatedSubject, removeCallerContext);
}
Also used : PrivilegedAction(java.security.PrivilegedAction) Permission(java.security.Permission) SubjectDelegationPermission(javax.management.remote.SubjectDelegationPermission) SubjectDelegationPermission(javax.management.remote.SubjectDelegationPermission) Principal(java.security.Principal)

Example 59 with PrivilegedAction

use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.

the class ICC_Profile method activateDeferredProfile.

void activateDeferredProfile() throws ProfileDataException {
    byte[] profileData;
    FileInputStream fis;
    final String fileName = deferralInfo.filename;
    profileActivator = null;
    deferralInfo = null;
    PrivilegedAction<FileInputStream> pa = new PrivilegedAction<FileInputStream>() {

        public FileInputStream run() {
            File f = getStandardProfileFile(fileName);
            if (f != null) {
                try {
                    return new FileInputStream(f);
                } catch (FileNotFoundException e) {
                }
            }
            return null;
        }
    };
    if ((fis = AccessController.doPrivileged(pa)) == null) {
        throw new ProfileDataException("Cannot open file " + fileName);
    }
    try {
        profileData = getProfileDataFromStream(fis);
        fis.close();
    /* close the file */
    } catch (IOException e) {
        ProfileDataException pde = new ProfileDataException("Invalid ICC Profile Data" + fileName);
        pde.initCause(e);
        throw pde;
    }
    if (profileData == null) {
        throw new ProfileDataException("Invalid ICC Profile Data" + fileName);
    }
    try {
        cmmProfile = CMSManager.getModule().loadProfile(profileData);
    } catch (CMMException c) {
        ProfileDataException pde = new ProfileDataException("Invalid ICC Profile Data" + fileName);
        pde.initCause(c);
        throw pde;
    }
}
Also used : PrivilegedAction(java.security.PrivilegedAction) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 60 with PrivilegedAction

use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.

the class RenderingEngine method getInstance.

/**
     * Returns an instance of {@code RenderingEngine} as determined
     * by the installation environment and runtime flags.
     * <p>
     * A specific instance of the {@code RenderingEngine} can be
     * chosen by specifying the runtime flag:
     * <pre>
     *     java -Dsun.java2d.renderer=&lt;classname&gt;
     * </pre>
     *
     * If no specific {@code RenderingEngine} is specified on the command
     * or Ductus renderer is specified, it will attempt loading the
     * sun.dc.DuctusRenderingEngine class using Class.forName as a fastpath;
     * if not found, use the ServiceLoader.
     * If no specific {@code RenderingEngine} is specified on the command
     * line then the last one returned by enumerating all subclasses of
     * {@code RenderingEngine} known to the ServiceLoader is used.
     * <p>
     * Runtime tracing of the actions of the {@code RenderingEngine}
     * can be enabled by specifying the runtime flag:
     * <pre>
     *     java -Dsun.java2d.renderer.trace=&lt;any string&gt;
     * </pre>
     * @return an instance of {@code RenderingEngine}
     * @since 1.7
     */
public static synchronized RenderingEngine getInstance() {
    if (reImpl != null) {
        return reImpl;
    }
    reImpl = AccessController.doPrivileged(new PrivilegedAction<RenderingEngine>() {

        public RenderingEngine run() {
            final String ductusREClass = "sun.dc.DuctusRenderingEngine";
            String reClass = System.getProperty("sun.java2d.renderer", ductusREClass);
            try {
                Class<?> cls = Class.forName(reClass);
                return (RenderingEngine) cls.newInstance();
            } catch (ReflectiveOperationException ignored) {
            // not found
            }
            ServiceLoader<RenderingEngine> reLoader = ServiceLoader.loadInstalled(RenderingEngine.class);
            RenderingEngine service = null;
            for (RenderingEngine re : reLoader) {
                service = re;
                if (re.getClass().getName().equals(reClass)) {
                    break;
                }
            }
            return service;
        }
    });
    if (reImpl == null) {
        throw new InternalError("No RenderingEngine module found");
    }
    GetPropertyAction gpa = new GetPropertyAction("sun.java2d.renderer.trace");
    String reTrace = AccessController.doPrivileged(gpa);
    if (reTrace != null) {
        reImpl = new Tracer(reImpl);
    }
    return reImpl;
}
Also used : GetPropertyAction(sun.security.action.GetPropertyAction) PrivilegedAction(java.security.PrivilegedAction)

Aggregations

PrivilegedAction (java.security.PrivilegedAction)190 IOException (java.io.IOException)44 Subject (javax.security.auth.Subject)28 File (java.io.File)19 AccessControlContext (java.security.AccessControlContext)18 Method (java.lang.reflect.Method)13 InputStream (java.io.InputStream)12 URL (java.net.URL)11 LoginException (com.sun.enterprise.security.auth.login.common.LoginException)10 Field (java.lang.reflect.Field)10 URLClassLoader (java.net.URLClassLoader)10 Principal (java.security.Principal)10 Set (java.util.Set)9 PrivilegedActionException (java.security.PrivilegedActionException)8 Iterator (java.util.Iterator)8 PasswordCredential (com.sun.enterprise.security.auth.login.common.PasswordCredential)7 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)7 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)7 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)7 URISyntaxException (java.net.URISyntaxException)7