Code example for AccessControlException

0
  public static Subject getSubject()
  { 
    AccessControlContext context = AccessController.getContext();
    Subject subject = Subject.getSubject(context);
    if (subject == null)
      throw new AccessControlException("Denied");
    return subject;
  } 
 
  public static Set<Principal> getPrincipals()
  { 
    return getSubject().getPrincipals();
  } 
 
  public static Set<Principal> getPrincipals(Class<Principal> c)
  { 
    Subject subject = getSubject();
    return subject.getPrincipals(c);
  }