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


Java Permission類代碼示例

本文整理匯總了Java中java.security.Permission的典型用法代碼示例。如果您正苦於以下問題:Java Permission類的具體用法?Java Permission怎麽用?Java Permission使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Permission類屬於java.security包,在下文中一共展示了Permission類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findClass

import java.security.Permission; //導入依賴的package包/類
static Class<?> findClass(Module module, String cn, Permission perm) {
    try {
        Class<?> c = Class.forName(module, cn);
        if (c == null) {
            throw new RuntimeException(cn + " not found in " + module);
        }
        if (c.getModule() != module) {
            throw new RuntimeException(c.getModule() + " != " + module);
        }
        return c;
    } catch (AccessControlException e) {
        if (e.getPermission().equals(perm))
            return null;
        throw e;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:NoAccess.java

示例2: main

import java.security.Permission; //導入依賴的package包/類
public static void main(String[] args) throws JAXBException {
    System.out.println("\nWithout security manager\n");
    test(FactoryBase.class);
    test(Factory1.class);
    test(Factory2.class);

    System.out.println("\nWith security manager\n");
    Policy.setPolicy(new Policy() {
        @Override
        public boolean implies(ProtectionDomain domain, Permission permission) {
            return true; // allow all
        }
    });
    System.setSecurityManager(new SecurityManager());
    test(FactoryBase.class);
    test(Factory1.class);
    test(Factory2.class);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:JAXBContextWithSubclassedFactory.java

示例3: checkSunClass

import java.security.Permission; //導入依賴的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

示例4: getPermissions

import java.security.Permission; //導入依賴的package包/類
/**
 * Get the Permissions for a CodeSource.  If this instance
 * of WebappClassLoaderBase is for a web application context,
 * add read FilePermission or JndiPermissions for the base
 * directory (if unpacked),
 * the context URL, and jar file resources.
 *
 * @param codeSource where the code was loaded from
 * @return PermissionCollection for CodeSource
 */
@Override
protected PermissionCollection getPermissions(CodeSource codeSource) {

    String codeUrl = codeSource.getLocation().toString();
    PermissionCollection pc;
    if ((pc = loaderPC.get(codeUrl)) == null) {
        pc = super.getPermissions(codeSource);
        if (pc != null) {
            Iterator<Permission> perms = permissionList.iterator();
            while (perms.hasNext()) {
                Permission p = perms.next();
                pc.add(p);
            }
            loaderPC.put(codeUrl,pc);
        }
    }
    return (pc);

}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:30,代碼來源:WebappClassLoaderBase.java

示例5: test

import java.security.Permission; //導入依賴的package包/類
public static void test(Permission perm, boolean expectException) {
    boolean getException = (Boolean) AccessController.doPrivileged((PrivilegedAction) () -> {
        try {
            AccessController.checkPermission(perm);
            return (Boolean) false;
        } catch (AccessControlException ex) {
            return (Boolean) true;
        }
    });

    if (expectException ^ getException) {
        String message = "Check Permission :" + perm + "\n ExpectException = "
                + expectException + "\n getException = " + getException;
        throw new RuntimeException(message);
    }

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

示例6: checkMBeanTrustPermission

import java.security.Permission; //導入依賴的package包/類
private static void checkMBeanTrustPermission(final Class<?> theClass)
    throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanTrustPermission("register");
        PrivilegedAction<ProtectionDomain> act =
            new PrivilegedAction<ProtectionDomain>() {
                public ProtectionDomain run() {
                    return theClass.getProtectionDomain();
                }
            };
        ProtectionDomain pd = AccessController.doPrivileged(act);
        AccessControlContext acc =
            new AccessControlContext(new ProtectionDomain[] { pd });
        sm.checkPermission(perm, acc);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:DefaultMBeanServerInterceptor.java

示例7: checkRemoveCallerContext

import java.security.Permission; //導入依賴的package包/類
/**
 * Check if the connector server creator can assume the identity of each
 * principal in the authenticated subject, i.e. check if the connector
 * server creator codebase contains a subject delegation permission for
 * each principal present in the authenticated subject.
 *
 * @return {@code true} if the connector server creator can delegate to all
 * the authenticated principals in the subject. Otherwise, {@code false}.
 */
public static synchronized boolean
    checkRemoveCallerContext(Subject subject) {
    try {
        for (Principal p : getSubjectPrincipals(subject)) {
            final String pname =
                p.getClass().getName() + "." + p.getName();
            final Permission sdp =
                new SubjectDelegationPermission(pname);
            AccessController.checkPermission(sdp);
        }
    } catch (SecurityException e) {
        return false;
    }
    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:SubjectDelegator.java

示例8: checkPermission

import java.security.Permission; //導入依賴的package包/類
private void checkPermission(Permission perm, boolean expectException) {
    boolean getException = (Boolean) AccessController
            .doPrivileged((PrivilegedAction) () -> {
        try {
            AccessController.checkPermission(perm);
            return (Boolean) false;
        } catch (AccessControlException ex) {
            return (Boolean) true;
        }
    });

    if (expectException ^ getException) {
        String message = "Check Permission :" + perm + "\n ExpectException = "
                + expectException + "\n getException = " + getException;
        throw new RuntimeException(message);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:Version.java

示例9: checkPermission

import java.security.Permission; //導入依賴的package包/類
/**
 * {@inheritDoc}
 *
 * @see java.lang.SecurityManager#checkPermission(java.security.Permission)
 */
@Override
public void checkPermission ( Permission perm ) {

    if ( perm instanceof RuntimePermission ) {
        return;
    }

    Set<URL> cbs = new HashSet<>();
    for ( Class<?> cl : getClassContext() ) {
        if ( cl.getProtectionDomain() != null && cl.getProtectionDomain().getCodeSource() != null
                && cl.getProtectionDomain().getCodeSource().getLocation() != null
                && !"file".equals(cl.getProtectionDomain().getCodeSource().getLocation().getProtocol()) ) {
            cbs.add(cl.getProtectionDomain().getCodeSource().getLocation());
        }
    }

    this.remoteCodebases.addAll(cbs);
}
 
開發者ID:mbechler,項目名稱:marshalsec,代碼行數:24,代碼來源:TestingSecurityManager.java

示例10: implies

import java.security.Permission; //導入依賴的package包/類
/**
 * Check and see if this collection of permissions implies the permissions
 * expressed in "permission".
 *
 * @param permission the Permission object to compare
 *
 * @return true if "permission" is a proper subset of a permission in
 * the collection, false if not.
 */

public boolean implies(Permission permission)
{
    if (! (permission instanceof SocketPermission))
            return false;

    SocketPermission np = (SocketPermission) permission;

    int desired = np.getMask();
    int effective = 0;
    int needed = desired;

    synchronized (this) {
        int len = perms.size();
        //System.out.println("implies "+np);
        for (int i = 0; i < len; i++) {
            SocketPermission x = perms.get(i);
            //System.out.println("  trying "+x);
            if (((needed & x.getMask()) != 0) && x.impliesIgnoreMask(np)) {
                effective |=  x.getMask();
                if ((effective & desired) == desired)
                    return true;
                needed = (desired ^ effective);
            }
        }
    }
    return false;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:SocketPermission.java

示例11: getPermission

import java.security.Permission; //導入依賴的package包/類
@Override public Permission getPermission() throws IOException {
  URL url = getURL();
  String hostname = url.getHost();
  int hostPort = url.getPort() != -1
      ? url.getPort()
      : HttpUrl.defaultPort(url.getProtocol());
  if (usingProxy()) {
    InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address();
    hostname = proxyAddress.getHostName();
    hostPort = proxyAddress.getPort();
  }
  return new SocketPermission(hostname + ":" + hostPort, "connect, resolve");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:OkHttpURLConnection.java

示例12: getClassLoader

import java.security.Permission; //導入依賴的package包/類
public final ClassLoader getClassLoader(ObjectName name) {
    ClassLoader instance = loadersWithNames.get(name);
    if (instance != null) {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            Permission perm =
                    new MBeanPermission(instance.getClass().getName(),
                    null,
                    name,
                    "getClassLoader");
            sm.checkPermission(perm);
        }
    }
    return instance;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ClassLoaderRepositorySupport.java

示例13: elements

import java.security.Permission; //導入依賴的package包/類
public java.util.Enumeration<Permission> elements() {
    if (perms == null)
        init();
    synchronized (perms) {
        return perms.elements();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:Launcher.java

示例14: getConnectPermission

import java.security.Permission; //導入依賴的package包/類
public static Permission getConnectPermission(URL url) throws IOException {
    String urlStringLowerCase = url.toString().toLowerCase();
    if (urlStringLowerCase.startsWith("http:") || urlStringLowerCase.startsWith("https:")) {
        return getURLConnectPermission(url);
    } else if (urlStringLowerCase.startsWith("jar:http:") || urlStringLowerCase.startsWith("jar:https:")) {
        String urlString = url.toString();
        int bangPos = urlString.indexOf("!/");
        urlString = urlString.substring(4, bangPos > -1 ? bangPos : urlString.length());
        URL u = new URL(urlString);
        return getURLConnectPermission(u);
        // If protocol is HTTP or HTTPS than use URLPermission object
    } else {
        return url.openConnection().getPermission();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:16,代碼來源:URLUtil.java

示例15: checkPermission

import java.security.Permission; //導入依賴的package包/類
private static void checkPermission(String action)
throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanServerPermission(action);
        sm.checkPermission(perm);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:MBeanServerFactory.java


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