Example usage for java.security AllPermission AllPermission

List of usage examples for java.security AllPermission AllPermission

Introduction

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

Prototype

public AllPermission() 

Source Link

Document

Creates a new AllPermission object.

Usage

From source file:org.jboss.additional.testsuite.jdkall.present.elytron.application.AbstractCredentialStoreTestCase.java

@Deployment(testable = false)
public static WebArchive createDeployment() {
    return ShrinkWrap.create(WebArchive.class).addClass(ReadCredentialServlet.class)
            .addAsManifestResource(new StringAsset(
                    "Dependencies: org.jboss.as.server,org.jboss.as.controller,org.wildfly.security.elytron\n"),
                    "MANIFEST.MF")
            .addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new AllPermission()),
                    "permissions.xml");
}

From source file:de.innovationgate.wgpublisher.expressions.tmlscript.IsolatedJARLoader.java

@Override
protected PermissionCollection getPermissions(CodeSource arg0) {
    Permissions permissions = new Permissions();
    permissions.add(new AllPermission());
    return permissions;
}

From source file:org.pegadi.client.ApplicationLauncher.java

private static void setAllPermissions() {
    // give all permissions. needed when run from java web start, because
    // the rmi classloaders don't heed the security settings in the .jnlp
    // file.//from  w ww . j  a va2s. com
    try {
        Policy.setPolicy(new Policy() {
            public PermissionCollection getPermissions(CodeSource codesource) {
                Permissions perms = new Permissions();
                perms.add(new AllPermission());
                return (perms);
            }

            public void refresh() {
            }
        });
    } catch (Exception wse) {
        LoggerFactory.getLogger(ApplicationLauncher.class).error("Error setting policies", wse);
        System.exit(-1);
    }
}

From source file:com.googlecode.onevre.utils.ServerClassLoader.java

/**
 *
 * @see java.security.SecureClassLoader#getPermissions(
 *     java.security.CodeSource)/*from w ww . j  a  va2s  .c  o m*/
 */
protected PermissionCollection getPermissions(CodeSource codesource) {
    boolean isAcceptable = false;
    if (!CHECKED.containsKey(codesource.getLocation())) {
        Certificate[] certs = codesource.getCertificates();
        if (certs == null || certs.length == 0) {
            JOptionPane.showMessageDialog(null, "The jar at " + codesource.getLocation() + " is not signed!",
                    "Security Error", JOptionPane.ERROR_MESSAGE);
            isAcceptable = false;
        } else {
            isAcceptable = true;
            for (int i = 0; (i < certs.length) && isAcceptable; i++) {
                if (!verifyCertificate((X509Certificate) certs[i])) {
                    isAcceptable = false;
                }
            }
        }
        CHECKED.put(codesource.getLocation(), isAcceptable);
    } else {
        isAcceptable = CHECKED.get(codesource.getLocation());
    }

    Permissions permissions = new Permissions();
    if (isAcceptable) {
        permissions.add(new AllPermission());
        return permissions;
    }
    throw new SecurityException("Access denied to " + codesource.getLocation());
}

From source file:eu.europa.ejusticeportal.dss.applet.DssApplet.java

/**
 * Check that all required privilege are granted, stop applet if not.
 */// www.  ja va 2  s  .com
private void checkPrivileges() {

    try {
        final SecurityManager security = System.getSecurityManager();
        if (security != null) {
            final Permission perm = new AllPermission();
            // Throws a security exception if not allowed
            security.checkPermission(perm);
        }
    } catch (Exception ex) {
        ExceptionUtils.log(new UnexpectedException(ex, "Fail to check privileges."), LOG);
        initFailure();
    }
}

From source file:com.threerings.getdown.data.Application.java

/**
 * Runs this application directly in the current VM.
 *//*from   w  w  w. ja v a 2  s .  c  om*/
