本文整理匯總了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);
}