Example usage for java.lang System setSecurityManager

List of usage examples for java.lang System setSecurityManager

Introduction

In this page you can find the example usage for java.lang System setSecurityManager.

Prototype

public static void setSecurityManager(SecurityManager sm) 

Source Link

Document

Sets the system-wide security manager.

Usage

From source file:engine.ComputeEngine.java

public static void main(String[] args) {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }/*from www.j a  v a  2s.  c om*/
    try {
        String name = "Compute";
        Compute engine = new ComputeEngine();
        Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0);
        Registry registry = LocateRegistry.getRegistry();
        registry.rebind(name, stub);
        System.out.println("ComputeEngine bound");
    } catch (Exception e) {
        System.err.println("ComputeEngine exception:");
        e.printStackTrace();
    }
}

From source file:SecurityManagerTest.java

public static void main(String[] args) throws Exception {
    try {/*from   w ww .  java  2 s.  c o m*/
        System.setSecurityManager(new PasswordSecurityManager("Booga Booga"));
    } catch (SecurityException se) {
        System.err.println("SecurityManager already set!");
    }

    DataInputStream in = new DataInputStream(new FileInputStream("inputtext.txt"));
    DataOutputStream out = new DataOutputStream(new FileOutputStream("outputtext.txt"));
    String inputString;
    while ((inputString = in.readLine()) != null) {
        out.writeBytes(inputString);
        out.writeByte('\n');
    }
    in.close();
    out.close();
}

From source file:azkaban.soloserver.AzkabanSingleServer.java

public static void main(String[] args) throws Exception {
    log.info("Starting Azkaban Server");

    if (System.getSecurityManager() == null) {
        Policy.setPolicy(new Policy() {
            @Override//w  ww  .  j a v  a2  s . co  m
            public boolean implies(final ProtectionDomain domain, final Permission permission) {
                return true; // allow all
            }
        });
        System.setSecurityManager(new SecurityManager());
    }

    if (args.length == 0) {
        args = prepareDefaultConf();
    }

    final Props props = AzkabanServer.loadProps(args);
    if (props == null) {
        log.error("Properties not found. Need it to connect to the db.");
        log.error("Exiting...");
        return;
    }

    if (props.getBoolean(AzkabanDatabaseSetup.DATABASE_CHECK_VERSION, true)) {
        final boolean updateDB = props.getBoolean(AzkabanDatabaseSetup.DATABASE_AUTO_UPDATE_TABLES, true);
        final String scriptDir = props.getString(AzkabanDatabaseSetup.DATABASE_SQL_SCRIPT_DIR, "sql");
        AzkabanDatabaseUpdater.runDatabaseUpdater(props, scriptDir, updateDB);
    }

    /* Initialize Guice Injector */
    final Injector injector = Guice.createInjector(new AzkabanCommonModule(props), new AzkabanWebServerModule(),
            new AzkabanExecServerModule());
    SERVICE_PROVIDER.setInjector(injector);

    /* Launch server */
    injector.getInstance(AzkabanSingleServer.class).launch();
}

From source file:edu.clemson.cs.nestbed.client.Client.java

public static void main(String[] args) throws Exception {
    /*/*from w w w  .  j  a  v  a2s  .  c  om*/
    System.setOut(new PrintStream(new BufferedOutputStream(
              new LogOutputStream(System.class, Level.WARN)),  true));
    System.setErr(new PrintStream(new BufferedOutputStream(
              new LogOutputStream(System.class, Level.ERROR)), true));
              */

    loadProperties();

    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new RMISecurityManager());
    }

    PropertyConfigurator.configure(Client.class.getClassLoader().getResource("clientLog.conf"));

    log.info("******************************************************\n" + "** NESTbed Client Starting\n"
            + "******************************************************");
    log.info("Version:  " + Version.VERSION);

    log.debug("Class Loader:  " + Client.class.getClassLoader());
    ParentClassLoader.setParent(Client.class.getClassLoader());

    TestbedManagerFrame mainWindow = new TestbedManagerFrame();
    mainWindow.setVisible(true);
}

From source file:ParallelizedMatrixProduct.java

