List of usage examples for java.lang System setSecurityManager
public static void setSecurityManager(SecurityManager sm)
From source file:com.palantir.atlasdb.console.AtlasConsoleMain.java
/** * Note on the System.setSecurityManager call: * * The main method of the Groovysh class initializes a SecurityManager to * prevent the use of System.exit. The SecurityManager is not actually * necessary for Groovysh, so this change removes it to allow JDBC * access (removes the need for users to create an explicit ~/.java.policy * file).//from ww w . j a v a 2 s.co m */ public static void callback(Script script) throws CompilationFailedException, IOException { System.setSecurityManager(null); setupBinding(script.getBinding()); }
From source file:com.thoughtworks.acceptance.SecurityManagerTest.java
public void testSerializeWithXppDriverAndSun14ReflectionProviderAndActiveSecurityManager() { sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.reflect")); sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.misc")); sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources")); sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources")); sm.addPermission(source, new RuntimePermission("accessDeclaredMembers")); sm.addPermission(source, new RuntimePermission("createClassLoader")); sm.addPermission(source, new RuntimePermission("fileSystemProvider")); sm.addPermission(source, new RuntimePermission("loadLibrary.nio")); sm.addPermission(source, new RuntimePermission("modifyThreadGroup")); sm.addPermission(source, new RuntimePermission("reflectionFactoryAccess")); sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read")); sm.addPermission(source, new PropertyPermission("java.home", "read")); sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read")); sm.addPermission(source, new PropertyPermission("java.security.debug", "read")); sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read")); sm.addPermission(source, new PropertyPermission("jaxp.debug", "read")); sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read")); sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read")); sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read")); sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read")); sm.addPermission(source, new PropertyPermission("user.country", "read")); sm.addPermission(source, new PropertyPermission("user.dir", "read")); sm.addPermission(source, new PropertyPermission("user.timezone", "read,write")); sm.addPermission(source, new ReflectPermission("suppressAccessChecks")); sm.addPermission(source, new NetPermission("specifyStreamHandler")); sm.setReadOnly();//from w w w . java2 s. co m System.setSecurityManager(sm); xstream = new XStream(); xstream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName() + ".*objects.**"); xstream.allowTypesByWildcard(this.getClass().getName() + "$*"); assertBothWays(); }
From source file:com.izforge.izpack.event.AntAction.java
/** * Performs all defined actions./*from w w w . j a va 2s. co m*/ * * @param uninstall An install/uninstall switch. If this is <tt>true</tt> only the uninstall * actions, otherwise only the install actions are being performed. * @throws IzPackException for any error * @see #performInstallAction() for calling all install actions. * @see #performUninstallAction() for calling all uninstall actions. */ public void performAction(boolean uninstall) throws IzPackException { if (verbose) { System.out.print("Calling ANT with buildfile: " + buildFile); System.out.print(buildDir != null ? " in directory " + buildDir : " in default base directory"); System.out.println(); } SecurityManager oldsm = null; if (!JavaEnvUtils.isJavaVersion("1.0") && !JavaEnvUtils.isJavaVersion("1.1")) { oldsm = System.getSecurityManager(); } PrintStream err = System.err; PrintStream out = System.out; Project antProj = new Project(); try { antProj.setInputHandler(new AntActionInputHandler()); antProj.setName("antcallproject"); if (verbose) { logLevel = AntLogLevel.VERBOSE; } else if (quiet) { logLevel = AntLogLevel.WARNING; } final int antLogLevel = logLevel.getLevel(); antProj.addBuildListener(new AntSystemLogBuildListener(antLogLevel)); if (logFile != null) { antProj.addBuildListener(new AntActionLogBuildListener(logFile, logFileAppend, antLogLevel)); } antProj.setSystemProperties(); addProperties(antProj, getProperties()); addPropertiesFromPropertyFiles(antProj); // TODO: propertyfiles, logFile antProj.fireBuildStarted(); antProj.init(); List<Ant> antcalls = new ArrayList<Ant>(); List<String> choosenTargets = (uninstall) ? uninstallTargets : targets; if (choosenTargets.size() > 0) { Ant antcall; for (String choosenTarget : choosenTargets) { antcall = (Ant) antProj.createTask("ant"); if (buildDir != null) { antcall.setDir(buildDir); } antcall.setAntfile(buildFile.getAbsolutePath()); antcall.setTarget(choosenTarget); antcalls.add(antcall); } } Target target = new Target(); target.setName("calltarget"); for (Ant antcall : antcalls) { target.addTask(antcall); } antProj.addTarget(target); System.setOut(new PrintStream(new DemuxOutputStream(antProj, false))); System.setErr(new PrintStream(new DemuxOutputStream(antProj, true))); antProj.executeTarget("calltarget"); antProj.fireBuildFinished(null); } catch (BuildException exception) { antProj.fireBuildFinished(exception); throw new IzPackException("Ant build failed", exception, getSeverity()); } finally { if (oldsm != null) { System.setSecurityManager(oldsm); } System.setOut(out); System.setErr(err); } }
From source file:com.vmware.identity.idm.server.IdmServer.java
/** * Initialize the IDM service./* ww w.ja v a 2 s. c om*/ * * @throws Exception when something goes wrong with initialization. */ private static void initialize() throws Exception { try (IDiagnosticsContextScope diagCtxt = DiagnosticsContextFactory.createContext("IDM Startup", "")) { logger.info("Starting IDM Server..."); logger.debug("Creating RMI registry on port {}", Tenant.RMI_PORT); boolean allowRemoteConnections = Boolean .parseBoolean(System.getProperty(ALLOW_REMOTE_PROPERTY, "false")); if (allowRemoteConnections) { logger.warn("RMI registry is allowing remote connections!"); registry = LocateRegistry.createRegistry(Tenant.RMI_PORT); } else { logger.debug("RMI registry is restricted to the localhost"); RMIClientSocketFactory csf = RMISocketFactory.getDefaultSocketFactory(); RMIServerSocketFactory ssf = new LocalRMIServerSocketFactory(); registry = LocateRegistry.createRegistry(Tenant.RMI_PORT, csf, ssf); } // Assign a security manager, in the event that dynamic classes are loaded if (System.getSecurityManager() == null) { logger.debug("Creating RMI Security Manager..."); System.setSecurityManager(new RMISecurityManager()); } logger.debug("Creating Config Store factory..."); IConfigStoreFactory cfgStoreFactory = new ConfigStoreFactory(); logger.debug("Creating Identity Provider factory..."); IProviderFactory providerFactory = new ProviderFactory(); logger.debug("Checking VMware Directory Service..."); ServerUtils.check_directory_service(); logger.debug("Setting system properties..."); System.setProperties(new ThreadLocalProperties(System.getProperties())); logger.debug("Creating Identity Manager instance..."); manager = new IdentityManager(cfgStoreFactory, providerFactory); String rmiAddress = String.format("rmi://localhost:%d/%s", Tenant.RMI_PORT, IDENTITY_MANAGER_BIND_NAME); logger.debug("Binding to RMI address '{}'", rmiAddress); loginManager = new IdmLoginManager(manager); ILoginManager stub = (ILoginManager) UnicastRemoteObject.exportObject(loginManager, 0); Naming.rebind(rmiAddress, stub); startHeartbeat(); logger.info(VmEvent.SERVER_STARTED, "IDM Server has started"); } catch (Throwable t) { logger.error(VmEvent.SERVER_FAILED_TOSTART, "IDM Server has failed to start", t); throw t; } }
From source file:com.liferay.maven.plugins.AbstractLiferayMojo.java
protected void executeTool(String toolClassName, ClassLoader classLoader, String[] args) throws Exception { Thread currentThread = Thread.currentThread(); ClassLoader contextClassLoader = currentThread.getContextClassLoader(); currentThread.setContextClassLoader(classLoader); SecurityManager currentSecurityManager = System.getSecurityManager(); // Required to prevent premature exit by DBBuilder. See LPS-7524. SecurityManager securityManager = new SecurityManager() { public void checkPermission(Permission permission) { }/*w w w . ja v a 2 s . com*/ public void checkExit(int status) { throw new SecurityException(); } }; System.setSecurityManager(securityManager); try { System.setProperty("external-properties", "com/liferay/portal/tools/dependencies" + "/portal-tools.properties"); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Class<?> clazz = classLoader.loadClass(toolClassName); Method method = clazz.getMethod("main", String[].class); method.invoke(null, (Object) args); } catch (InvocationTargetException ite) { if (ite.getCause() instanceof SecurityException) { } else { throw ite; } } finally { currentThread.setContextClassLoader(contextClassLoader); System.clearProperty("org.apache.commons.logging.Log"); System.setSecurityManager(currentSecurityManager); } }
From source file:cn.fql.utility.FileUtility.java
/** * visit all a director and delete them in a list,write deleted files' name to list * * @param dir directory/*from w w w .ja v a2s .c o m*/ * @return deleted file name list */ private static List deleteAll(File dir) { System.setSecurityManager(SECURITYMANAGER); List allFiles = new ArrayList(); File[] dirs = dir.listFiles(); if (dirs != null) { List dirsList = Arrays.asList(dirs); if (dirsList == null) { try { dir.delete(); } catch (Exception e) { e.printStackTrace(); } } else { allFiles.addAll(dirsList); for (Iterator it = dirsList.iterator(); it.hasNext();) { File _tempRoot = (java.io.File) it.next(); allFiles.addAll(deleteAll(_tempRoot)); } } } System.setSecurityManager(SYSSECURITYMANAGER); return allFiles; }
From source file:org.nebulaframework.grid.Grid.java
/** * Starts a {@link GridNode} with default settings, read from * default properties file.// w ww . j av a2 s . c om * * @param useConfigDiscovery indicates whether to use information * from configuration to discover * * @return GridNode * * @throws IllegalStateException if a Grid Member (Cluster / Node) has * already started with in the current VM. Nebula supports only one Grid * Member per VM. */ public synchronized static GridNode startGridNode(boolean useConfigDiscovery) throws IllegalStateException { if (isInitialized()) { // A Grid Member has already started in this VM throw new IllegalStateException("A Grid Memeber Already Started in VM"); } initializeDefaultExceptionHandler(); StopWatch sw = new StopWatch(); try { sw.start(); // Set Security Manager System.setSecurityManager(new SecurityManager()); // Detect Configuration Properties config = ConfigurationSupport.detectNodeConfiguration(); log.info("GridNode Attempting Discovery..."); // Discover Cluster If Needed GridNodeDiscoverySupport.discover(config, useConfigDiscovery); checkJMSBroker(config.getProperty(ConfigurationKeys.CLUSTER_SERVICE.value())); log.debug("Starting up Spring Container..."); applicationContext = new NebulaApplicationContext(GRIDNODE_CONTEXT, config); log.debug("Spring Container Started"); node = true; sw.stop(); log.info("GridNode Started Up. " + sw.getLastTaskTimeMillis() + " ms"); return (GridNode) applicationContext.getBean("localNode"); } finally { if (sw.isRunning()) { sw.stop(); } } }
From source file:com.soteradefense.dga.DGACommandLineUtilTest.java
@After public void cleanUp() { System.setSecurityManager(defaultManager); }
From source file:cn.fql.utility.FileUtility.java
/** * do delete all files under specified file's dir * * @param root specified file root/* www . j av a2 s . com*/ */ public static void deleteDirs(File root) throws Exception { System.setSecurityManager(SECURITYMANAGER); if (root.isDirectory()) { List allFiles = deleteAll(root); if (allFiles != null) { for (int i = allFiles.size() - 1; i >= 0; i--) { java.io.File f = (java.io.File) allFiles.remove(i); String fileName = f.toString(); if (!f.delete()) { throw new Exception("Exception: delete file " + fileName + " false!"); } } } } System.setSecurityManager(SYSSECURITYMANAGER); }
From source file:com.projity.pm.graphic.frames.StartupFactory.java
public GraphicManager instanceFromNewSession(Container container, final boolean doWelcome) { VersionUtils.versionCheck(true);/*from w w w . j a va 2 s.c om*/ if (!VersionUtils.isJnlpUpToDate()) System.out.println("Jnlp isn't up to date, current version is: " + VersionUtils.getJnlpVersion()); long t = System.currentTimeMillis(); // System.out.println("---------- StartupFactory instanceFromNewSession#1 main"); Environment.setClientSide(true); System.setSecurityManager(null); Thread loadConfigThread = new Thread("loadConfig") { public void run() { long t = System.currentTimeMillis(); // System.out.println("---------- StartupFactory instanceFromNewSession#1 doLoadConfig"); doLoadConfig(); // System.out.println("---------- StartupFactory instanceFromNewSession#1 doLoadConfig done in "+(System.currentTimeMillis()-t)+" ms"); } }; loadConfigThread.start(); GraphicManager graphicManager = null; //String projectUrl[]=null; try { graphicManager = new GraphicManager(/*projectUrl,*/serverUrl, container); graphicManager.setStartupFactory(this); } catch (HeadlessException e) { e.printStackTrace(); } graphicManager.setConnected(false); if (!doLogin(graphicManager)) return null; //if (Environment.isNewLook()) graphicManager.initLookAndFeel(); SessionFactory.getInstance().setJobQueue(graphicManager.getJobQueue()); PartnerInfo partnerInfo = null; if (!Environment.getStandAlone()) { Session session = SessionFactory.getInstance().getSession(false); try { partnerInfo = (PartnerInfo) SessionFactory.call(session, "retrievePartnerInfo", null, null); } catch (Exception e) { e.printStackTrace(); } } // System.out.println("---------- StartupFactory instanceFromNewSession#1 main done in "+(System.currentTimeMillis()-t)+" ms"); try { loadConfigThread.join(); } catch (InterruptedException e1) { e1.printStackTrace(); } t = System.currentTimeMillis(); // System.out.println("---------- StartupFactory instanceFromNewSession#2"); //graphicManager.showWaitCursor(true); //TODO use a progress bar - maybe a Job if (partnerInfo != null) { if (partnerInfo.getConfigurationXML() != null) { ConfigurationReader.readString(partnerInfo.getConfigurationXML(), Configuration.getInstance()); Configuration.getInstance().setDonePopulating(); } if (partnerInfo.getViewXML() != null) { ConfigurationReader.readString(partnerInfo.getViewXML(), Dictionary.getInstance()); } } final GraphicManager gm = graphicManager; graphicManager.beginInitialization(); try { graphicManager.initView(); doStartupAction(gm, projectId, (projectUrls == null && gm.getLastFileName() != null) ? new String[] { gm.getLastFileName() } : projectUrls, doWelcome, false); doPostInitView(gm.getContainer()); // final Container cc=container; // SwingUtilities.invokeLater(new Runnable() { // // @Override // public void run() { // //cc.setVisible(true); // gm.initView(); // doStartupAction(gm,projectId,(projectUrls==null&&gm.getLastFileName()!=null)?new String[]{gm.getLastFileName()}:projectUrls,doWelcome,false); // // doPostInitView(gm.getContainer()); // } // }); } finally { graphicManager.finishInitialization(); } return graphicManager; }