Example usage for java.security AccessController checkPermission

List of usage examples for java.security AccessController checkPermission

Introduction

In this page you can find the example usage for java.security AccessController checkPermission.

Prototype


public static void checkPermission(Permission perm) throws AccessControlException 

Source Link

Document

Determines whether the access request indicated by the specified permission should be allowed or denied, based on the current AccessControlContext and security policy.

Usage

From source file:com.sshtools.sshterm.SshTerminalPanel.java

public void init(SshToolsApplication application) throws SshToolsApplicationException {
    super.init(application);
    boolean kerb_support = false;
    if (PreferencesStore.get(PREF_KRB5_MYPROXY_USE, "NONE").indexOf("true") >= 0)
        kerb_support = true;/*from w ww  . j ava2 s  . co  m*/

    //  Additional connection tabs
    if (kerb_support == true) {
        additionalTabs = new SshToolsConnectionTab[] { new SshTermCommandTab(), new SshTermTerminalTab(),
                new GSIAuthTab(), new XForwardingTab(), new SshToolsConnectionKerberosTab() };
        SshTerminalPanel.PREF_KRB5_MYPROXY_ENABLED = true;
    } else {
        additionalTabs = new SshToolsConnectionTab[] { new SshTermCommandTab(), new SshTermTerminalTab(),
                new GSIAuthTab(), new XForwardingTab() };
        SshTerminalPanel.PREF_KRB5_MYPROXY_ENABLED = false;

    }
    //
    //portForwardingPane = new PortForwardingPane();

    //  Printing page format
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new RuntimePermission("queuePrintJob"));
        }

        try {
            PrinterJob job = PrinterJob.getPrinterJob();

            if (job == null) {
                throw new IOException("Could not get print page format.");
            }

            pageFormat = job.defaultPage();

            if (PreferencesStore.preferenceExists(PREF_PAGE_FORMAT_ORIENTATION)) {
                pageFormat.setOrientation(
                        PreferencesStore.getInt(PREF_PAGE_FORMAT_ORIENTATION, PageFormat.LANDSCAPE));

                Paper paper = new Paper();
                paper.setImageableArea(PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_X, 0),
                        PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_Y, 0),
                        PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_W, 0),
                        PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_H, 0));
                paper.setSize(PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_W, 0),
                        PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_H, 0));
                pageFormat.setPaper(paper);
            }
        } catch (Exception e) {
            showExceptionMessage("Error", e.getMessage());
        }
    } catch (AccessControlException ace) {
        ace.printStackTrace();
    }

    enableEvents(VDU_EVENTS);

    // Set up the actions
    initActions();

    // Create the status bar
    statusBar = new StatusBar();

    dataListener = new DataNotificationListener(statusBar);

    // Create our terminal emulation object
    try {
        emulation = createEmulation();
    } catch (IOException ioe) {
        throw new SshToolsApplicationException(ioe);
    }

    emulation.addTerminalListener(this);

    // Set a scrollbar for the terminal - doesn't seem to be as simple as this
    scrollBar = new JScrollBar(JScrollBar.VERTICAL);
    emulation.setBufferSize(1000);

    // Create our swing terminal and add it to the main frame
    terminal = new TerminalPanel(emulation) {
        public void processEvent(AWTEvent evt) {
            /** We can't add a MouseWheelListener because it was not available in 1.3, so direct processing of events is necessary */
            if (evt instanceof MouseEvent && evt.getID() == 507) {
                try {
                    Method m = evt.getClass().getMethod("getWheelRotation", new Class[] {});
                    SshTerminalPanel.this.scrollBar.setValue(SshTerminalPanel.this.scrollBar.getValue()
                            + (SshTerminalPanel.this.scrollBar.getUnitIncrement()
                                    * ((Integer) m.invoke(evt, new Object[] {})).intValue()
                                    * PreferencesStore.getInt(PREF_MOUSE_WHEEL_INCREMENT, 1)));

                } catch (Throwable t) {
                    //   In theory, this should never happen
                }
            } else {
                super.processEvent(evt);
            }
        }

        public void copyNotify() {
            copyAction.actionPerformed(null);
        }

    };
    terminal.requestFocus();
    terminal.setScrollbar(scrollBar);
    terminal.addMouseMotionListener(this);

    //terminal.addMouseWheelListener(this);
    // Center panel with terminal and scrollbar
    JPanel center = new JPanel(new BorderLayout());
    center.setBackground(Color.red);
    center.add(terminal, BorderLayout.CENTER);
    center.add(scrollBar, BorderLayout.EAST);

    // Show the context menu on mouse button 3 (right click)
    terminal.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) > 0) {
                getContextMenu()
                        .setLabel((getCurrentConnectionFile() == null) ? getApplication().getApplicationName()
                                : getCurrentConnectionFile().getName());
                getContextMenu().show(terminal, evt.getX(), evt.getY());
            } else if ((evt.getModifiers() & MouseEvent.BUTTON2_MASK) > 0) {
                pasteAction.actionPerformed(null);
            }
        }
    });

    //
    //        JPanel top = new JPanel(new BorderLayout());
    //        top.add(getJMenuBar(), BorderLayout.NORTH);
    //        top.add(north, BorderLayout.SOUTH);
    setLayout(new BorderLayout());
    add(center, BorderLayout.CENTER);

    //        add(top, BorderLayout.NORTH);
    // Make sure that the swing terminal has focus
    terminal.requestFocus();
}

