本文整理汇总了Java中java.security.AccessControlException.getPermission方法的典型用法代码示例。如果您正苦于以下问题:Java AccessControlException.getPermission方法的具体用法?Java AccessControlException.getPermission怎么用?Java AccessControlException.getPermission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.AccessControlException
的用法示例。
在下文中一共展示了AccessControlException.getPermission方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkSunClass
import java.security.AccessControlException; //导入方法依赖的package包/类
/**
* Fix for 4179055: Need to assist resolving sun stubs; resolve
* class locally if it is a "permitted" sun class
*/
private Class<?> checkSunClass(String className, AccessControlException e)
throws AccessControlException
{
// ensure that we are giving out a stub for the correct reason
Permission perm = e.getPermission();
String name = null;
if (perm != null) {
name = perm.getName();
}
Class<?> resolvedClass = permittedSunClasses.get(className);
// if class not permitted, throw the SecurityException
if ((name == null) ||
(resolvedClass == null) ||
((!name.equals("accessClassInPackage.sun.rmi.server")) &&
(!name.equals("accessClassInPackage.sun.rmi.registry"))))
{
throw e;
}
return resolvedClass;
}
示例2: testPermission
import java.security.AccessControlException; //导入方法依赖的package包/类
/**
* Test the LoggingPermission("control") is required.
* @param loggerName The logger to use.
*/
public static void testPermission(String loggerName) {
if (System.getSecurityManager() != null) {
throw new Error("Security manager is already set");
}
Policy.setPolicy(new SimplePolicy(TestCase.PERMISSION));
System.setSecurityManager(new SecurityManager());
final ResourceBundle bundle = ResourceBundle.getBundle(LIST_BUNDLE_NAME);
Logger foobar = Logger.getLogger(loggerName);
try {
foobar.setResourceBundle(bundle);
throw new RuntimeException("Permission not checked!");
} catch (AccessControlException x) {
if (x.getPermission() instanceof LoggingPermission) {
if ("control".equals(x.getPermission().getName())) {
System.out.println("Got expected exception: " + x);
return;
}
}
throw new RuntimeException("Unexpected exception: "+x, x);
}
}
示例3: main
import java.security.AccessControlException; //导入方法依赖的package包/类
public static void main (String args[]) throws Exception {
Authenticator defaultAuth = Authenticator.getDefault();
if (defaultAuth != null) {
throw new RuntimeException("Unexpected authenticator: null expected");
}
MyAuthenticator auth = new MyAuthenticator();
Authenticator.setDefault(auth);
defaultAuth = Authenticator.getDefault();
if (defaultAuth != auth) {
throw new RuntimeException("Unexpected authenticator: auth expected");
}
System.setSecurityManager(new SecurityManager());
try {
defaultAuth = Authenticator.getDefault();
throw new RuntimeException("Expected security exception not raised");
} catch (AccessControlException s) {
System.out.println("Got expected exception: " + s);
if (!s.getPermission().equals(new NetPermission("requestPasswordAuthentication"))) {
throw new RuntimeException("Unexpected permission check: " + s.getPermission());
}
}
System.out.println("Test passed with default authenticator "
+ defaultAuth);
}