List of usage examples for java.lang System setSecurityManager
public static void setSecurityManager(SecurityManager sm)
From source file:it.unifi.rcl.chess.traceanalysis.Trace.java
private static void forbidSystemExitCall() { final SecurityManager securityManager = new SecurityManager() { public void checkPermission(Permission permission) { if (permission.getName().contains("exitVM")) { throw new ExitTrappedException(); }//from w ww . j a v a2 s . c o m } }; System.setSecurityManager(securityManager); }
From source file:it.unifi.rcl.chess.traceanalysis.Trace.java
private static void enableSystemExitCall() { System.setSecurityManager(null); }
From source file:com.thoughtworks.acceptance.SecurityManagerTest.java
public void testSerializeWithXppDriverAndPureJavaReflectionProviderAndActiveSecurityManager() { 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 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.io.serialization.extendedDebugInfo", "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 ww w . j ava 2s.co m*/ System.setSecurityManager(sm); xstream = new XStream(new PureJavaReflectionProvider()); xstream.allowTypesByWildcard(AbstractAcceptanceTest.class.getPackage().getName() + ".*objects.**"); xstream.allowTypesByWildcard(this.getClass().getName() + "$*"); assertBothWays(); }
From source file:com.enioka.jqm.tools.JqmEngine.java
/** * Starts the engine/*from ww w. j a v a 2s. c om*/ * * @param nodeName * the name of the node to start, as in the NODE table of the database. * @throws JqmInitError */ void start(String nodeName) { if (nodeName == null || nodeName.isEmpty()) { throw new IllegalArgumentException("nodeName cannot be null or empty"); } // Set thread name - used in audits Thread.currentThread().setName("JQM engine;;" + nodeName); Helpers.setLogFileName(nodeName); // Log: we are starting... jqmlogger.info("JQM engine version " + this.getVersion() + " for node " + nodeName + " is starting"); jqmlogger.info("Java version is " + System.getProperty("java.version") + ". JVM was made by " + System.getProperty("java.vendor") + " as " + System.getProperty("java.vm.name") + " version " + System.getProperty("java.vm.version")); // JNDI first - the engine itself uses JNDI to fetch its connections! Helpers.registerJndiIfNeeded(); // Database connection EntityManager em = Helpers.getNewEm(); // Node configuration is in the database node = em.createQuery("SELECT n FROM Node n WHERE n.name = :l", Node.class).setParameter("l", nodeName) .getSingleResult(); // Check if double-start long toWait = (long) (1.1 * Long.parseLong(Helpers.getParameter("internalPollingPeriodMs", "60000", em))); if (node.getLastSeenAlive() != null && Calendar.getInstance().getTimeInMillis() - node.getLastSeenAlive().getTimeInMillis() <= toWait) { long r = Calendar.getInstance().getTimeInMillis() - node.getLastSeenAlive().getTimeInMillis(); throw new JqmInitErrorTooSoon("Another engine named " + nodeName + " was running less than " + r / 1000 + " seconds ago. Either stop the other node, or if it already stopped, please wait " + (toWait - r) / 1000 + " seconds"); } // Prevent very quick multiple starts by immediately setting the keep-alive em.getTransaction().begin(); node.setLastSeenAlive(Calendar.getInstance()); em.getTransaction().commit(); // Only start if the node configuration seems OK Helpers.checkConfiguration(nodeName, em); // Log parameters Helpers.dumpParameters(em, node); // Log level Helpers.setLogLevel(node.getRootLogLevel()); // Log multicasting (& log4j stdout redirect) GlobalParameter gp1 = em .createQuery("SELECT g FROM GlobalParameter g WHERE g.key = :k", GlobalParameter.class) .setParameter("k", "logFilePerLaunch").getSingleResult(); if ("true".equals(gp1.getValue()) || "both".equals(gp1.getValue())) { RollingFileAppender a = (RollingFileAppender) Logger.getRootLogger().getAppender("rollingfile"); MultiplexPrintStream s = new MultiplexPrintStream(System.out, FilenameUtils.getFullPath(a.getFile()), "both".equals(gp1.getValue())); System.setOut(s); ((ConsoleAppender) Logger.getRootLogger().getAppender("consoleAppender")) .setWriter(new OutputStreamWriter(s)); s = new MultiplexPrintStream(System.err, FilenameUtils.getFullPath(a.getFile()), "both".equals(gp1.getValue())); System.setErr(s); } // Remote JMX server if (node.getJmxRegistryPort() != null && node.getJmxServerPort() != null && node.getJmxRegistryPort() > 0 && node.getJmxServerPort() > 0) { JmxAgent.registerAgent(node.getJmxRegistryPort(), node.getJmxServerPort(), node.getDns()); } else { jqmlogger.info( "JMX remote listener will not be started as JMX registry port and JMX server port parameters are not both defined"); } // Jetty this.server = new JettyServer(); this.server.start(node, em); // JMX if (node.getJmxServerPort() != null && node.getJmxServerPort() > 0) { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); name = new ObjectName("com.enioka.jqm:type=Node,name=" + this.node.getName()); mbs.registerMBean(this, name); } catch (Exception e) { throw new JqmInitError("Could not create JMX beans", e); } jqmlogger.info("JMX management bean for the engine was registered"); } else { loadJmxBeans = false; jqmlogger.info("JMX management beans will not be loaded as JMX server port is null or zero"); } // Security if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManagerPayload()); } jqmlogger.info("Security manager was registered"); // Cleanup purgeDeadJobInstances(em, this.node); // Force Message EMF load em.createQuery("SELECT m FROM Message m WHERE 1=0", Message.class).getResultList(); // Pollers syncPollers(em, this.node); jqmlogger.info("All required queues are now polled"); // Internal poller (stop notifications, keepalive) intPoller = new InternalPoller(this); Thread t = new Thread(intPoller); t.start(); // Kill notifications killHook = new SignalHandler(this); Runtime.getRuntime().addShutdownHook(killHook); // Done em.close(); em = null; latestNodeStartedName = node.getName(); jqmlogger.info("End of JQM engine initialization"); }
From source file:com.cisco.dvbu.ps.deploytool.dao.wsapi.VCSWSDAOImpl.java
public void vcsImportCommand(String prefix, String arguments, String vcsIgnoreMessages, String propertyFile) throws CompositeException { String identifier = "VCSWSDAOImpl.vcsImportCommand"; // some unique identifier that characterizes this invocation. String actionName = "IMPORT"; try {/* www . jav a 2 s .com*/ boolean preserveQuotes = false; boolean initArgsList = true; List<String> argsList = new ArrayList<String>(); // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. // If so then force a no operation to happen by performing a -printcontents for pkg_import // mtinius-2016-04-14: commented out until a full analysis can be done. //if (CommonUtils.isExecOperation() && !arguments.toLowerCase().contains("-printcontents")) // arguments = arguments + " -printcontents"; // Parse the arguments argsList = CommonUtils.parseArguments(argsList, initArgsList, arguments, preserveQuotes, propertyFile); String[] args = argsList.toArray(new String[0]); /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // ImportCommand.startCommand(null, null, args); /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ String maskedargsList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled()) { logger.debug(identifier + "(prefix, arguments, vcsIngoreMessages, propertyFile). prefix=" + prefix + " arguments=[" + maskedargsList + "]" + " vcsIgnoreMessages=" + vcsIgnoreMessages + " propertyFile=" + propertyFile); } // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "ImportCommand.startCommand"; try { // Get the offset location of the java.policy file [offset from PDTool home]. String javaPolicyOffset = CommonConstants.javaPolicy; String javaPolicyLocation = CommonUtils.extractVariable(prefix, CommonUtils.getFileOrSystemPropertyValue(propertyFile, "PROJECT_HOME_PHYSICAL"), propertyFile, true) + javaPolicyOffset; // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger exportLogger = Logger.getLogger(ImportCommand.class); System.setOut(new PrintStream(new LogOutputStream(exportLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(exportLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Invoke the Composite native import command. ImportCommand.startCommand(null, null, args); } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(null, null, " + maskedargsList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled()) { logger.debug(identifier + ":: Exited successfully from System.exit(): " + command + "(null, null, " + maskedargsList + ")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } catch (Exception e) { if (resolveExecCommandLineError(prefix, e.getMessage().toString(), vcsIgnoreMessages)) { ApplicationException applicationException = new ApplicationException( "ImportCommand execution returned an error=" + e.getMessage().toString()); if (logger.isErrorEnabled()) { logger.error(applicationException); } throw applicationException; } } }
From source file:com.amazonaws.services.dynamodbv2.online.index.integration.tests.ViolationDetectionTest.java
@BeforeClass public static void setup() throws FileNotFoundException, IOException { awsConnection = new AWSConnection(AWS_CREDENTIAL_PATH); dynamoDBClient = awsConnection.getDynamoDBClient(DYNAMODB_REGION, TestUtils.RUN_TESTS_ON_DYNAMODB_LOCAL); tableManager = new TableManager(dynamoDBClient); generateTableAndDataForDetectorTable(); generateTableAndDataForDetectorDeleteTestTable(); System.setSecurityManager(new NoExitSecurityManager()); }
From source file:com.amazonaws.services.dynamodbv2.online.index.integration.tests.ViolationDetectionTest.java
@AfterClass public static void tearDown() { System.setSecurityManager(securityManager); if (tablesToDelete != null) { for (String tableName : tablesToDelete) { tableManager.deleteTable(tableName); }/*from w w w . java2 s .co m*/ } // Delete the output files String[] fileNames = { DETECTOR_OP_FILE }; TestUtils.deleteFiles(fileNames); }
From source file:org.nebulaframework.grid.Grid.java
/** * Starts a Light-weight {@link GridNode} (a GridNode without * Job Execution Support, that is non-worker) with default * settings, read from default properties file. * //from w ww. ja v a2 s . co m * @param useConfigDiscovery indicates whether to use information * from configuration to discover * * @param isGui indicates that the application is a GUI based * application and any disconnection notifications should be * done through message boxes. * * @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 startLightGridNode(boolean useConfigDiscovery, final boolean isGui) 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()); Properties config = ConfigurationSupport.detectNodeConfiguration(); log.info("GridNode Attempting Discovery..."); // Discover Cluster If Needed GridNodeDiscoverySupport.discover(config, useConfigDiscovery); checkJMSBroker(config.getProperty(ConfigurationKeys.CLUSTER_SERVICE.value())); // If we reach here, connection test succeeded log.debug("Starting up Spring Container..."); applicationContext = new NebulaApplicationContext(GRIDNODE_LIGHT_CONTEXT, config); log.debug("Spring Container Started"); node = true; lightweight = true; sw.stop(); log.info("GridNode Started Up. " + sw.getLastTaskTimeMillis() + " ms"); GridNode node = (GridNode) applicationContext.getBean("localNode"); ServiceEventsSupport.addServiceHook(new ServiceHookCallback() { @Override public void onServiceEvent(ServiceMessage message) { log.warn("[GridNode] Disconnected from Cluster"); log.warn("[GridNode] Shutting Down"); if (isGui) { JOptionPane.showMessageDialog(UISupport.activeWindow(), "Disconnected from Cluster, terminating VM"); } System.exit(0); } }, node.getClusterId().toString(), ServiceMessageType.NODE_DISCONNECTED); return node; } finally { if (sw.isRunning()) { sw.stop(); } } }
From source file:com.cisco.dvbu.ps.deploytool.dao.wsapi.ArchiveWSDAOImpl.java
public void takeArchiveAction(String actionName, ArchiveType archive, String serverId, String pathToServersXML, String prefix, String propertyFile) throws CompositeException { if (logger.isDebugEnabled()) { logger.debug(// w w w . j a v a 2 s .co m "ArchiveWSDAOImpl.takeArchiveAction(actionName, archive, serverId, pathToServersXML, prefix, propertyFile). actionName=" + actionName + " archive object=" + archive.toString() + " serverId=" + serverId + " pathToServersXML=" + pathToServersXML + " prefix=" + prefix + " propertyFile=" + propertyFile); } // Set the debug options setDebug(); // Read target server properties from xml and build target server object based on target server name CompositeServer targetServer = WsApiHelperObjects.getServerLogger(serverId, pathToServersXML, "ArchiveWSDAOImpl.takeArchiveAction(" + actionName + ")", logger); // // DA@20120610 Comment unnecessary ping - if server is down the backup/restore command will fail as fast as ping // Ping the Server to make sure it is alive and the values are correct. // WsApiHelperObjects.pingServer(targetServer, true); // Get the offset location of the java.policy file [offset from PDTool home]. String javaPolicyOffset = CommonConstants.javaPolicy; String javaPolicyLocation = CommonUtils.extractVariable(prefix, CommonUtils.getFileOrSystemPropertyValue(propertyFile, "PROJECT_HOME_PHYSICAL"), propertyFile, true) + javaPolicyOffset; String identifier = "ArchiveWSDAOImpl.takeArchiveAction"; // some unique identifier that characterizes this invocation. try { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput(":: executing action: " + actionName, prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: executing action: "+actionName); } List<String> argsList = getCommonArchiveParameters(archive, targetServer); if (actionName.equalsIgnoreCase(ArchiveDAO.action.IMPORT.name())) { // pkg_import boolean archiveISNULL = false; if (archive == null) archiveISNULL = true; if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.IMPORT.name().toString() + " archiveISNULL=[" + archiveISNULL + "]", prefix, "-debug3", logger, debug1, debug2, debug3); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. // If so then force a no operation to happen by performing a -printcontents for pkg_import if (!CommonUtils.isExecOperation() || (archive.isPrintcontents() != null && !archive.isPrintcontents())) archive.setPrintcontents(true); // Construct the variable input for pacakged import List<String> parms = getPackageImportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.IMPORT.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.IMPORT.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // ImportCommand.startCommand(".", ".", args); /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "ImportCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger importLogger = Logger.getLogger(ImportCommand.class); System.setOut(new PrintStream(new LogOutputStream(importLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(importLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking ImportCommand.startCommand(\".\", \".\", args)."); } // Invoke the Composite native import command. ImportCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully imported."); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.RESTORE.name())) { // backup_import // Construct the variable input for backup import List<String> parms = getBackupImportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.RESTORE.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.RESTORE.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // RestoreCommand.startCommand(".", ".", args) ; /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "RestoreCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger restoreLogger = Logger.getLogger(RestoreCommand.class); System.setOut(new PrintStream(new LogOutputStream(restoreLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(restoreLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking RestoreCommand.startCommand(\".\", \".\", args)."); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Invoke the Composite native restore command. RestoreCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully restored."); } } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.EXPORT.name())) { // pkg_export List<String> parms = getPackageExportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.EXPORT.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.EXPORT.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // ExportCommand.startCommand(".", ".", args); /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "ExportCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger exportLogger = Logger.getLogger(ExportCommand.class); System.setOut(new PrintStream(new LogOutputStream(exportLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(exportLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking ExportCommand.startCommand(\".\", \".\", args)."); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Invoke the Composite native export command. ExportCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully exported."); } } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.BACKUP.name())) { // backup_export List<String> parms = getBackupExportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.BACKUP.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.BACKUP.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // BackupCommand.startCommand(".", ".", args); /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "BackupCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger backupLogger = Logger.getLogger(BackupCommand.class); System.setOut(new PrintStream(new LogOutputStream(backupLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(backupLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking BackupCommand.startCommand(\".\", \".\", args)."); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Invoke the Composite native backup command. BackupCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully backed up."); } } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput(identifier + ":: completed " + actionName, prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: completed " + actionName ); } } // TO DO: Implement specific catch clauses based on implementation catch (Exception e) { // TODO: Be more specific about error messages being returned // TODO: null - this is where soap-faults get passed - modify if you return a soap-fault (e.g. e.getFaultInfo()) if (e.getCause() != null && e.getCause() instanceof WebapiException) { // CompositeLogger.logException(e, DeployUtil.constructMessage(DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer),e.getCause()); CompositeLogger.logException(e.getCause(), DeployUtil.constructMessage( DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer)); } else { CompositeLogger.logException(e, DeployUtil.constructMessage(DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer)); } throw new ApplicationException(e.getMessage(), e); } }
From source file:com.amazonaws.services.dynamodbv2.online.index.integration.tests.ViolationCorrectionTest.java
@BeforeClass public static void setup() throws FileNotFoundException, IOException { awsConnection = new AWSConnection(AWS_CREDENTIAL_PATH); dynamoDBClient = awsConnection.getDynamoDBClient(DYNAMODB_REGION, TestUtils.RUN_TESTS_ON_DYNAMODB_LOCAL); tableManager = new TableManager(dynamoDBClient); generateTableAndDataForCorrectorTable(); System.setSecurityManager(new NoExitSecurityManager()); }