當前位置: 首頁>>代碼示例>>Java>>正文


Java AccessControlException.getPermission方法代碼示例

本文整理匯總了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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:MarshalInputStream.java

示例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);
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:TestSetResourceBundle.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:GetAuthenticatorTest.java


注:本文中的java.security.AccessControlException.getPermission方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。