java.net.NetPermission#sun.security.util.SecurityConstants源码实例Demo

下面列出了java.net.NetPermission#sun.security.util.SecurityConstants 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u60   文件: ReflectUtil.java
/**
 * Does a conservative approximation of member access check. Use this if
 * you don't have an actual 'userland' caller Class/ClassLoader available.
 * This might be more restrictive than a precise member access check where
 * you have a caller, but should never allow a member access that is
 * forbidden.
 *
 * @param m the {@code Member} about to be accessed
 */
public static void conservativeCheckMemberAccess(Member m) throws SecurityException{
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;

    // Check for package access on the declaring class.
    //
    // In addition, unless the member and the declaring class are both
    // public check for access declared member permissions.
    //
    // This is done regardless of ClassLoader relations between the {@code
    // Member m} and any potential caller.

    final Class<?> declaringClass = m.getDeclaringClass();

    checkPackageAccess(declaringClass);

    if (Modifier.isPublic(m.getModifiers()) &&
            Modifier.isPublic(declaringClass.getModifiers()))
        return;

    // Check for declared member access.
    sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
 
源代码2 项目: jdk8u-dev-jdk   文件: ReflectUtil.java
/**
 * Does a conservative approximation of member access check. Use this if
 * you don't have an actual 'userland' caller Class/ClassLoader available.
 * This might be more restrictive than a precise member access check where
 * you have a caller, but should never allow a member access that is
 * forbidden.
 *
 * @param m the {@code Member} about to be accessed
 */
public static void conservativeCheckMemberAccess(Member m) throws SecurityException{
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;

    // Check for package access on the declaring class.
    //
    // In addition, unless the member and the declaring class are both
    // public check for access declared member permissions.
    //
    // This is done regardless of ClassLoader relations between the {@code
    // Member m} and any potential caller.

    final Class<?> declaringClass = m.getDeclaringClass();

    checkPackageAccess(declaringClass);

    if (Modifier.isPublic(m.getModifiers()) &&
            Modifier.isPublic(declaringClass.getModifiers()))
        return;

    // Check for declared member access.
    sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
 
源代码3 项目: jdk8u-jdk   文件: UnixFileSystemProvider.java
@Override
public Path readSymbolicLink(Path obj1) throws IOException {
    UnixPath link = UnixPath.toUnixPath(obj1);
    // permission check
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        FilePermission perm = new FilePermission(link.getPathForPermissionCheck(),
            SecurityConstants.FILE_READLINK_ACTION);
        sm.checkPermission(perm);
    }
    try {
        byte[] target = readlink(link);
        return new UnixPath(link.getFileSystem(), target);
    } catch (UnixException x) {
       if (x.errno() == UnixConstants.EINVAL)
            throw new NotLinkException(link.getPathForExceptionMessage());
        x.rethrowAsIOException(link);
        return null;    // keep compiler happy
    }
}
 
源代码4 项目: jdk8u60   文件: PolicyFile.java
/**
 * Creates one of the well-known permissions directly instead of
 * via reflection. Keep list short to not penalize non-JDK-defined
 * permissions.
 */
private static final Permission getKnownInstance(Class<?> claz,
    String name, String actions) {
    if (claz.equals(FilePermission.class)) {
        return new FilePermission(name, actions);
    } else if (claz.equals(SocketPermission.class)) {
        return new SocketPermission(name, actions);
    } else if (claz.equals(RuntimePermission.class)) {
        return new RuntimePermission(name, actions);
    } else if (claz.equals(PropertyPermission.class)) {
        return new PropertyPermission(name, actions);
    } else if (claz.equals(NetPermission.class)) {
        return new NetPermission(name, actions);
    } else if (claz.equals(AllPermission.class)) {
        return SecurityConstants.ALL_PERMISSION;
    } else {
        return null;
    }
}
 
源代码5 项目: Bytecoder   文件: Executors.java
PrivilegedCallableUsingCurrentClassLoader(Callable<T> task) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        // Calls to getContextClassLoader from this class
        // never trigger a security check, but we check
        // whether our callers have this permission anyways.
        sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);

        // Whether setContextClassLoader turns out to be necessary
        // or not, we fail fast if permission is not available.
        sm.checkPermission(new RuntimePermission("setContextClassLoader"));
    }
    this.task = task;
    this.acc = AccessController.getContext();
    this.ccl = Thread.currentThread().getContextClassLoader();
}
 