From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java

public boolean checkPermission(Subject subject, final Permission permission) {
    try {// w  w  w  . j a  va 2s . c  om
        //Subject.doAs(subject, new PrivilegedAction()
        Subject.doAsPrivileged(subject, new PrivilegedAction() {
            public Object run() {
                AccessController.checkPermission(permission);
                return null;
            }
        }, null);
    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:com.sshtools.appframework.ui.SshToolsApplication.java

@SuppressWarnings("serial")
private void loadMRU() {
    try {//from w  w w. ja  v a2s .co m
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }
        File a = getApplicationPreferencesDirectory();
        if (a == null) {
            throw new AccessControlException("Application preferences directory not specified.");
        }
        InputStream in = null;
        MRUList mru = new MRUList();
        try {
            File f = new File(a, getApplicationName() + ".mru");
            if (f.exists()) {
                in = new FileInputStream(f);
                mru.reload(in);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtil.closeStream(in);
        }
        mruModel = new MRUListModel() {
            @Override
            public void add(File f) {
                super.add(f);
                saveMRU(SshToolsApplication.this);
            }

            @Override
            public void setMRUList(MRUList mru) {
                super.setMRUList(mru);
            }
        };
        mruModel.setMRUList(mru);
    } catch (AccessControlException ace) {
        ace.printStackTrace();
    }
}

From source file:com.sshtools.sshvnc.SshVNCPanel.java

private void initActions() {

    //  Create the action menu groups

    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File",

            'f', 0));

    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Edit", "Edit",

            'e', 10));

    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("View", "View",

            'v', 20));

    vncTab = new VNCTab( /*vnc*/);

    newAction = new NewAction() {

        public void actionPerformed(ActionEvent evt) {

            SshToolsConnectionProfile newProfile = newConnectionProfile(null);

            if (newProfile != null) {

                connect(newProfile, true);

            }/*from ww  w  .  j ava  2  s .  c  om*/

            else {

                log.info("New connection cancelled");

            }

        }

    };

    registerAction(newAction);

    closeAction = new CloseAction() {

        public void actionPerformed(ActionEvent evt) {

            closing = true;
            // Close on a thread to avoid blocking the event queue
            Thread thread = new Thread() {
                public void run() {
                    closeConnection(true);
                }
            };

            thread.start();

        }

    };

    registerAction(closeAction);

    refreshAction = new RefreshAction() {

        public void actionPerformed(ActionEvent evt) {

            refresh();

        }

    };

    registerAction(refreshAction);

    ctrlAltDelAction = new CtrlAltDelAction() {

        public void actionPerformed(ActionEvent evt) {

            try {

                vnc.sendCtrlAltDel();

            }

            catch (IOException ioe) {

                closeConnection(true);

                showErrorMessage(SshVNCPanel.this, "Error", ioe);

            }

        }

    };

    registerAction(ctrlAltDelAction);

    clipboardAction = new ClipboardAction() {

        public void actionPerformed(ActionEvent evt) {

            vnc.setClipboardVisible(!vnc.isClipboardVisible());

        }

    };

    registerAction(clipboardAction);

    if (getApplication().getMRUModel() != null) {

        registerAction(

                mruAction = new MRUActionImpl(getApplication().getMRUModel()));

    }

    connectionPropertiesAction = new ConnectionPropertiesAction() {

        public void actionPerformed(ActionEvent evt) {

            editConnection(getCurrentConnectionProfile());

        }

    };

    registerAction(connectionPropertiesAction);

    //  Only allow opening of files if allowed by the security manager

    try {

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "read"));

        }

        openAction = new OpenAction() {

            public void actionPerformed(ActionEvent evt) {

                open();

            }

        };

        registerAction(openAction);

    }

    catch (AccessControlException ace) {

        ace.printStackTrace();

    }

    //  Only allow saving of files if allowed by the security manager

    try {

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "write"));

        }

        saveAction = new SaveAction() {

            public void actionPerformed(ActionEvent evt) {

                saveConnection(false, getCurrentConnectionFile(),

                        getCurrentConnectionProfile());

            }

        };

        registerAction(saveAction);

        saveAsAction = new SaveAsAction() {

            public void actionPerformed(ActionEvent evt) {

                saveConnection(true, getCurrentConnectionFile(),

                        getCurrentConnectionProfile());

            }

        };

        registerAction(saveAsAction);

        recordAction = new RecordAction() {

            public void actionPerformed(ActionEvent evt) {

                startRecording();

            }

        };

        registerAction(recordAction);

        stopAction = new StopAction() {

            public void actionPerformed(ActionEvent evt) {

                stopRecording();

            }

        };

        registerAction(stopAction);

    }

    catch (AccessControlException ace) {

        ace.printStackTrace();

    }

    //  Only allow editing of connection file if read / write is allowed

    try {

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "write"));

        }

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "read"));

        }

        editAction = new EditAction() {

            public void actionPerformed(ActionEvent evt) {

                editConnection();

            }

        };

        registerAction(editAction);

    }

    catch (AccessControlException ace) {

        ace.printStackTrace();

    }

    java.util.List providers = SessionProviderFactory.getInstance().getSessionProviders();
    SessionProvider provider;
    SessionProviderAction action;
    for (Iterator it = providers.iterator(); it.hasNext();) {
        provider = (SessionProvider) it.next();
        action = new SessionProviderAction(provider);
        sessionActions.put(action.getActionCommand(), action);
        action.addActionListener(this);
        registerAction(action);
    }

}

