下面列出了java.lang.System#getSecurityManager ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}
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!");
}
}