源代码6 项目: jdk8u-jdk   文件: ReflectUtil.java
/**
 * Does a conservative approximation of member access check. Use this if
 * you don't have an actual 'userland' caller Class/ClassLoader available.
 * This might be more restrictive than a precise member access check where
 * you have a caller, but should never allow a member access that is
 * forbidden.
 *
 * @param m the {@code Member} about to be accessed
 */
public static void conservativeCheckMemberAccess(Member m) throws SecurityException{
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;

    // Check for package access on the declaring class.
    //
    // In addition, unless the member and the declaring class are both
    // public check for access declared member permissions.
    //
    // This is done regardless of ClassLoader relations between the {@code
    // Member m} and any potential caller.

    final Class<?> declaringClass = m.getDeclaringClass();

    checkPackageAccess(declaringClass);

    if (Modifier.isPublic(m.getModifiers()) &&
            Modifier.isPublic(declaringClass.getModifiers()))
        return;

    // Check for declared member access.
    sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
 
源代码7 项目: openjdk-jdk9   文件: ProtectionDomain.java
/**
 * Return true (merge policy permissions) in the following cases:
 *
 * . SecurityManager is null
 *
 * . SecurityManager is not null,
 *          debug is not null,
 *          SecurityManager impelmentation is in bootclasspath,
 *          Policy implementation is in bootclasspath
 *          (the bootclasspath restrictions avoid recursion)
 *
 * . SecurityManager is not null,
 *          debug is null,
 *          caller has Policy.getPolicy permission
 */
private static boolean seeAllp() {
    SecurityManager sm = System.getSecurityManager();

    if (sm == null) {
        return true;
    } else {
        if (DebugHolder.debug != null) {
            if (sm.getClass().getClassLoader() == null &&
                Policy.getPolicyNoCheck().getClass().getClassLoader()
                                                            == null) {
                return true;
            }
        } else {
            try {
                sm.checkPermission(SecurityConstants.GET_POLICY_PERMISSION);
                return true;
            } catch (SecurityException se) {
                // fall thru and return false
            }
        }
    }

    return false;
}
 
源代码8 项目: openjdk-jdk8u-backup   文件: MethodHandles.java
/**
 * Perform necessary <a href="MethodHandles.Lookup.html#secmgr">access checks</a>.
 * Determines a trustable caller class to compare with refc, the symbolic reference class.
 * If this lookup object has private access, then the caller class is the lookupClass.
 */
void checkSecurityManager(Class<?> refc, MemberName m) {
    SecurityManager smgr = System.getSecurityManager();
    if (smgr == null)  return;
    if (allowedModes == TRUSTED)  return;

    // Step 1:
    boolean fullPowerLookup = hasPrivateAccess();
    if (!fullPowerLookup ||
        !VerifyAccess.classLoaderIsAncestor(lookupClass, refc)) {
        ReflectUtil.checkPackageAccess(refc);
    }

    // Step 2:
    if (m.isPublic()) return;
    if (!fullPowerLookup) {
        smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
    }

    // Step 3:
    Class<?> defc = m.getDeclaringClass();
    if (!fullPowerLookup && defc != refc) {
        ReflectUtil.checkPackageAccess(defc);
    }
}
 
源代码9 项目: JDKSourceCode1.8   文件: Window.java
private void setWarningString() {
    warningString = null;
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        try {
            sm.checkPermission(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION);
        } catch (SecurityException se) {
            // make sure the privileged action is only
            // for getting the property! We don't want the
            // above checkPermission call to always succeed!
            warningString = AccessController.doPrivileged(
                  new GetPropertyAction("awt.appletWarning",
                                        "Java Applet Window"));
        }
    }
}
 
