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:Main.java

public static void main(String[] args) {
    AccessControlContext con = AccessController.getContext();

    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkRead("test.txt", con);

    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    // perform the check
    sm.checkExit(5);//from w w  w  . j a v  a 2s.com
    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkPackageAccess("java2s.com");

    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    // check if accepting access for thread group is enabled
    sm.checkAccess(new ThreadGroup("example"));

    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkPackageDefinition("java2s.com");

    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) {
    AccessControlContext con = AccessController.getContext();

    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkPermission(new FilePermission("test.txt", "read,write"), con);

    System.out.println("Allowed!");
}

From source file:Main.java

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

    SecurityManager sm = new SecurityManager();
    System.setSecurityManager(sm);
    URL codebase = new URL("http://java.sun.com/");

    //codebase = new File("c:\\java\\").toURI().toURL();
    //codebase = new File(System.getProperty("user.home")).toURI().toURL();

    CodeSource cs = new CodeSource(codebase, (Certificate[]) null);

    PermissionCollection pcoll = Policy.getPolicy().getPermissions(cs);

    Enumeration e = pcoll.elements();
    for (; e.hasMoreElements();) {
        Permission p = (Permission) e.nextElement();
    }/* w ww  .j  a va2  s .  com*/
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkMemberAccess(Main.class, Member.PUBLIC);

    System.out.println("Allowed!");
}

From source file:groovesquid.Main.java

public static void main(String[] args) {

    System.setSecurityManager(null);

    log.log(Level.INFO, "Groovesquid v{0} running on {1} {2} ({3}) in {4}",
            new Object[] { version, System.getProperty("java.vm.name"),
                    System.getProperty("java.runtime.version"), System.getProperty("java.vm.vendor"),
                    System.getProperty("java.home") });

    // show gui/* w w  w. ja  va2 s . c o m*/

    // apple os x
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Groovesquid");
    // antialising
    System.setProperty("awt.useSystemAAFontSettings", "lcd");
    System.setProperty("swing.aatext", "true");
    // flackering bg fix
    System.setProperty("sun.awt.noerasebackground", "true");
    System.setProperty("sun.java2d.noddraw", "true");
    Toolkit.getDefaultToolkit().setDynamicLayout(true);

    try {
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        log.log(Level.SEVERE, null, ex);
    }

    // load languages
    languages = loadLanguages();

    // Load config
    config = loadConfig();

    // GUI
    try {
        gui = (GUI) config.getGuiClass().newInstance();
    } catch (InstantiationException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    settings = new Settings();
    about = new About();

    // Update Checker
    new UpdateCheckThread().start();

    // init grooveshark (every 25min)
    new InitThread().start();

}

From source file:client.ComputePi.java

public static void main(String args[]) {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }//  w  ww.  j  a v  a  2s .  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();
    }
}