Example usage for java.lang RuntimePermission RuntimePermission

List of usage examples for java.lang RuntimePermission RuntimePermission

Introduction

In this page you can find the example usage for java.lang RuntimePermission RuntimePermission.

Prototype


public RuntimePermission(String name) 

Source Link

Document

Creates a new RuntimePermission with the specified name.

Usage

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

/**
 *
 *
 * @param application//from  w w w .j a  v  a  2 s. c o m
 *
 * @throws SshToolsApplicationException
 */
public void init(SshToolsApplication application) throws SshToolsApplicationException {
    super.init(application);

    //  Additional connection tabs
    additionalTabs = new SshToolsConnectionTab[] { new SshTermTerminalTab() };

    //  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[] {});
                    SshTermSessionPanel.this.scrollBar.setValue(SshTermSessionPanel.this.scrollBar.getValue()
                            + (SshTermSessionPanel.this.scrollBar.getUnitIncrement()
                                    * ((Integer) m.invoke(evt, new Object[] {})).intValue()
                                    * PreferencesStore.getInt(PREF_MOUSE_WHEEL_INCREMENT, 1)));

                } catch (Throwable t) {
                }
            } 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(getApplication().getApplicationName());
                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: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;/*w  w w.  ja v  a  2 s  .c o 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: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 {//from   ww  w.  ja  v a2s  . c om
        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//from ww w .  ja v  a  2  s.  co 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.jasper.compiler.JspRuntimeContext.java

/**
 * Method used to initialize SecurityManager data.
 *///from   w ww. j  av  a2  s  .  c o  m
private void initSecurity() {

    // Setup the PermissionCollection for this web app context
    // based on the permissions configured for the root of the
    // web app context directory, then add a file read permission
    // for that directory.
    Policy policy = Policy.getPolicy();
    if (policy != null) {
        try {
            // Get the permissions for the web app context
            String docBase = context.getRealPath("/");
            if (docBase == null) {
                docBase = options.getScratchDir().toString();
            }
            String codeBase = docBase;
            if (!codeBase.endsWith(File.separator)) {
                codeBase = codeBase + File.separator;
            }
            File contextDir = new File(codeBase);
            URL url = contextDir.getCanonicalFile().toURL();
            codeSource = new CodeSource(url, null);
            permissionCollection = policy.getPermissions(codeSource);

            // Create a file read permission for web app context directory
            if (!docBase.endsWith(File.separator)) {
                permissionCollection.add(new FilePermission(docBase, "read"));
                docBase = docBase + File.separator;
            } else {
                permissionCollection
                        .add(new FilePermission(docBase.substring(0, docBase.length() - 1), "read"));
            }
            docBase = docBase + "-";
            permissionCollection.add(new FilePermission(docBase, "read"));

            // Create a file read permission for web app tempdir (work)
            // directory
            String workDir = options.getScratchDir().toString();
            if (!workDir.endsWith(File.separator)) {
                permissionCollection.add(new FilePermission(workDir, "read"));
                workDir = workDir + File.separator;
            }
            workDir = workDir + "-";
            permissionCollection.add(new FilePermission(workDir, "read"));

            // Allow the JSP to access org.apache.jasper.runtime.HttpJspBase
            permissionCollection.add(new RuntimePermission("accessClassInPackage.org.apache.jasper.runtime"));

            if (parentClassLoader instanceof URLClassLoader) {
                URL[] urls = parentClassLoader.getURLs();
                String jarUrl = null;
                String jndiUrl = null;
                for (int i = 0; i < urls.length; i++) {
                    if (jndiUrl == null && urls[i].toString().startsWith("jndi:")) {
                        jndiUrl = urls[i].toString() + "-";
                    }
                    if (jarUrl == null && urls[i].toString().startsWith("jar:jndi:")) {
                        jarUrl = urls[i].toString();
                        jarUrl = jarUrl.substring(0, jarUrl.length() - 2);
                        jarUrl = jarUrl.substring(0, jarUrl.lastIndexOf('/')) + "/-";
                    }
                }
                if (jarUrl != null) {
                    permissionCollection.add(new FilePermission(jarUrl, "read"));
                    permissionCollection.add(new FilePermission(jarUrl.substring(4), "read"));
                }
                if (jndiUrl != null)
                    permissionCollection.add(new FilePermission(jndiUrl, "read"));
            }
        } catch (Exception e) {
            context.log("Security Init for context failed", e);
        }
    }
}