源代码10 项目: JDKSourceCode1.8   文件: Class.java
private void checkMemberAccess(int which, Class<?> caller, boolean checkProxyInterfaces) {
    final SecurityManager s = System.getSecurityManager();
    if (s != null) {
        /* Default policy allows access to all {@link Member#PUBLIC} members,
         * as well as access to classes that have the same class loader as the caller.
         * In all other cases, it requires RuntimePermission("accessDeclaredMembers")
         * permission.
         */
        final ClassLoader ccl = ClassLoader.getClassLoader(caller);
        final ClassLoader cl = getClassLoader0();
        if (which != Member.PUBLIC) {
            if (ccl != cl) {
                s.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
            }
        }
        this.checkPackageAccess(ccl, checkProxyInterfaces);
    }
}
 
源代码11 项目: jdk8u-jdk   文件: InputEvent.java
private boolean canAccessSystemClipboard() {
    boolean b = false;

    if (!GraphicsEnvironment.isHeadless()) {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            try {
                sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
                b = true;
            } catch (SecurityException se) {
                if (logger.isLoggable(PlatformLogger.Level.FINE)) {
                    logger.fine("InputEvent.canAccessSystemClipboard() got SecurityException ", se);
                }
            }
        } else {
            b = true;
        }
    }

    return b;
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: SwingUtilities2.java
/**
 * checks the security permissions for accessing system clipboard
 *
 * for untrusted context (see isTrustedContext) checks the
 * permissions for the current event being handled
 *
 */
public static boolean canAccessSystemClipboard() {
    boolean canAccess = false;
    if (!GraphicsEnvironment.isHeadless()) {
        SecurityManager sm = System.getSecurityManager();
        if (sm == null) {
            canAccess = true;
        } else {
            try {
                sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
                canAccess = true;
            } catch (SecurityException e) {
            }
            if (canAccess && ! isTrustedContext()) {
                canAccess = canCurrentEventAccessSystemClipboard(true);
            }
        }
    }
    return canAccess;
}
 
源代码13 项目: TencentKona-8   文件: PolicyFile.java
/**
 * Creates one of the well-known permissions directly instead of
 * via reflection. Keep list short to not penalize non-JDK-defined
 * permissions.
 */
private static final Permission getKnownInstance(Class<?> claz,
    String name, String actions) {
    if (claz.equals(FilePermission.class)) {
        return new FilePermission(name, actions);
    } else if (claz.equals(SocketPermission.class)) {
        return new SocketPermission(name, actions);
    } else if (claz.equals(RuntimePermission.class)) {
        return new RuntimePermission(name, actions);
    } else if (claz.equals(PropertyPermission.class)) {
        return new PropertyPermission(name, actions);
    } else if (claz.equals(NetPermission.class)) {
        return new NetPermission(name, actions);
    } else if (claz.equals(AllPermission.class)) {
        return SecurityConstants.ALL_PERMISSION;
    } else {
        return null;
    }
}
 
源代码14 项目: dragonwell8_jdk   文件: ReflectUtil.java
/**
 * Does a conservative approximation of member access check. Use this if
 * you don't have an actual 'userland' caller Class/ClassLoader available.
 * This might be more restrictive than a precise member access check where
 * you have a caller, but should never allow a member access that is
 * forbidden.
 *
 * @param m the {@code Member} about to be accessed
 */
public static void conservativeCheckMemberAccess(Member m) throws SecurityException{
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;

    // Check for package access on the declaring class.
    //
    // In addition, unless the member and the declaring class are both
    // public check for access declared member permissions.
    //
    // This is done regardless of ClassLoader relations between the {@code
    // Member m} and any potential caller.

    final Class<?> declaringClass = m.getDeclaringClass();

    checkPackageAccess(declaringClass);

    if (Modifier.isPublic(m.getModifiers()) &&
            Modifier.isPublic(declaringClass.getModifiers()))
        return;

    // Check for declared member access.
    sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
 
源代码15 项目: openjdk-jdk9   文件: Executors.java
PrivilegedCallableUsingCurrentClassLoader(Callable<T> task) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        // Calls to getContextClassLoader from this class
        // never trigger a security check, but we check
        // whether our callers have this permission anyways.
        sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);

        // Whether setContextClassLoader turns out to be necessary
        // or not, we fail fast if permission is not available.
        sm.checkPermission(new RuntimePermission("setContextClassLoader"));
    }
    this.task = task;
    this.acc = AccessController.getContext();
    this.ccl = Thread.currentThread().getContextClassLoader();
}
 
