Java Code Examples for java.lang.System#getSecurityManager()

The following examples show how to use java.lang.System#getSecurityManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDynamicPolicy.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 2
Source File: TestDynamicPolicy.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 3
Source File: TestDynamicPolicy.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 4
Source File: TestDynamicPolicy.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 5
Source File: TestDynamicPolicy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 6
Source File: TestDynamicPolicy.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 7
Source File: TestDynamicPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 8
Source File: TestDynamicPolicy.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 9
Source File: TestDynamicPolicy.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 10
Source File: TestDynamicPolicy.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 11
Source File: TestDynamicPolicy.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 12
Source File: TestDynamicPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}
 
Example 13
Source File: TestDynamicPolicy.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void doit() throws Exception {
    // A security manager must be installed
    SecurityManager sm=System.getSecurityManager();
    if (sm==null)
        throw new
            Exception("Test must be run with a security manager installed");

    // Instantiate and set the new policy
    DynamicPolicy dp = new DynamicPolicy();
    Policy.setPolicy(dp);

    // Verify that policy has been set
    if (dp != Policy.getPolicy())
        throw new Exception("Policy was not set!!");

    // now see this class can access user.name
    String usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name prior to refresh!");
        throw new
            Exception("Test was able to read user.name prior to refresh!");
    }

    // Now, make policy allow reading user.name
    dp.refresh();

    // now I should be able to read it
    usr = getUserName();

    if (usr == null) {
        System.out.println("Test was unable to read user.name after refresh!");
        throw new
            Exception("Test was unable to read user.name after refresh!");
    }
    // Now, take away permission to read user.name
    dp.refresh();

    // now I should not be able to read it
    usr = getUserName();

    if (usr != null) {
        System.out.println("Test was able to read user.name following 2nd refresh!");
        throw new
            Exception("Test was able to read user.name following 2nd refresh!");
    }

}