From source file:com.sshtools.powervnc.PowerVNCPanel.java

private void initActions() {

    //  Create the action menu groups

    System.out.println("initActions");
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File",

            'f', 0));

    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Edit", "Edit",

            'e', 10));

    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("View", "View",

            'v', 20));

    vncTab = new VNCTab( /*vnc*/);

    desktopAction = new DesktopAction() {

        public void actionPerformed(ActionEvent evt) {

            try {
                authenticationComplete(false);
            } catch (SshException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();/*from  w  w w.j av  a2 s .com*/
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            /*
                    newProfile = newConnectionProfile(null);
                    
                    if (newProfile != null) {
                    
                      connect(newProfile, true);
                    
                    }
                    
                    else {
                    
                      log.info("New connection cancelled");
                    
                    }
            */
        }

    };

    registerAction(desktopAction);

    closeAction = new CloseAction() {

        public void actionPerformed(ActionEvent evt) {

            closing = true;
            // Close on a thread to avoid blocking the event queue
            Thread thread = new Thread() {
                public void run() {
                    closeConnection(true);
                }
            };

            thread.start();

        }

    };

    registerAction(closeAction);

    filemanagerAction = new FileManagerAction() {

        public void actionPerformed(ActionEvent evt) {

            new JFtp(ssh);
            //         refresh();

        }

    };

    registerAction(filemanagerAction);

    ctrlAltDelAction = new CtrlAltDelAction() {

        public void actionPerformed(ActionEvent evt) {

            try {

                vnc.sendCtrlAltDel();

            }

            catch (IOException ioe) {

                closeConnection(true);

                showErrorMessage(PowerVNCPanel.this, "Error", ioe);

            }

        }

    };

    registerAction(ctrlAltDelAction);

    clipboardAction = new ClipboardAction() {

        public void actionPerformed(ActionEvent evt) {

            vnc.setClipboardVisible(!vnc.isClipboardVisible());

        }

    };

    registerAction(clipboardAction);

    if (getApplication().getMRUModel() != null) {

        registerAction(

                mruAction = new MRUActionImpl(getApplication().getMRUModel()));

    }

    connectionPropertiesAction = new ConnectionPropertiesAction() {

        public void actionPerformed(ActionEvent evt) {

            editConnection(getCurrentConnectionProfile());

        }

    };

    registerAction(connectionPropertiesAction);

    //  Only allow opening of files if allowed by the security manager

    try {

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "read"));

        }

        openAction = new OpenAction() {

            public void actionPerformed(ActionEvent evt) {

                open();

            }

        };

        registerAction(openAction);

    }

    catch (AccessControlException ace) {

        ace.printStackTrace();

    }

    //  Only allow saving of files if allowed by the security manager

    try {

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "write"));

        }

        saveAction = new SaveAction() {

            public void actionPerformed(ActionEvent evt) {

                saveConnection(false, getCurrentConnectionFile(),

                        getCurrentConnectionProfile());

            }

        };

        registerAction(saveAction);

        saveAsAction = new SaveAsAction() {

            public void actionPerformed(ActionEvent evt) {

                saveConnection(true, getCurrentConnectionFile(),

                        getCurrentConnectionProfile());

            }

        };

        registerAction(saveAsAction);

        recordAction = new RecordAction() {

            public void actionPerformed(ActionEvent evt) {

                startRecording();

            }

        };

        registerAction(recordAction);

        stopAction = new StopAction() {

            public void actionPerformed(ActionEvent evt) {

                stopRecording();

            }

        };

        registerAction(stopAction);

    }

    catch (AccessControlException ace) {

        ace.printStackTrace();

    }

    //  Only allow editing of connection file if read / write is allowed

    try {

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "write"));

        }

        if (System.getSecurityManager() != null) {

            AccessController.checkPermission(

                    new FilePermission("<<ALL FILES>>", "read"));

        }

        editAction = new EditAction() {

            public void actionPerformed(ActionEvent evt) {

                editConnection();

            }

        };

        registerAction(editAction);

    }

    catch (AccessControlException ace) {

        ace.printStackTrace();

    }

    java.util.List providers = SessionProviderFactory.getInstance().getSessionProviders();
    SessionProvider provider;
    SessionProviderAction action;
    for (Iterator it = providers.iterator(); it.hasNext();) {
        provider = (SessionProvider) it.next();
        action = new SessionProviderAction(provider);
        sessionActions.put(action.getActionCommand(), action);
        action.addActionListener(this);
        registerAction(action);
    }

}