源代码16 项目: openjdk-8-source   文件: PolicyFile.java
/**
 * Creates one of the well-known permissions directly instead of
 * via reflection. Keep list short to not penalize non-JDK-defined
 * permissions.
 */
private static final Permission getKnownInstance(Class<?> claz,
    String name, String actions) {
    if (claz.equals(FilePermission.class)) {
        return new FilePermission(name, actions);
    } else if (claz.equals(SocketPermission.class)) {
        return new SocketPermission(name, actions);
    } else if (claz.equals(RuntimePermission.class)) {
        return new RuntimePermission(name, actions);
    } else if (claz.equals(PropertyPermission.class)) {
        return new PropertyPermission(name, actions);
    } else if (claz.equals(NetPermission.class)) {
        return new NetPermission(name, actions);
    } else if (claz.equals(AllPermission.class)) {
        return SecurityConstants.ALL_PERMISSION;
    } else {
        return null;
    }
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: AppletSecurity.java
/**
 * Applets are not allowed to manipulate threads outside
 * applet thread groups. However a terminated thread no longer belongs
 * to any group.
 */
public void checkAccess(Thread t) {
    /* When multiple applets is reloaded simultaneously, there will be
     * multiple invocations to this method from plugin's SecurityManager.
     * This method should not be synchronized to avoid deadlock when
     * a page with multiple applets is reloaded
     */
    if ((t.getState() != Thread.State.TERMINATED) && !inThreadGroup(t)) {
        checkPermission(SecurityConstants.MODIFY_THREAD_PERMISSION);
    }
}
 
源代码18 项目: JDKSourceCode1.8   文件: Proxy.java
private static void checkProxyAccess(Class<?> caller,
                                     ClassLoader loader,
                                     Class<?>... interfaces)
{
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        ClassLoader ccl = caller.getClassLoader();
        if (VM.isSystemDomainLoader(loader) && !VM.isSystemDomainLoader(ccl)) {
            sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
        }
        ReflectUtil.checkProxyPackageAccess(ccl, interfaces);
    }
}
 
源代码19 项目: hottub   文件: AppletSecurity.java
/**
 * Tests if a client can get access to the AWT event queue.
 * <p>
 * This method calls <code>checkPermission</code> with the
 * <code>AWTPermission("accessEventQueue")</code> permission.
 *
 * @since   JDK1.1
 * @exception  SecurityException  if the caller does not have
 *             permission to access the AWT event queue.
 */
public void checkAwtEventQueueAccess() {
    AppContext appContext = AppContext.getAppContext();
    AppletClassLoader appletClassLoader = currentAppletClassLoader();

    if (AppContext.isMainContext(appContext) && (appletClassLoader != null)) {
        // If we're about to allow access to the main EventQueue,
        // and anything untrusted is on the class context stack,
        // disallow access.
        super.checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION);
    }
}
 
源代码20 项目: jdk1.8-source-analysis   文件: MouseInfo.java
/**
 * Returns a <code>PointerInfo</code> instance that represents the current
 * location of the mouse pointer.
 * The <code>GraphicsDevice</code> stored in this <code>PointerInfo</code>
 * contains the mouse pointer. The coordinate system used for the mouse position
 * depends on whether or not the <code>GraphicsDevice</code> is part of a virtual
 * screen device.
 * For virtual screen devices, the coordinates are given in the virtual
 * coordinate system, otherwise they are returned in the coordinate system
 * of the <code>GraphicsDevice</code>. See {@link GraphicsConfiguration}
 * for more information about the virtual screen devices.
 * On systems without a mouse, returns <code>null</code>.
 * <p>
 * If there is a security manager, its <code>checkPermission</code> method
 * is called with an <code>AWTPermission("watchMousePointer")</code>
 * permission before creating and returning a <code>PointerInfo</code>
 * object. This may result in a <code>SecurityException</code>.
 *
 * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
 * @exception SecurityException if a security manager exists and its
 *            <code>checkPermission</code> method doesn't allow the operation
 * @see       GraphicsConfiguration
 * @see       SecurityManager#checkPermission
 * @see       java.awt.AWTPermission
 * @return    location of the mouse pointer
 * @since     1.5
 */
