List of usage examples for java.lang System getSecurityManager
public static SecurityManager getSecurityManager()
From source file:org.pentaho.di.kitchen.KitchenIT.java
@Before public void setUp() { oldSecurityManager = System.getSecurityManager(); System.setSecurityManager(new MySecurityManager(oldSecurityManager)); }
From source file:com.sshtools.common.ui.ResourceIcon.java
/** * * * @param imageName//from ww w . jav a2 s . c o m */ protected void loadImage(String imageName) { Image image = null; URL url = cls.getResource(imageName); if (url != null) { log.debug(url.toString()); image = Toolkit.getDefaultToolkit().getImage(url); } else { try { if (System.getSecurityManager() != null) { AccessController.checkPermission(new FilePermission(imageName, "read")); } image = Toolkit.getDefaultToolkit().getImage(imageName); } catch (AccessControlException ace) { log.error("Icon " + imageName + " could not be located as a " + "resource, and the current security manager will not " + "allow checking for a local file."); } } if (image != null) { this.setImage(image); } }
From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.EventAdminDispatcher.java
public void beforeClose(final BlueprintEvent event) { if (dispatcher != null) { try {/*www. j av a 2s . com*/ if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { dispatcher.beforeClose(event); return null; } }); } else { dispatcher.beforeClose(event); } } catch (Throwable th) { log.warn("Cannot dispatch event " + event, th); } } }
From source file:com.sshtools.j2ssh.transport.AbstractKnownHostsKeyVerification.java
/** * <p>//ww w. ja v a 2 s . com * Constructs a host key verification instance reading the specified * known_hosts file. * </p> * * @param knownhosts the path of the known_hosts file * * @throws InvalidHostFileException if the known_hosts file is invalid * * @since 0.2.0 */ public AbstractKnownHostsKeyVerification(String knownhosts) 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 (knownhosts != null) { if (System.getSecurityManager() != null) { AccessController.checkPermission(new FilePermission(knownhosts, "read")); } // Load the hosts file. Do not worry if fle doesnt exist, just disable // save of File f = new File(knownhosts); if (f.exists()) { in = new FileInputStream(f); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { StringTokenizer tokens = new StringTokenizer(line, " "); String host = (String) tokens.nextElement(); String algorithm = (String) tokens.nextElement(); String key = (String) tokens.nextElement(); SshPublicKey pk = SshKeyPairFactory.decodePublicKey(Base64.decode(key)); /*if (host.indexOf(",") > -1) { host = host.substring(0, host.indexOf(",")); }*/ putAllowedKey(host, pk); //allowedHosts.put(host + "#" + pk.getAlgorithmName(), pk); } reader.close(); hostFileWriteable = f.canWrite(); } else { // Try to create the file and its parents if necersary f.getParentFile().mkdirs(); 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."); } this.knownhosts = knownhosts; } } catch (AccessControlException ace) { hostFileWriteable = false; log.warn("Not enough permission to load a hosts file, so just creating an empty list"); } catch (IOException ioe) { hostFileWriteable = false; log.info("Could not open or read " + knownhosts + ": " + ioe.getMessage()); } finally { if (in != null) { try { in.close(); } catch (IOException ioe) { } } } }
From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerUtil.java
/** * Creates a {@link ScheduledThreadPoolExecutor} for use on {@link LogsDownloaderWorker}. * /*ww w. ja v a2 s. co m*/ * @param caller * @return */ static ScheduledThreadPoolExecutor createThreadPool(LogsDownloaderWorker caller) { ScheduledThreadPoolExecutor ret = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(4, new ThreadFactory() { private ThreadGroup group; private long count = 0; { SecurityManager s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); } @Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r); t.setName(caller.getClass().getSimpleName() + "::" + Integer.toHexString(caller.hashCode()) + "::" + count++); t.setDaemon(true); return t; } }); return ret; }
From source file:org.wso2.carbon.core.ServerManagement.java
/** * Method to switch a node to maintenance mode. * <p/>// w w w . j av a 2 s . c om * Here is the sequence of events: * <p/> * <ol> * <li>Client calls this method</li> * <li>The server stops accepting new requests/connections, but continues to stay alive so * that old requests & connections can be served</li> * <li>Once all requests have been processed, the method returns</li * </ol> * @throws Exception - on errors while starting maintenance */ public void startMaintenance() throws Exception { SecurityManager secMan = System.getSecurityManager(); if (secMan != null) { secMan.checkPermission(new ManagementPermission("control")); } log.info("Starting to switch to maintenance mode..."); for (TransportInDescription tinDesc : inTransports.values()) { TransportListener transport = tinDesc.getReceiver(); transport.stop(); } log.info("Stopped all transport listeners"); waitForRequestCompletion(); }
From source file:org.kchine.r.server.http.frontend.RebindServlet.java
public void init(ServletConfig sConfig) throws ServletException { super.init(sConfig); log.info("command servlet init"); PoolUtils.injectSystemProperties(true); ServerDefaults.init();//from ww w. j ava 2 s . c o m if (System.getSecurityManager() == null) { System.setSecurityManager(new YesSecurityManager()); } }
From source file:org.beangle.model.persist.hibernate.internal.ChainedClassLoader.java
public Class<?> loadClass(final String name) throws ClassNotFoundException { if (System.getSecurityManager() != null) { try {/* www. j a v a 2s. c o m*/ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() { public Class<?> run() throws Exception { return doLoadClass(name); } }); } catch (PrivilegedActionException pae) { throw (ClassNotFoundException) pae.getException(); } } else { return doLoadClass(name); } }
From source file:com.sshtools.j2ssh.configuration.ConfigurationLoader.java
/** * * * @param property//from w ww . j av a2 s . c o m * @param defaultValue * * @return */ public static String checkAndGetProperty(String property, String defaultValue) { // Check for access to sshtools.platform try { if (System.getSecurityManager() != null) { AccessController.checkPermission(new PropertyPermission(property, "read")); } return System.getProperty(property, defaultValue); } catch (AccessControlException ace) { return defaultValue; } }
From source file:org.wso2.carbon.webapp.mgt.TomcatGenericWebappsDeployer.java
/** * Constructor//from ww w. ja va2 s . c o m * * @param webContextPrefix The Web context prefix * @param tenantId The tenant ID of the tenant to whom this deployer belongs to * @param tenantDomain The tenant domain of the tenant to whom this deployer belongs to * @param webApplicationsHolderMap WebApplicationsHolder */ public TomcatGenericWebappsDeployer(String webContextPrefix, int tenantId, String tenantDomain, Map<String, WebApplicationsHolder> webApplicationsHolderMap, ConfigurationContext configurationContext) { SecurityManager secMan = System.getSecurityManager(); if (secMan != null) { secMan.checkPermission(new ManagementPermission("control")); } this.tenantId = tenantId; this.tenantDomain = tenantDomain; this.webContextPrefix = webContextPrefix; this.webApplicationsHolderMap = webApplicationsHolderMap; this.configurationContext = configurationContext; }