public static void main(String args[]) throws Exception {

    System.setSecurityManager(new YesSecurityManager());

    double[][] matrix1 = new double[MATRIX_SIZE][MATRIX_SIZE];
    double[][] matrix2 = new double[MATRIX_SIZE][MATRIX_SIZE];

    for (int i = 0; i < MATRIX_SIZE; ++i)
        for (int j = 0; j < MATRIX_SIZE; ++j) {
            matrix1[i][j] = Math.round(Math.random() * MATRIX_ELEMENT_MAX_VALUE);
            matrix2[i][j] = Math.round(Math.random() * MATRIX_ELEMENT_MAX_VALUE);
        }/* www.  java2s  .co  m*/

    ExecutorService exec = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
    Future<Double>[][] futures = new Future[MATRIX_SIZE][MATRIX_SIZE];
    for (int i = 0; i < MATRIX_SIZE; ++i) {
        for (int j = 0; j < MATRIX_SIZE; ++j) {
            final double[] v1 = getRow(matrix1, i);
            final double[] v2 = getColumn(matrix2, j);

            if (i % 2 == 0) {
                futures[i][j] = exec.submit(new Callable<Double>() {
                    public Double call() {

                        RPFSessionInfo.get().put("USER", "USER FOR " + Thread.currentThread().getName());
                        RServices rp = null;
                        int replayCounter = NBR_REPLAY_ON_FAILURE;

                        while (replayCounter >= 0) {

                            try {

                                rp = (RServices) org.kchine.rpf.ServantProviderFactory.getFactory()
                                        .getServantProvider().borrowServantProxy();

                                rp.putAndAssign(new RNumeric(v1), "rv1");
                                rp.putAndAssign(new RNumeric(v2), "rv2");
                                RMatrix res = ((RMatrix) rp.getObject("rv1%*%rv2"));

                                return ((RNumeric) res.getValue()).getValue()[0];

                            } catch (TimeoutException e) {
                                e.printStackTrace();
                                return null;
                            } catch (RemoteException re) {
                                re.printStackTrace();
                                --replayCounter;

                            } finally {

                                try {
                                    if (rp != null) {
                                        ServantProviderFactory.getFactory().getServantProvider()
                                                .returnServantProxy(rp);
                                        log.info("<" + Thread.currentThread().getName()
                                                + "> returned resource : " + rp.getServantName());
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                            }

                        }

                        return null;

                    }
                });
            } else {
                futures[i][j] = exec.submit(new Callable<Double>() {
                    public Double call() {

                        try {
                            return vecprod(v1, v2);
                        } finally {
                            log.info("<" + Thread.currentThread().getName() + "> Java task ended successfully");
                        }
                    }
                });
            }
        }

    }

    while (true) {
        if (countDone(futures) == (MATRIX_SIZE * MATRIX_SIZE))
            break;
        try {
            Thread.sleep(20);
        } catch (Exception e) {
        }
    }

    log.info(" done --  product matrix -->");

    Double[][] matrix1_x_matrix2 = new Double[MATRIX_SIZE][MATRIX_SIZE];
    for (int i = 0; i < MATRIX_SIZE; ++i)
        for (int j = 0; j < MATRIX_SIZE; ++j)
            matrix1_x_matrix2[i][j] = futures[i][j].get();

    System.out.println(showMatrix(matrix1, "M1"));
    System.out.println(showMatrix(matrix2, "M2"));
    System.out.println(showMatrix(matrix1_x_matrix2, "M1 x M2"));

    System.exit(0);
}

From source file:edu.cornell.med.icb.R.RConfigurationServer.java

public static void main(final String[] args) throws RemoteException {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }/*from  w  w w .j ava 2  s. c o m*/

    final String name = "RConfiguration";
    final RConfiguration engine = new RConfigurationServer();
    final RConfiguration stub = (RConfiguration) UnicastRemoteObject.exportObject(engine, 0);
    final Registry registry = LocateRegistry.getRegistry();
    System.out.println(ArrayUtils.toString(registry.list()));
    registry.rebind(name, stub);
    System.out.println("RConfiguration bound");
}

From source file:engine.Pi.java

public static void main(String args[]) {
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }//from   w  ww  .j a v a2s. c om
        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 {//  w  w  w  . j  ava2 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  w w.  j  a v  a2  s.co  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:CustomSecurityManager.java

public static void main() {
    System.setSecurityManager(new CustomSecurityManager());
    SecurityManager secMgr = System.getSecurityManager();
    if (secMgr != null) {
        secMgr.checkRead("fileName");
    }/*  www .j a  v a  2s  . c  o  m*/
}