public void invokeDirect(JApplet applet) throws IOException {
    ClassPath classPath = ClassPaths.buildClassPath(this);
    URL[] jarUrls = classPath.asUrls();

    // create custom class loader
    URLClassLoader loader = new URLClassLoader(jarUrls, ClassLoader.getSystemClassLoader()) {
        @Override
        protected PermissionCollection getPermissions(CodeSource code) {
            Permissions perms = new Permissions();
            perms.add(new AllPermission());
            return perms;
        }
    };
    Thread.currentThread().setContextClassLoader(loader);

    log.info("Configured URL class loader:");
    for (URL url : jarUrls)
        log.info("  " + url);

    // configure any system properties that we can
    for (String jvmarg : _jvmargs) {
        if (jvmarg.startsWith("-D")) {
            jvmarg = processArg(jvmarg.substring(2));
            int eqidx = jvmarg.indexOf("=");
            if (eqidx == -1) {
                log.warning("Bogus system property: '" + jvmarg + "'?");
            } else {
                System.setProperty(jvmarg.substring(0, eqidx), jvmarg.substring(eqidx + 1));
            }
        }
    }

    // pass along any pass-through arguments
    Map<String, String> passProps = new HashMap<String, String>();
    for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
        String key = (String) entry.getKey();
        if (key.startsWith(PROP_PASSTHROUGH_PREFIX)) {
            key = key.substring(PROP_PASSTHROUGH_PREFIX.length());
            passProps.put(key, (String) entry.getValue());
        }
    }
    // we can't set these in the above loop lest we get a ConcurrentModificationException
    for (Map.Entry<String, String> entry : passProps.entrySet()) {
        System.setProperty(entry.getKey(), entry.getValue());
    }

    // make a note that we're running in "applet" mode
    System.setProperty("applet", "true");

    // prepare our app arguments
    String[] args = new String[_appargs.size()];
    for (int ii = 0; ii < args.length; ii++)
        args[ii] = processArg(_appargs.get(ii));

    try {
        log.info("Loading " + _class);
        Class<?> appclass = loader.loadClass(_class);
        Method main;
        try {
            // first see if the class has a special applet-aware main
            main = appclass.getMethod("main", JApplet.class, SA_PROTO.getClass());
            log.info("Invoking main(JApplet, {" + StringUtil.join(args, ", ") + "})");
            main.invoke(null, new Object[] { applet, args });
        } catch (NoSuchMethodException nsme) {
            main = appclass.getMethod("main", SA_PROTO.getClass());
            log.info("Invoking main({" + StringUtil.join(args, ", ") + "})");
            main.invoke(null, new Object[] { args });
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:org.apache.log4j.chainsaw.LogUI.java

/**
 * Creates, activates, and then shows the Chainsaw GUI, optionally showing
 * the splash screen, and using the passed shutdown action when the user
 * requests to exit the application (if null, then Chainsaw will exit the vm)
 *
 * @param model//from w w  w.ja v a2s  .c om
 * @param newShutdownAction
 *                    DOCUMENT ME!
 */
public static void createChainsawGUI(ApplicationPreferenceModel model, Action newShutdownAction) {

    if (model.isOkToRemoveSecurityManager()) {
        MessageCenter.getInstance()
                .addMessage("User has authorised removal of Java Security Manager via preferences");
        System.setSecurityManager(null);
        // this SHOULD set the Policy/Permission stuff for any
        // code loaded from our custom classloader.  
        // crossing fingers...
        Policy.setPolicy(new Policy() {

            public void refresh() {
            }

            public PermissionCollection getPermissions(CodeSource codesource) {
                Permissions perms = new Permissions();
                perms.add(new AllPermission());
                return (perms);
            }
        });
    }

    final LogUI logUI = new LogUI();
    logUI.applicationPreferenceModel = model;

    if (model.isShowSplash()) {
        showSplash(logUI);
    }
    logUI.cyclicBufferSize = model.getCyclicBufferSize();
    logUI.pluginRegistry = repositoryExImpl.getPluginRegistry();

    logUI.handler = new ChainsawAppenderHandler();
    logUI.handler.addEventBatchListener(logUI.new NewTabEventBatchReceiver());

    /**
     * TODO until we work out how JoranConfigurator might be able to have
     * configurable class loader, if at all.  For now we temporarily replace the
     * TCCL so that Plugins that need access to resources in 
     * the Plugins directory can find them (this is particularly
     * important for the Web start version of Chainsaw
     */
    //configuration initialized here
    logUI.ensureChainsawAppenderHandlerAdded();
    logger = LogManager.getLogger(LogUI.class);

    //set hostname, application and group properties which will cause Chainsaw and other apache-generated
    //logging events to route (by default) to a tab named 'chainsaw-log'
    PropertyRewritePolicy policy = new PropertyRewritePolicy();
    policy.setProperties("hostname=chainsaw,application=log,group=chainsaw");

    RewriteAppender rewriteAppender = new RewriteAppender();
    rewriteAppender.setRewritePolicy(policy);

    Enumeration appenders = Logger.getLogger("org.apache").getAllAppenders();
    if (!appenders.hasMoreElements()) {
        appenders = Logger.getRootLogger().getAllAppenders();
    }
    while (appenders.hasMoreElements()) {
        Appender nextAppender = (Appender) appenders.nextElement();
        rewriteAppender.addAppender(nextAppender);
    }
    Logger.getLogger("org.apache").removeAllAppenders();
    Logger.getLogger("org.apache").addAppender(rewriteAppender);
    Logger.getLogger("org.apache").setAdditivity(false);

    //commons-vfs uses httpclient for http filesystem support, route this to the chainsaw-log tab as well
    appenders = Logger.getLogger("httpclient").getAllAppenders();
    if (!appenders.hasMoreElements()) {
        appenders = Logger.getRootLogger().getAllAppenders();
    }
    while (appenders.hasMoreElements()) {
        Appender nextAppender = (Appender) appenders.nextElement();
        rewriteAppender.addAppender(nextAppender);
    }
    Logger.getLogger("httpclient").removeAllAppenders();
    Logger.getLogger("httpclient").addAppender(rewriteAppender);
    Logger.getLogger("httpclient").setAdditivity(false);

    //set the commons.vfs.cache logger to info, since it can contain password information
    Logger.getLogger("org.apache.commons.vfs.cache").setLevel(Level.INFO);

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
            logger.error("Uncaught exception in thread " + t, e);
        }
    });

    String config = configurationURLAppArg;
    if (config != null) {
        logger.info("Command-line configuration arg provided (overriding auto-configuration URL) - using: "
                + config);
    } else {
        config = model.getConfigurationURL();
    }

    if (config != null && (!config.trim().equals(""))) {
        config = config.trim();
        try {
            URL configURL = new URL(config);
            logger.info("Using '" + config + "' for auto-configuration");
            logUI.loadConfigurationUsingPluginClassLoader(configURL);
        } catch (MalformedURLException e) {
            logger.error("Initial configuration - failed to convert config string to url", e);
        } catch (IOException e) {
            logger.error("Unable to access auto-configuration URL: " + config);
        }
    }

    //register a listener to load the configuration when it changes (avoid having to restart Chainsaw when applying a new configuration)
    //this doesn't remove receivers from receivers panel, it just triggers DOMConfigurator.configure.
    model.addPropertyChangeListener("configurationURL", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            String newConfiguration = evt.getNewValue().toString();
            if (newConfiguration != null && !(newConfiguration.trim().equals(""))) {
                newConfiguration = newConfiguration.trim();
                try {
                    logger.info("loading updated configuration: " + newConfiguration);
                    URL newConfigurationURL = new URL(newConfiguration);
                    File file = new File(newConfigurationURL.toURI());
                    if (file.exists()) {
                        logUI.loadConfigurationUsingPluginClassLoader(newConfigurationURL);
                    } else {
                        logger.info("Updated configuration but file does not exist");
                    }
                } catch (MalformedURLException e) {
                    logger.error("Updated configuration - failed to convert config string to URL", e);
                } catch (URISyntaxException e) {
                    logger.error("Updated configuration - failed to convert config string to URL", e);
                }
            }
        }
    });

    LogManager.getRootLogger().setLevel(Level.TRACE);
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            logUI.activateViewer();
        }
    });

    logger.info("SecurityManager is now: " + System.getSecurityManager());

    if (newShutdownAction != null) {
        logUI.setShutdownAction(newShutdownAction);
    } else {
        logUI.setShutdownAction(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
    }
}