List of usage examples for java.lang System setSecurityManager
public static void setSecurityManager(SecurityManager sm)
From source file:org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager.java
private String executeTest(File test) throws Exception { String reportFileName;//from w w w. ja v a 2s .co m String reportFileFullPath; JMeter jmeterInstance = new JMeter(); try { log.info("Executing test: " + test.getCanonicalPath()); reportFileName = test.getName().substring(0, test.getName().lastIndexOf(".")) + "-" + fmt.format(new Date()) + ".jmeterResult" + ".jtl"; File reportDir = JMeterInstallationProvider.getInstance().getReportDir(); reportFileFullPath = reportDir.toString() + File.separator + reportFileName; List<String> argsTmp = Arrays.asList("-n", "-t", test.getCanonicalPath(), "-l", reportDir.toString() + File.separator + reportFileName, "-p", jmeterProps.toString(), "-d", jmeterHome.getCanonicalPath(), "-L", "jorphan=" + jmeterLogLevel, "-L", "jmeter.util=" + jmeterLogLevel); List<String> args = new ArrayList<String>(); args.addAll(argsTmp); SecurityManager oldManager = System.getSecurityManager(); UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { if (e instanceof ExitException && ((ExitException) e).getCode() == 0) { return; //Ignore } log.error("Error in thread " + t.getName()); } }); try { logParamsAndProps(args); jmeterInstance.start(args.toArray(new String[] {})); BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(jmeterLogFile), Charset.defaultCharset())); while (!checkForEndOfTest(in)) { try { Thread.sleep(1000); } catch (InterruptedException e) { break; } } } catch (ExitException e) { if (e.getCode() != 0) { throw new Exception("Test failed", e); } } catch (Exception e) { log.error(e); } finally { System.setSecurityManager(oldManager); Thread.setDefaultUncaughtExceptionHandler(oldHandler); } } catch (IOException e) { throw new Exception("Can't execute test", e); } return reportFileFullPath; }
From source file:org.wso2.developerstudio.visualdatamapper.diagram.avro.generators.XSDtoAvroGen.java
public String generateAVRO(String xsdFileLoc) { packageName = "generated.avro"; schemaFiles = xsdFileLoc;/*from w ww .j a va2s . c o m*/ outputDirectory = new File(outputDirectoryString); if (!outputDirectory.exists()) { outputDirectory.mkdir(); } String args[] = buildArguments(); try { // XJC blindly calls System.exit when it is finished. // This creates a work-around. SecurityManager oldSecurityManager = System.getSecurityManager(); //System.setSecurityManager(new DelegatingNoExitSecurityManager( // oldSecurityManager)); forbidSystemExitCall(); try { Driver.main(args); } catch (DelegatingNoExitSecurityManager.NormalExitException ex) { log.error("Preventing the Driver executing system exit on finish" + ex); } finally { System.setSecurityManager(oldSecurityManager); } } catch (Exception ex) { log.error( "Error in generating the JAXB java classes from the given XSD file, please recheck the generated XSD, " + ex); } String changedOutput = AvroSchemagenPlugin.replaceNamespace(args[1], args[5]); // now consume the generated schemas File avroSchemaOutput = AvroSchemagenPlugin.getSchemaDirectory(outputDirectory); if (!avroSchemaOutput.exists()) { } File outputDir = new File(outputDirectoryString); try { FileUtils.deleteDirectory(outputDir); } catch (IOException e) { log.equals("could not delete the directory with JAXB java and Generated Avro content at : " + outputDirectoryString + e); } return changedOutput; }
From source file:sorcer.launcher.SorcerLauncher.java
public static void installSecurityManager() { if (System.getSecurityManager() == null) System.setSecurityManager(new SecurityManager()/*{ @Override public void checkPermission(Permission perm) { String name = perm.getName(); if (name.startsWith("exitVM") && !(hasCaller(ExitingCallback.class) || hasCaller("sorcer.launcher.Sorcer"))) throw new SecurityException("Exit forbidden"); } private boolean hasCaller(Class type){ return hasCaller(type.getName()); } private boolean hasCaller(String type){ for (Class caller : getClassContext()) { if(type.equals(caller.getName())) return true; } return false; } }*/); }
From source file:src.eidreader.EstEIDUtil.java
public void unused2_init() { System.err.println("Gonna set the security manager..."); //~ System.out.println("toto"); System.setSecurityManager(new SecurityManager() { @Override//from w w w. j av a 2s .c o m public void checkPermission(Permission permission) { if (permission instanceof CardPermission) { return; } //~ if (permission instanceof RuntimePermission) { //~ return; //~ } //~ if (permission instanceof FilePermission) { //~ return; //~ } java.security.AccessController.checkPermission(permission); } }); System.err.println("Initialized"); }