List of usage examples for java.lang System getSecurityManager
public static SecurityManager getSecurityManager()
From source file:org.docx4all.ui.main.WordMLEditor.java
public static void main(String[] args) { // // Whenever we flush Preferences on Linux, we need *not* to use // // our Xalan jar (which we need // javax.xml.transform.TransformerFactory tfactory = javax.xml.transform.TransformerFactory.newInstance(); // TRANSFORMER_FACTORY_DEFAULT = tfactory.getClass().getName(); // log.debug("Set TRANSFORMER_FACTORY_DEFAULT to " + TRANSFORMER_FACTORY_DEFAULT); // If we launch via JNLP with Java 6 JAXB (as opposed to the JAXB RI), // we trip up with access denied on RuntimePermission accessDeclaredMembers // (is this because NamespacePrefixMapperSunInternal extends com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper?). // This is despite the JNLP file seeking all-permissions. // Workaround: if (System.getSecurityManager() == null) { System.out.println("Initial SecurityManager: null"); } else {//from w ww . ja va 2s . com System.out.println("Initial SecurityManager: " + System.getSecurityManager().getClass().getName()); System.setSecurityManager(null); } launch(WordMLEditor.class, args); }
From source file:engine.Pi.java
public static void main(String args[]) { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }// www . ja v a 2 s . co m try { String name = "Compute"; Registry registry = LocateRegistry.getRegistry(args[0]); Compute comp = (Compute) registry.lookup(name); Pi task = new Pi(Integer.parseInt(args[1])); BigDecimal pi = comp.executeTask(task); System.out.println(pi); } catch (Exception e) { System.err.println("ComputePi exception:"); e.printStackTrace(); } }
From source file:uk.co.moonsit.rmi.GraphClient.java
@SuppressWarnings("SleepWhileInLoop") public static void main(String args[]) { Properties p = new Properties(); try {/*from www.ja v a 2 s . c o m*/ p.load(new FileReader("graph.properties")); } catch (IOException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } //String[] labels = p.getProperty("labels").split(","); GraphClient demo = null; int type = 0; boolean log = false; if (args[0].equals("-l")) { log = true; } switch (type) { case 0: try { System.setProperty("java.security.policy", "file:./client.policy"); if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } String name = "GraphServer"; String host = p.getProperty("host"); System.out.println(host); Registry registry = LocateRegistry.getRegistry(host); String[] list = registry.list(); for (String s : list) { System.out.println(s); } GraphDataInterface gs = null; boolean bound = false; while (!bound) { try { gs = (GraphDataInterface) registry.lookup(name); bound = true; } catch (NotBoundException e) { System.err.println("GraphServer exception:" + e.toString()); Thread.sleep(500); } } @SuppressWarnings("null") String config = gs.getConfig(); System.out.println(config); /*float[] fs = gs.getValues(); for (float f : fs) { System.out.println(f); }*/ demo = new GraphClient(gs, 1000, 700, Float.parseFloat(p.getProperty("frequency")), log); demo.init(config); demo.run(); } catch (RemoteException e) { System.err.println("GraphClient exception:" + e.toString()); } catch (FileNotFoundException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } finally { if (demo != null) { demo.close(); } } break; case 1: try { demo = new GraphClient(1000, 700, Float.parseFloat(p.getProperty("frequency"))); demo.init("A^B|Time|Error|-360|360"); demo.addData(0, 1, 100); demo.addData(0, 2, 200); demo.addData(1, 1, 50); demo.addData(1, 2, 450); } catch (FileNotFoundException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } break; } }
From source file:org.pegadi.client.ApplicationLauncher.java
public static void main(String[] args) { com.sun.net.ssl.internal.ssl.Provider provider = new com.sun.net.ssl.internal.ssl.Provider(); java.security.Security.addProvider(provider); setAllPermissions();//from w ww . j a v a 2s . c o m /** * If we are on Apples operating system, we would like to use the screen * menu bar It is the first property we set in our main method. This is * to make sure that the property is set before awt is loaded. */ if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) { System.setProperty("apple.laf.useScreenMenuBar", "true"); } Logger log = LoggerFactory.getLogger(ApplicationLauncher.class); /** * Making sure default L&F is System */ if (!UIManager.getLookAndFeel().getName().equals(UIManager.getSystemLookAndFeelClassName())) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { log.warn("Unable to change L&F to System", e); } } long start = System.currentTimeMillis(); // Splash Splash splash = new Splash("/images/splash.png"); splash.setVisible(true); splash.setCursor(new Cursor(Cursor.WAIT_CURSOR)); if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/pegadi/client/client-context.xml"); closeContextOnShutdown(context); long timeToLogin = System.currentTimeMillis() - start; log.info("Connected OK after {} ms", timeToLogin); log.info("Java Version {}", System.getProperty("java.version")); splash.dispose(); }
From source file:Utils.java
public static void makeAccessible(final AccessibleObject object) { if (!object.isAccessible()) { if (System.getSecurityManager() == null) { object.setAccessible(true);// w w w . java 2 s . c o m } else { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { object.setAccessible(true); return null; } }); } } }
From source file:Main.java
public static ThreadGroup createThreadGroup(String name) { SecurityManager s = System.getSecurityManager(); ThreadGroup parent = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); return new ThreadGroup(parent, name); }
From source file:CustomSecurityManager.java
public static void main() { System.setSecurityManager(new CustomSecurityManager()); SecurityManager secMgr = System.getSecurityManager(); if (secMgr != null) { secMgr.checkRead("fileName"); }/*from w w w.j a v a 2s. c o m*/ }
From source file:org.tinygroup.jspengine.security.SecurityClassLoad.java
public static void securityClassLoad(ClassLoader loader) { if (System.getSecurityManager() == null) { return;//from w w w. j a va2 s. c o m } String basePackage = "org.tinygroup.jspengine."; try { loader.loadClass(basePackage + "runtime.JspFactoryImpl$PrivilegedGetPageContext"); loader.loadClass(basePackage + "runtime.JspFactoryImpl$PrivilegedReleasePageContext"); loader.loadClass(basePackage + "runtime.JspRuntimeLibrary"); loader.loadClass(basePackage + "runtime.JspRuntimeLibrary$PrivilegedIntrospectHelper"); loader.loadClass(basePackage + "runtime.ServletResponseWrapperInclude"); loader.loadClass(basePackage + "runtime.TagHandlerPool"); loader.loadClass(basePackage + "runtime.JspFragmentHelper"); loader.loadClass(basePackage + "runtime.ProtectedFunctionMapper"); loader.loadClass(basePackage + "runtime.ProtectedFunctionMapper$1"); loader.loadClass(basePackage + "runtime.ProtectedFunctionMapper$2"); loader.loadClass(basePackage + "runtime.ProtectedFunctionMapper$3"); loader.loadClass(basePackage + "runtime.ProtectedFunctionMapper$4"); loader.loadClass(basePackage + "runtime.PageContextImpl"); loader.loadClass(basePackage + "runtime.PageContextImpl$1"); loader.loadClass(basePackage + "runtime.PageContextImpl$2"); loader.loadClass(basePackage + "runtime.PageContextImpl$3"); loader.loadClass(basePackage + "runtime.PageContextImpl$4"); loader.loadClass(basePackage + "runtime.PageContextImpl$5"); loader.loadClass(basePackage + "runtime.PageContextImpl$6"); loader.loadClass(basePackage + "runtime.PageContextImpl$7"); loader.loadClass(basePackage + "runtime.PageContextImpl$8"); loader.loadClass(basePackage + "runtime.PageContextImpl$9"); loader.loadClass(basePackage + "runtime.PageContextImpl$10"); loader.loadClass(basePackage + "runtime.PageContextImpl$11"); loader.loadClass(basePackage + "runtime.JspContextWrapper"); loader.loadClass(basePackage + "servlet.JspServletWrapper"); loader.loadClass(basePackage + "runtime.JspWriterImpl$1"); } catch (ClassNotFoundException ex) { log.error("SecurityClassLoad", ex); } }
From source file:SecurityActions.java
static ClassLoader getTCL() { if (System.getSecurityManager() == null) { return Thread.currentThread().getContextClassLoader(); } else {/*from w w w .ja va 2 s. c o m*/ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } }); } }
From source file:ReflectionExecutor.java
/** * Execution of reflection with {@link ReflectionAction}. * //from w w w .j a v a 2 s . co m * @param <T> * @param action * @return */ public static <T> T doSafeAction(final ReflectionAction<T> action) { final SecurityManager securityManager = System.getSecurityManager(); if (securityManager == null) { try { return action.run(); } catch (Exception e) { throw new RuntimeException(e); } } try { return AccessController.doPrivileged(new PrivilegedExceptionAction<T>() { @Override public T run() throws Exception { return action.run(); } }); } catch (PrivilegedActionException e) { Throwable cause = e.getCause(); if (InvocationTargetException.class.isInstance(cause)) { InvocationTargetException e1 = (InvocationTargetException) cause; throw new Exception(e1.getTargetException()); } throw new Exception(cause); } }