List of usage examples for java.lang System getSecurityManager
public static SecurityManager getSecurityManager()
From source file:org.pentaho.di.pan.PanIT.java
@Before public void setUp() throws KettleException { KettleEnvironment.init();// w ww .ja v a 2 s . c om oldSecurityManager = System.getSecurityManager(); System.setSecurityManager(new PanIT.MySecurityManager(oldSecurityManager)); }
From source file:org.mobicents.slee.runtime.sbb.SbbObjectPoolFactory.java
public void destroyObject(Object sbb) throws java.lang.Exception { if (doTraceLogs) { logger.trace("destroyObject() for " + sbbComponent); }//from w w w . j a va 2 s .co m SbbObject sbbObject = (SbbObject) sbb; final ClassLoader oldClassLoader = SleeContainerUtils.getCurrentThreadClassLoader(); try { //unsetSbbContext must be called with the context classloader //of the entities sbbDescriptor as with other sbb invocatiions. Thread.currentThread().setContextClassLoader(sbbComponent.getClassLoader()); if (sbbObject.getState() != SbbObjectState.DOES_NOT_EXIST) { sbbObject.unsetSbbContext(); } } finally { if (System.getSecurityManager() != null) AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { Thread.currentThread().setContextClassLoader(oldClassLoader); return null; } }); else Thread.currentThread().setContextClassLoader(oldClassLoader); } sbbObject.setState(SbbObjectState.DOES_NOT_EXIST); }
From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.EventAdminDispatcher.java
public void beforeRefresh(final BlueprintEvent event) { if (dispatcher != null) { try {/* w ww .ja v a 2 s.com*/ if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { dispatcher.beforeRefresh(event); return null; } }); } else { dispatcher.beforeRefresh(event); } } catch (Throwable th) { log.warn("Cannot dispatch event " + event, th); } } }
From source file:org.apache.jasper.runtime.JspFactoryImpl.java
public PageContext getPageContext(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoflush) { if (System.getSecurityManager() != null) { PrivilegedGetPageContext dp = new PrivilegedGetPageContext((JspFactoryImpl) this, servlet, request, response, errorPageURL, needsSession, bufferSize, autoflush); return (PageContext) AccessController.doPrivileged(dp); } else {/* w w w . j av a 2 s . c o m*/ return internalGetPageContext(servlet, request, response, errorPageURL, needsSession, bufferSize, autoflush); } }
From source file:org.apache.fop.render.afp.AFPForeignAttributeReader.java
/** * Returns the resource level//from www .ja v a 2 s. c om * * @param foreignAttributes the foreign attributes * @return the resource level */ public AFPResourceLevel getResourceLevel(Map/*<QName, String>*/ foreignAttributes) { AFPResourceLevel resourceLevel = null; if (foreignAttributes != null && !foreignAttributes.isEmpty()) { if (foreignAttributes.containsKey(RESOURCE_LEVEL)) { String levelString = (String) foreignAttributes.get(RESOURCE_LEVEL); resourceLevel = AFPResourceLevel.valueOf(levelString); // if external get resource group file attributes if (resourceLevel != null && resourceLevel.isExternal()) { String resourceGroupFile = (String) foreignAttributes.get(RESOURCE_GROUP_FILE); if (resourceGroupFile == null) { String msg = RESOURCE_GROUP_FILE + " not specified"; LOG.error(msg); throw new UnsupportedOperationException(msg); } File resourceExternalGroupFile = new File(resourceGroupFile); SecurityManager security = System.getSecurityManager(); try { if (security != null) { security.checkWrite(resourceExternalGroupFile.getPath()); } } catch (SecurityException ex) { String msg = "unable to gain write access to external resource file: " + resourceGroupFile; LOG.error(msg); } try { boolean exists = resourceExternalGroupFile.exists(); if (exists) { LOG.warn("overwriting external resource file: " + resourceGroupFile); } resourceLevel.setExternalFilePath(resourceGroupFile); } catch (SecurityException ex) { String msg = "unable to gain read access to external resource file: " + resourceGroupFile; LOG.error(msg); } } } } return resourceLevel; }
From source file:com.symbian.driver.remoting.master.TDIWrapper.java
/** * Standard Constructor// w ww .ja va 2 s . c om * * @param aTestPackage * A test pacakage path. * @param aResultsPath * A path where to collect the results. * @throws ArrayIndexOutOfBoundsException * @throws ParseException * @throws IOException * @throws TimeLimitExceededException */ public TDIWrapper(final File aTestPackage, final File aResultsPath) throws ArrayIndexOutOfBoundsException, ParseException, IOException, TimeLimitExceededException { // Setup Autmation Folder URL lSource = TDIWrapper.class.getProtectionDomain().getCodeSource().getLocation(); File lInstallationFolder = new File(lSource.getPath()).getParentFile().getParentFile(); iAutomationFolder = new File(lInstallationFolder, "automation"); LOGGER.info("Automation folder has been set as: " + iAutomationFolder); // Initialise Package final Task lStartTask = initialize(aTestPackage, aResultsPath); // for timeout set the root node of SymbianVisitor to xxyy // do some kind of stopping! lSymbianThread = new Thread(new Runnable() { public void run() { Thread lCurrentThread = Thread.currentThread(); if (lSymbianThread == lCurrentThread) { SymbianVisitor lSymbianVisitor = new SymbianVisitor(); try { TDConfig.getInstance().printConfig(true); } catch (IOException lE) { LOGGER.log(Level.WARNING, "Could not print the config..." + lE.getMessage(), lE); } // execute the test SecurityManager lSec = null; try { lSec = System.getSecurityManager(); //set security manager to disable system.exit() called by Test Driver System.setSecurityManager(new NoExitSecurityManager()); lSymbianVisitor.start(lStartTask); } catch (SecurityException lSecurityException) { // ignore } finally { // reset security manager so that the server can exit in case of problems. try { System.setSecurityManager(lSec); } catch (SecurityException lSecurityException) { // ignore } } // cleanup all data except testresults } } }); }
From source file:com.scoredev.scores.HighScore.java
/** * get the high score. return -1 if it hasn't been set. * *///from w ww .j a v a 2s. c o m public int getHighScore() throws IOException, ClassNotFoundException { //check permission first SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new HighScorePermission(gameName)); } Integer score = null; // need a doPrivileged block to manipulate the file try { score = (Integer) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException, ClassNotFoundException { Hashtable scores = null; // try to open the existing file. Should have a locking // protocol (could use File.createNewFile). FileInputStream fis = new FileInputStream(highScoreFile); ObjectInputStream ois = new ObjectInputStream(fis); scores = (Hashtable) ois.readObject(); // get the high score out return scores.get(gameName); } }); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); if (e instanceof IOException) throw (IOException) e; else throw (ClassNotFoundException) e; } if (score == null) return -1; else return score.intValue(); }
From source file:com.sshtools.common.hosts.AbstractHostKeyVerification.java
/** * Creates a new AbstractHostKeyVerification object. * * @param hostFileName/*from ww w .j a va 2s . c om*/ * * @throws InvalidHostFileException */ public AbstractHostKeyVerification(String hostFileName) throws InvalidHostFileException { InputStream in = null; try { // If no host file is supplied, or there is not enough permission to load // the file, then just create an empty list. if (hostFileName != null) { if (System.getSecurityManager() != null) { AccessController.checkPermission(new FilePermission(hostFileName, "read")); } // Load the hosts file. Do not worry if fle doesnt exist, just disable // save of File f = new File(hostFileName); if (f.exists()) { in = new FileInputStream(f); hostFile = hostFileName; SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); saxParser.parse(in, this); hostFileWriteable = f.canWrite(); } else { // Try to create the file if (f.createNewFile()) { FileOutputStream out = new FileOutputStream(f); out.write(toString().getBytes()); out.close(); hostFileWriteable = true; } else { hostFileWriteable = false; } } if (!hostFileWriteable) { log.warn("Host file is not writeable."); } } } catch (AccessControlException ace) { log.warn("Not enough permission to load a hosts file, so just creating an empty list"); } catch (IOException ioe) { throw new InvalidHostFileException("Could not open or read " + hostFileName); } catch (SAXException sax) { throw new InvalidHostFileException("Failed XML parsing: " + sax.getMessage()); } catch (ParserConfigurationException pce) { throw new InvalidHostFileException("Failed to initialize xml parser: " + pce.getMessage()); } finally { if (in != null) { try { in.close(); } catch (IOException ioe) { } } } }
From source file:net.sf.mpaxs.spi.computeHost.StartUp.java
/** * * @param cfg/*from w w w .ja v a 2 s.co m*/ */ public StartUp(Configuration cfg) { Settings settings = new Settings(cfg); try { System.setProperty("java.rmi.server.codebase", settings.getCodebase().toString()); Logger.getLogger(StartUp.class.getName()).log(Level.INFO, "RMI Codebase at {0}", settings.getCodebase().toString()); } catch (MalformedURLException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } File policyFile; policyFile = new File(new File(settings.getOption(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR)), settings.getPolicyName()); if (!policyFile.exists()) { System.out.println("Did not find security policy, will create default one!"); policyFile.getParentFile().mkdirs(); BufferedReader br = new BufferedReader(new InputStreamReader( StartUp.class.getResourceAsStream("/net/sf/mpaxs/spi/computeHost/wideopen.policy"))); try { BufferedWriter bw = new BufferedWriter(new FileWriter(policyFile)); String s = null; while ((s = br.readLine()) != null) { bw.write(s + "\n"); } bw.flush(); bw.close(); br.close(); Logger.getLogger(StartUp.class.getName()).log(Level.INFO, "Using security policy at " + policyFile.getAbsolutePath()); } catch (IOException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } } else { Logger.getLogger(StartUp.class.getName()).log(Level.INFO, "Found existing policy file at " + policyFile.getAbsolutePath()); } System.setProperty("java.security.policy", policyFile.getAbsolutePath()); System.setProperty("java.net.preferIPv4Stack", "true"); if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } Logger.getLogger(StartUp.class.getName()).log(Level.FINE, "Creating host"); Host h = new Host(); Logger.getLogger(StartUp.class.getName()).log(Level.FINE, "Configuring host"); h.configure(cfg); Logger.getLogger(StartUp.class.getName()).log(Level.FINE, "Setting auth token " + settings.getOption(ConfigurationKeys.KEY_AUTH_TOKEN)); String at = settings.getOption(ConfigurationKeys.KEY_AUTH_TOKEN); h.setAuthenticationToken(UUID.fromString(at)); Logger.getLogger(StartUp.class.getName()).log(Level.INFO, "Starting host {0}", settings.getHostID()); h.startComputeHost(); }
From source file:com.liferay.maven.arquillian.internal.tasks.ExecuteDeployerTask.java
protected void executeTool(String deployerClassName, 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() { @Override/*from w ww. j a v a 2s. c om*/ public void checkPermission(Permission permission) { } @Override 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(deployerClassName); Method method = clazz.getMethod("main", String[].class); method.invoke(null, (Object) args); } catch (InvocationTargetException ite) { if (!(ite.getCause() instanceof SecurityException)) { throw ite; } } finally { currentThread.setContextClassLoader(contextClassLoader); System.setSecurityManager(currentSecurityManager); } }