From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java

/**
 *
 *
 * @param disconnect//from   w  ww  .j  a v a  2s .  c o  m
 */
public void closeConnection(boolean disconnect) {
    //
    if (isNeedSave() && (currentConnectionFile != null)) { // Stop save dialog box when not using a pre-existing profile.
        //  Only allow saving of files if allowed by the security manager
        try {
            if (System.getSecurityManager() != null) {
                AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));

                if (JOptionPane.showConfirmDialog(this, "You have unsaved changes to the connection "
                        + ((currentConnectionFile == null) ? "<Untitled>" : currentConnectionFile.getName())
                        + ".\nDo you want to save the changes now?", "Unsaved changes",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                    saveConnection(false, getCurrentConnectionFile(), getCurrentConnectionProfile());
                    setNeedSave(false);
                }
            }
        } catch (AccessControlException ace) {
            log.warn("Changes made to connection, but security manager won't allow saving of files.");
        }
    }

    //setCurrentConnectionFile(null);
}

From source file:com.ecyrd.jspwiki.auth.SecurityVerifier.java

/**
 * Verifies that a particular Principal possesses a Permission, as defined
 * in the security policy file.//from   ww  w.j ava  2  s . c  om
 * @param principal the principal
 * @param permission the permission
 * @return the result, based on consultation with the active Java security
 *         policy
 */
protected final boolean verifyStaticPermission(Principal principal, final Permission permission) {
    Subject subject = new Subject();
    subject.getPrincipals().add(principal);
    boolean allowedByGlobalPolicy = ((Boolean) Subject.doAsPrivileged(subject, new PrivilegedAction<Object>() {
        public Object run() {
            try {
                AccessController.checkPermission(permission);
                return Boolean.TRUE;
            } catch (AccessControlException e) {
                return Boolean.FALSE;
            }
        }
    }, null)).booleanValue();

    if (allowedByGlobalPolicy) {
        return true;
    }

    // Check local policy
    Principal[] principals = new Principal[] { principal };
    return m_engine.getAuthorizationManager().allowedByLocalPolicy(principals, permission);
}

