Java Tutorial/Security/GuardedObject

Материал из Java эксперт
Перейти к: навигация, поиск

Guard guard = new PropertyPermission(java.home, read);

import java.security.AccessControlException;
import java.security.Guard;
import java.security.GuardedObject;
import java.util.PropertyPermission;
public class Main {
  public static void main(String[] argv) throws Exception {
    String secretObj = "secret";
    Guard guard = new PropertyPermission("java.home", "read");
    GuardedObject gobj = new GuardedObject(secretObj, guard);
    try {
      Object o = gobj.getObject();
    } catch (AccessControlException e) {
      e.printStackTrace();
    }
  }
}





new GuardedObject(Object obj, Guard)

import java.security.AccessControlException;
import java.security.Guard;
import java.security.GuardedObject;
import java.util.PropertyPermission;
public class Main {
  public static void main(String[] argv) throws Exception {
    String secretObj = "secret";
    Guard guard = new PropertyPermission("java.home", "read");
    GuardedObject gobj = new GuardedObject(secretObj, guard);
    try {
      Object o = gobj.getObject();
    } catch (AccessControlException e) {
      e.printStackTrace();
    }
  }
}





Object GuardedObject.getObject()

import java.security.AccessControlException;
import java.security.Guard;
import java.security.GuardedObject;
import java.util.PropertyPermission;
public class Main {
  public static void main(String[] argv) throws Exception {
    String secretObj = "secret";
    Guard guard = new PropertyPermission("java.home", "read");
    GuardedObject gobj = new GuardedObject(secretObj, guard);
    try {
      Object o = gobj.getObject();
    } catch (AccessControlException e) {
      e.printStackTrace();
    }
  }
}