List of usage examples for java.lang SecurityManager SecurityManager
public SecurityManager()
SecurityManager
. From source file:com.phonegap.DirectoryManager.java
/** * Delete directory./*from www . j a v a2 s .c om*/ * * @param fileName The name of the directory to delete * @return T=deleted, F=could not delete */ protected static boolean deleteDirectory(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); // Make sure SD card exists if ((testSaveLocationExists()) && (!fileName.equals(""))) { File path = Environment.getExternalStorageDirectory(); File newPath = constructFilePaths(path.toString(), fileName); checker.checkDelete(newPath.toString()); // If dir to delete is really a directory if (newPath.isDirectory()) { String[] listfile = newPath.list(); // Delete all files within the specified directory and then delete the directory try { for (int i = 0; i < listfile.length; i++) { File deletedFile = new File(newPath.toString() + "/" + listfile[i].toString()); deletedFile.delete(); } newPath.delete(); Log.i("DirectoryManager deleteDirectory", fileName); status = true; } catch (Exception e) { e.printStackTrace(); status = false; } } // If dir not a directory, then error else { status = false; } } // If no SD card else { status = false; } return status; }
From source file:org.firstopen.custom.view.EventMonitorBean.java
public EventMonitorBean(String name) throws InfrastructureException { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }/*from w w w . j av a 2 s.com*/ JMSUtil.createQueue(MONITOR_NAME); connection = JMSUtil.getQueueConnection(); try { queueSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer receiver = queueSession.createConsumer(JMSUtil.getQueue(MONITOR_NAME)); receiver.setMessageListener(this); connection.start(); } catch (JMSException e) { log.error("unable to start listener on Queue"); throw new InfrastructureException(e); } }
From source file:org.eu.gasp.core.bootstrap.Bootstrap.java
public Bootstrap(final String homeDir, final String policyFilePath, final String log4jFilePath, final String propertyFilePath) { if (StringUtils.isBlank(homeDir)) { throw new IllegalArgumentException("homeDir"); }/*from www . ja va 2 s. c o m*/ try { this.homeDir = new File(homeDir).getCanonicalPath(); } catch (Exception e) { throw new IllegalStateException("Unexpected exception", e); } // the home dir is declared in the System properties System.setProperty("gasp.home", homeDir); try { this.propertyFilePath = new File(homeDir, propertyFilePath == null ? "conf/gasp.properties" : propertyFilePath).getCanonicalPath(); } catch (Exception e) { throw new IllegalStateException("Unexpected exception", e); } this.log4jFilePath = log4jFilePath; if (!StringUtils.isBlank(policyFilePath)) { // installing security manager try { System.setProperty("java.security.policy", new File(homeDir, policyFilePath).getAbsoluteFile().toURI().toURL().toExternalForm()); System.setSecurityManager(new SecurityManager()); } catch (Exception e) { throw new IllegalStateException("Error while setting the Java security policy", e); } } // adding a shutdown hook to properly close the application Runtime.getRuntime().addShutdownHook(new ShutdownHook(this)); }
From source file:se.tillvaxtverket.ttsigvalws.ttwebservice.TTSigValServlet.java
@Override public void init(ServletConfig config) throws ServletException { this.context = config.getServletContext(); // Remove any occurance of the BC provider Security.removeProvider("BC"); // Insert the BC provider in a preferred position Security.insertProviderAt(new BouncyCastleProvider(), 1); try {/*from w w w . ja va 2 s. c o m*/ SecurityManager secMan = new SecurityManager(); secMan.checkSetFactory(); HttpURLConnection.setContentHandlerFactory(new OCSPContentHandlerFactory()); LOG.info("Setting URL Content handler factory to OCSPContentHandlerFactory"); } catch (Exception ex) { LOG.warning("Error when setting URL content handler factory"); } infoText = ResourceBundle.getBundle("infoText"); LOG.info(currentDir); String dataDir = context.getInitParameter("DataDirectory"); ConfigData conf = new ConfigData(dataDir); baseModel = new SigValidationBaseModel(conf); Locale.setDefault(new Locale(baseModel.getConf().getLanguageCode())); }
From source file:net.sf.mpaxs.spi.computeHost.StartUp.java
/** * * @param cfg//from www . j a v a 2 s . c o 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 www . j a v a 2 s . 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); } }
From source file:org.firstopen.singularity.admin.view.ECSpecBean.java
public ECSpecBean(String name) { try {//from w w w . j av a2 s. c o m if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } InitialContext jndiContext = JNDIUtil.getInitialContext(); Object objref = jndiContext.lookup("jnp://localhost:1099/ejb/ale/AleSLSB"); AleSLSBHome aleSLSBHome = (AleSLSBHome) PortableRemoteObject.narrow(objref, AleSLSBHome.class); aSLSB = aleSLSBHome.create(); createLogicalDeviceSelectList(); createECSpecSelectList(); } catch (Exception e) { log.error("can't create ECSpecBean"); /* * can't recover wrap in RuntimeException */ throw new InfrastructureException(e); } }
From source file:com.liferay.arquillian.maven.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// www. j a v a 2 s . c o m public void checkPermission(Permission permission) { //It is not needed to check permissions } @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); } }
From source file:org.nebulaframework.grid.Grid.java
/** * Starts {@link ClusterManager} instance with default settings, * read from default properties file./*from www . j a va 2s. co m*/ * * @return ClusterManager * * @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 ClusterManager startClusterManager() 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(); log.info("ClusterManager Starting..."); // Set Security Manager System.setSecurityManager(new SecurityManager()); // Detect Configuration Properties config = ConfigurationSupport.detectClusterConfiguration(); // Register with any Colombus Servers ClusterDiscoverySupport.registerColombus(config); clusterManager = true; log.debug("Starting up Spring Container..."); applicationContext = new NebulaApplicationContext(CLUSTER_SPRING_CONTEXT, config); log.debug("Spring Container Started"); return (ClusterManager) applicationContext.getBean("clusterManager"); } finally { sw.stop(); log.info("ClusterManager Started Up. " + sw.getLastTaskTimeMillis() + " ms"); } }
From source file:com.phonegap.DirectoryManager.java
/** * Delete file.// w w w. ja v a2 s .co m * * @param fileName The name of the file to delete * @return T=deleted, F=not deleted */ protected static boolean deleteFile(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); // Make sure SD card exists if ((testSaveLocationExists()) && (!fileName.equals(""))) { File path = Environment.getExternalStorageDirectory(); File newPath = constructFilePaths(path.toString(), fileName); checker.checkDelete(newPath.toString()); // If file to delete is really a file if (newPath.isFile()) { try { Log.i("DirectoryManager deleteFile", fileName); newPath.delete(); status = true; } catch (SecurityException se) { se.printStackTrace(); status = false; } } // If not a file, then error else { status = false; } } // If no SD card else { status = false; } return status; }