From source file:com.sshtools.sshterm.SshTermSessionPanel.java

private void initActions() {
    //  Create the action menu groups
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0));
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Edit", "Edit", 'e', 10));
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("View", "View", 'v', 20));
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 90));
    actions = new Vector();

    connectionPropertiesAction = new ConnectionPropertiesActionImpl();
    registerAction(connectionPropertiesAction);

    // newAction = new NewAction();
    //  registerAction(newAction);
    //  Only allow opening of files if allowed by the security manager
    try {//  w w  w .  ja  v  a  2  s.co m
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "read"));
        }

        //openAction = new OpenAction();
        // registerAction(openAction);
        playAction = new PlayAction();
        registerAction(playAction);
    } catch (AccessControlException ace) {
        log.warn("File reading actions are not available");
    }

    //  Only allow saving of files if allowed by the security manager
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }

        // saveAction = new SaveAction();
        // registerAction(saveAction);
        //  saveAsAction = new SaveAsAction();
        //  registerAction(saveAsAction);
        recordAction = new RecordAction();
        registerAction(recordAction);
        stopAction = new StopAction();
        registerAction(stopAction);
    } catch (AccessControlException ace) {
        log.warn("File write actions are not available");
    }

    //  Only allow editing of connection file if read / write is allowed
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }

        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "read"));
        }

        // editAction = new EditActionImpl();
        // registerAction(editAction);
    } catch (AccessControlException ace) {
        log.warn("Read / write actions are not available");
    }

    //  Checking if printing is allowed
    if (pageFormat != null) {
        try {
            if (System.getSecurityManager() != null) {
                AccessController.checkPermission(new RuntimePermission("queuePrintJob"));
            }

            printAction = new PrintActionImpl();
            registerAction(printAction);
            printPreviewAction = new PrintPreviewActionImpl();
            registerAction(printPreviewAction);
        } catch (AccessControlException ace) {
            log.warn("Print actions are not available");
        }
    }

    //  Always allow refreshing of terminal
    refreshAction = new RefreshActionImpl();
    registerAction(refreshAction);

    //  Always allow closing of connect
    closeAction = new CloseAction();
    registerAction(closeAction);

    //  Copy / Paste
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new AWTPermission("accessClipboard"));
        }

        copyAction = new CopyActionImpl();
        registerAction(copyAction);
        pasteAction = new PasteActionImpl();
        registerAction(pasteAction);
    } catch (AccessControlException ace) {
    }

    //  Theres no point in having the keygen action if we can't write to local file
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }

        //  keygenAction = new KeygenAction();
        // registerAction(keygenAction);
    } catch (AccessControlException ace) {
        log.warn("Keygen actions is not available");
    }

    //  Clear action
    clearAction = new ClearActionImpl();
    registerAction(clearAction);

    // Remove stuff we dont want
    deregisterAction(getAction("Options"));
    setActionVisible("New Window", false);
    setActionVisible("About", false);
}

From source file:com.sshtools.sshterm.SshTerminalPanel.java