From source file:org.jboss.as.test.integration.security.loginmodules.negotiation.SPNEGOLoginModuleTestCase.java

/**
 * Creates {@link WebArchive}./*from  w w w. j a  va2 s .  c  om*/
 *
 * @return
 */
@Deployment(name = "WEB", testable = false)
public static WebArchive deployment() {
    LOGGER.debug("Web deployment");
    final WebArchive war = createWebApp(WEBAPP_NAME, "web-spnego-authn.xml", "SPNEGO");
    war.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(
            // Permissions for PropagateIdentityServlet to get delegation credentials DelegationCredentialContext.getDelegCredential()
            new RuntimePermission("org.jboss.security.negotiation.getDelegCredential"),
            // Permissions for PropagateIdentityServlet to read properties
            new PropertyPermission(GSSTestConstants.PROPERTY_PORT, "read"),
            new PropertyPermission(GSSTestConstants.PROPERTY_PRINCIPAL, "read"),
            new PropertyPermission(GSSTestConstants.PROPERTY_PASSWORD, "read"),
            // Permissions for GSSTestClient to connect to GSSTestServer
            new SocketPermission(TestSuiteEnvironment.getServerAddress(), "resolve,connect"),
            new SocketPermission(CoreUtils.getCannonicalHost(TestSuiteEnvironment.getServerAddress()),
                    "resolve,connect"),
            // Permissions for GSSTestClient to initiate gss context
            new ServicePermission(GSSTestConstants.PRINCIPAL, "initiate"),
            new ServicePermission("krbtgt/JBOSS.ORG@JBOSS.ORG", "initiate")), "permissions.xml");
    return war;
}

From source file:org.jboss.as.test.integration.ws.authentication.policy.AuthenticationPolicyContextTestCase.java

@Deployment(name = PICKETLINK_STS, managed = false, testable = false)
public static Archive<?> createPicketlinkStsDeployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, PICKETLINK_STS + ".war");
    war.addClass(PicketLinkSTSService.class);
    war.addAsResource(AuthenticationPolicyContextTestCase.class.getPackage(), "resources/sts-users.properties",
            "sts-users.properties");
    war.addAsResource(AuthenticationPolicyContextTestCase.class.getPackage(), "resources/sts-roles.properties",
            "sts-roles.properties");
    war.addAsResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/WEB-INF/sts_keystore.jks", "sts_keystore.jks");
    war.addAsWebInfResource(createFilteredAsset("resources/WEB-INF/picketlink-sts.xml"),
            "classes/picketlink-sts.xml");
    war.addAsWebInfResource(createFilteredAsset("resources/WEB-INF/wsdl/PicketLinkSTS.wsdl"),
            "wsdl/PicketLinkSTS.wsdl");
    war.addAsWebInfResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/WEB-INF/beans.xml", "beans.xml");
    war.addAsWebInfResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/WEB-INF/jboss-web.xml", "jboss-web.xml");
    war.addAsWebInfResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/WEB-INF/jboss-wsse-server.xml", "jboss-wsse-server.xml");
    war.addAsWebInfResource(AuthenticationPolicyContextTestCase.class.getPackage(), "resources/WEB-INF/web.xml",
            "web.xml");
    war.addAsManifestResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/META-INF/jboss-deployment-structure.xml", "jboss-deployment-structure.xml");
    war.addAsManifestResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/META-INF/jboss-webservices.xml", "jboss-webservices.xml");
    war.addAsManifestResource(createPermissionsXmlAsset(new SecurityPermission("getPolicy"),
            new RuntimePermission("org.jboss.security.getSecurityContext")), "permissions.xml");
    return war;//from   ww w . ja  va 2s  .  co  m
}

From source file:org.jboss.as.test.integration.ws.authentication.policy.AuthenticationPolicyContextTestCase.java