public static PointerInfo getPointerInfo() throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.WATCH_MOUSE_PERMISSION);
    }

    Point point = new Point(0, 0);
    int deviceNum = Toolkit.getDefaultToolkit().getMouseInfoPeer().fillPointWithCoords(point);
    GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().
                               getScreenDevices();
    PointerInfo retval = null;
    if (areScreenDevicesIndependent(gds)) {
        retval = new PointerInfo(gds[deviceNum], point);
    } else {
        for (int i = 0; i < gds.length; i++) {
            GraphicsConfiguration gc = gds[i].getDefaultConfiguration();
            Rectangle bounds = gc.getBounds();
            if (bounds.contains(point)) {
                retval = new PointerInfo(gds[i], point);
            }
        }
    }

    return retval;
}
 
源代码21 项目: openjdk-8   文件: System.java
private static synchronized
void setSecurityManager0(final SecurityManager s) {
    SecurityManager sm = getSecurityManager();
    if (sm != null) {
        // ask the currently installed security manager if we
        // can replace it.
        sm.checkPermission(new RuntimePermission
                                 ("setSecurityManager"));
    }

    if ((s != null) && (s.getClass().getClassLoader() != null)) {
        // New security manager class is not on bootstrap classpath.
        // Cause policy to get initialized before we install the new
        // security manager, in order to prevent infinite loops when
        // trying to initialize the policy (which usually involves
        // accessing some security and/or system properties, which in turn
        // calls the installed security manager's checkPermission method
        // which will loop infinitely if there is a non-system class
        // (in this case: the new security manager class) on the stack).
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                s.getClass().getProtectionDomain().implies
                    (SecurityConstants.ALL_PERMISSION);
                return null;
            }
        });
    }

    security = s;
}
 
源代码22 项目: openjdk-jdk8u   文件: WToolkit.java
@Override
public Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new WClipboard();
        }
    }
    return clipboard;
}
 
源代码23 项目: openjdk-8-source   文件: SecurityManager.java
/**
 * returns true if the current context has been granted AllPermission
 */
private boolean hasAllPermission()
{
    try {
        checkPermission(SecurityConstants.ALL_PERMISSION);
        return true;
    } catch (SecurityException se) {
        return false;
    }
}
 
源代码24 项目: jdk8u_jdk   文件: SunToolkit.java
/**
 * Returns whether popup is allowed to be shown above the task bar.
 * This is a default implementation of this method, which checks
 * corresponding security permission.
 */
public boolean canPopupOverlapTaskBar() {
    boolean result = true;
    try {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(
                    SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
        }
    } catch (SecurityException se) {
        // There is no permission to show popups over the task bar
        result = false;
    }
    return result;
}
 
源代码25 项目: openjdk-jdk8u   文件: ServerSocket.java
private static Void checkPermission() {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(SecurityConstants.SET_SOCKETIMPL_PERMISSION);
    }
    return null;
}
 
源代码26 项目: jdk8u_jdk   文件: WToolkit.java
@Override
public Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new WClipboard();
        }
    }
    return clipboard;
}
 
源代码27 项目: openjdk-8   文件: XToolkit.java
public  Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new XClipboard("System", "CLIPBOARD");
        }
    }
    return clipboard;
}
 
源代码28 项目: openjdk-8-source   文件: Dialog.java
private void checkModalityPermission(ModalityType mt) {
    if (mt == ModalityType.TOOLKIT_MODAL) {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(
                SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION
            );
        }
    }
}
 
源代码29 项目: jdk8u_jdk   文件: Robot.java
private static void checkScreenCaptureAllowed() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(
            SecurityConstants.AWT.READ_DISPLAY_PIXELS_PERMISSION);
    }
}
 
源代码30 项目: jdk8u-dev-jdk   文件: XToolkit.java
public  Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new XClipboard("System", "CLIPBOARD");
        }
    }
    return clipboard;
}