private void initActions() {
    //  Create the action menu groups
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0));
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Edit", "Edit", 'e', 10));
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("View", "View", 'v', 20));
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Proxy", "Proxy", 'p', 80));
    registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 90));
    actions = new Vector();

    // MRU//www  .j  a  v a2  s  .c  o  m
    if (getApplication().getMRUModel() != null) {
        registerAction(mruAction = new MRUActionImpl(getApplication().getMRUModel()));
    }

    //
    connectionPropertiesAction = new ConnectionPropertiesActionImpl();
    registerAction(connectionPropertiesAction);
    newAction = new NewAction();
    registerAction(newAction);

    //  Only allow opening of files if allowed by the security manager
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "read"));
        }

        openAction = new OpenAction();
        registerAction(openAction);
        playAction = new PlayAction();
        registerAction(playAction);
    } catch (AccessControlException ace) {
        log.warn("File reading actions are not available");
    }

    //  Only allow saving of files if allowed by the security manager
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }

        saveAction = new SaveAction();
        registerAction(saveAction);
        saveAsAction = new SaveAsAction();
        registerAction(saveAsAction);
        recordAction = new RecordAction();
        registerAction(recordAction);
        stopAction = new StopAction();
        registerAction(stopAction);
    } catch (AccessControlException ace) {
        log.warn("File write actions are not available");
    }

    //  Only allow editing of connection file if read / write is allowed
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }

        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "read"));
        }

        editAction = new EditActionImpl();
        registerAction(editAction);
    } catch (AccessControlException ace) {
        log.warn("Read / write actions are not available");
    }

    //  Checking if printing is allowed
    if (pageFormat != null) {
        try {
            if (System.getSecurityManager() != null) {
                AccessController.checkPermission(new RuntimePermission("queuePrintJob"));
            }

            printAction = new PrintActionImpl();
            registerAction(printAction);
            printPreviewAction = new PrintPreviewActionImpl();
            registerAction(printPreviewAction);
        } catch (AccessControlException ace) {
            log.warn("Print actions are not available");
        }
    }

    //  Always allow refreshing of terminal
    refreshAction = new RefreshActionImpl();
    registerAction(refreshAction);

    //  Always allow closing of connect
    closeAction = new CloseAction();
    registerAction(closeAction);

    //  Copy / Paste
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new AWTPermission("accessClipboard"));
        }

        copyAction = new CopyActionImpl();
        registerAction(copyAction);
        pasteAction = new PasteActionImpl();
        registerAction(pasteAction);
    } catch (AccessControlException ace) {
    }

    //  Theres no point in having the keygen action if we can't write to local file
    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }

        keygenAction = new KeygenAction();
        registerAction(keygenAction);
    } catch (AccessControlException ace) {
        log.warn("Keygen actions is not available");
    }

    //  Clear action
    clearAction = new ClearActionImpl();
    registerAction(clearAction);

    // GSI options
    proxyInfoAction = new ProxyInfoAction();
    registerAction(proxyInfoAction);
    proxyDestroyAction = new ProxyDestroyAction();
    registerAction(proxyDestroyAction);

    // Secure Tunneling
    /*try {
      SessionProvider provider = SessionProviderFactory.getInstance().getProvider("tunneling");
      if(provider!=null) {
        tunnelingAction = (StandardAction)new SessionProviderAction(
    provider);
        registerAction(tunnelingAction);
      }
         }
         catch (Throwable t) {
      log.info(
          "Secure Tunneling not available on CLASSPATH");
         }
         //  ShiFT action
         try {
      SessionProvider provider = SessionProviderFactory.getInstance().getProvider("shift");
      if(provider!=null) {
        shiftAction = (StandardAction)new SessionProviderAction(
    provider);
        registerAction(shiftAction);
      }
         }
         catch (Throwable t) {
      log.info(
          "ShiFT not available on CLASSPATH");
         }*/

    java.util.List providers = SessionProviderFactory.getInstance().getSessionProviders();
    SessionProvider provider;
    SessionProviderAction action;
    for (Iterator it = providers.iterator(); it.hasNext();) {
        provider = (SessionProvider) it.next();
        action = new SessionProviderAction(provider);
        sessionActions.put(action.getActionCommand(), action);
        registerAction(action);
    }
}

From source file:org.apache.jxtadoop.security.authorize.ServiceAuthorizationManager.java

/**
 * Check if the given {@link Subject} has all of necessary {@link Permission} 
 * set.// w  w  w .j av a2  s .c  o m
 * 
 * @param user <code>Subject</code> to be authorized
 * @param permissions <code>Permission</code> set
 * @throws AuthorizationException if the authorization failed
 */
private static void checkPermission(final Subject user, final Permission... permissions)
        throws AuthorizationException {
    try {
        Subject.doAs(user, new PrivilegedExceptionAction<Void>() {
            public Void run() throws Exception {
                try {
                    for (Permission permission : permissions) {
                        AccessController.checkPermission(permission);
                    }
                } catch (AccessControlException ace) {
                    LOG.info("Authorization failed for " + UserGroupInformation.getCurrentUGI(), ace);
                    throw new AuthorizationException(ace);
                }
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw new AuthorizationException(e.getException());
    }
}