@Deployment(name = PICKETLINK_STS_WS, managed = false, testable = false)
public static Archive<?> createPicketlinkStsWsDeployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, PICKETLINK_STS_WS + ".war");
    war.addClasses(EchoServiceRemote.class);
    war.addClasses(EchoService.class);
    war.addAsResource(AuthenticationPolicyContextTestCase.class.getPackage(), "resources/sp-users.properties",
            "sp-users.properties");
    war.addAsResource(AuthenticationPolicyContextTestCase.class.getPackage(), "resources/sp-roles.properties",
            "sp-roles.properties");
    war.addAsResource(createFilteredAsset("resources/sts-config.properties"), "sts-config.properties");
    war.addAsWebInfResource(createFilteredAsset("resources/WEB-INF/wsdl/PicketLinkSTS.wsdl"),
            "wsdl/PicketLinkSTS.wsdl");
    war.addAsWebInfResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/WEB-INF/beans.xml", "beans.xml");
    war.addAsWebInfResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/WEB-INF/jboss-web-ws.xml", "jboss-web-ws.xml");
    war.addAsWebInfResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/WEB-INF/jboss-wsse-server.xml", "jboss-wsse-server.xml");
    war.addAsManifestResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/META-INF/jboss-deployment-structure.xml", "jboss-deployment-structure.xml");
    war.addAsManifestResource(AuthenticationPolicyContextTestCase.class.getPackage(),
            "resources/META-INF/jboss-webservices.xml", "jboss-webservices.xml");
    war.addAsResource(AuthenticationPolicyContextTestCase.class.getPackage(), "dummmy-ws-handler.xml",
            "org/jboss/as/test/integration/ws/authentication/policy/resources/dummmy-ws-handler.xml");
    war.addAsManifestResource(createPermissionsXmlAsset(new SecurityPermission("getPolicy"),
            new RuntimePermission("org.jboss.security.getSecurityContext")), "permissions.xml");
    return war;/*from  w  w  w.  j  a v  a2 s.c om*/
}

From source file:org.tinygroup.jspengine.compiler.JspRuntimeContext.java

/**
 * Method used to initialize SecurityManager data.
 *///from   ww  w .  j a  va2 s . c o  m
private void initSecurity() {

    // Setup the PermissionCollection for this web app context
    // based on the permissions configured for the root of the
    // web app context directory, then add a file read permission
    // for that directory.
    Policy policy = Policy.getPolicy();
    if (policy != null) {
        try {
            // Get the permissions for the web app context
            String docBase = context.getRealPath("/");
            if (docBase == null) {
                docBase = options.getScratchDir().toString();
            }
            String codeBase = docBase;
            if (!codeBase.endsWith(File.separator)) {
                codeBase = codeBase + File.separator;
            }
            File contextDir = new File(codeBase);
            URL url = contextDir.getCanonicalFile().toURL();
            codeSource = new CodeSource(url, (Certificate[]) null);
            permissionCollection = policy.getPermissions(codeSource);

            // Create a file read permission for web app context directory
            if (!docBase.endsWith(File.separator)) {
                permissionCollection.add(new FilePermission(docBase, "read"));
                docBase = docBase + File.separator;
            } else {
                permissionCollection
                        .add(new FilePermission(docBase.substring(0, docBase.length() - 1), "read"));
            }
            docBase = docBase + "-";
            permissionCollection.add(new FilePermission(docBase, "read"));

            // Create a file read permission for web app tempdir (work)
            // directory
            String workDir = options.getScratchDir().toString();
            if (!workDir.endsWith(File.separator)) {
                permissionCollection.add(new FilePermission(workDir, "read"));
                workDir = workDir + File.separator;
            }
            workDir = workDir + "-";
            permissionCollection.add(new FilePermission(workDir, "read"));

            // Allow the JSP to access
            // org.tinygroup.jspengine.runtime.HttpJspBase
            permissionCollection
                    .add(new RuntimePermission("accessClassInPackage.org.tinygroup.jspengine.runtime"));

            if (parentClassLoader instanceof URLClassLoader) {
                URL[] urls = ((URLClassLoader) parentClassLoader).getURLs();
                String jarUrl = null;
                String jndiUrl = null;
                for (int i = 0; i < urls.length; i++) {
                    if (jndiUrl == null && urls[i].toString().startsWith("jndi:")) {
                        jndiUrl = urls[i].toString() + "-";
                    }
                    if (jarUrl == null && urls[i].toString().startsWith("jar:jndi:")) {
                        jarUrl = urls[i].toString();
                        jarUrl = jarUrl.substring(0, jarUrl.length() - 2);
                        jarUrl = jarUrl.substring(0, jarUrl.lastIndexOf('/')) + "/-";
                    }
                }
                if (jarUrl != null) {
                    permissionCollection.add(new FilePermission(jarUrl, "read"));
                    permissionCollection.add(new FilePermission(jarUrl.substring(4), "read"));
                }
                if (jndiUrl != null)
                    permissionCollection.add(new FilePermission(jndiUrl, "read"));
            }
        } catch (Exception e) {
            context.log("Security Init for context failed", e);
        }
    }
}