Java Code Examples for java.lang.reflect.Member#PUBLIC

The following examples show how to use java.lang.reflect.Member#PUBLIC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Class.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void checkMemberAccess(SecurityManager sm, int which,
                               Class<?> caller, boolean checkProxyInterfaces) {
    /* 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);
    if (which != Member.PUBLIC) {
        final ClassLoader cl = getClassLoader0();
        if (ccl != cl) {
            sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
        }
    }
    this.checkPackageAccess(sm, ccl, checkProxyInterfaces);
}
 
Example 2
Source File: Class.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
private void checkMemberAccess(int which, Class<?> caller, boolean checkProxyInterfaces) {
    final SecurityManager s = System.getSecurityManager();
    if (s != null) {
        final ClassLoader ccl = ClassLoader.getClassLoader(caller);
        final ClassLoader cl = getClassLoader0();
        if (!isCheckMemberAccessOverridden(s)) {
            // Inlined SecurityManager.checkMemberAccess
            if (which != Member.PUBLIC) {
                if (ccl != cl) {
                    s.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
                }
            }
        } else {
            // Don't refactor; otherwise break the stack depth for
            // checkMemberAccess of subclasses of SecurityManager as specified.
            s.checkMemberAccess(this, which);
        }
        this.checkPackageAccess(ccl, checkProxyInterfaces);
    }
}
 
Example 3
Source File: Class.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
Source File: Class.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 5
Source File: Class.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 6
Source File: Class.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 7
Source File: Class.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 8
Source File: Class.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 9
Source File: Class.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 10
Source File: Class.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 11
Source File: Class.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private void checkMemberAccess(SecurityManager sm, int which,
                               Class<?> caller, boolean checkProxyInterfaces) {
    /* 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);
    if (which != Member.PUBLIC) {
        final ClassLoader cl = getClassLoader0();
        if (ccl != cl) {
            sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
        }
    }
    this.checkPackageAccess(sm, ccl, checkProxyInterfaces);
}
 
Example 12
Source File: Class.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 13
Source File: Class.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
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);
    }
}
 
Example 14
Source File: Class.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 15
Source File: Class.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 16
Source File: Class.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 17
Source File: Class.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
private Constructor<T> getConstructor0(Class<?>[] parameterTypes,
                                    int which) throws NoSuchMethodException
{
    if (parameterTypes == null) {
        parameterTypes = EmptyArray.CLASS;
    }
    for (Class<?> c : parameterTypes) {
        if (c == null) {
            throw new NoSuchMethodException("parameter type is null");
        }
    }
    Constructor<T> result = getDeclaredConstructorInternal(parameterTypes);
    if (result == null || which == Member.PUBLIC && !Modifier.isPublic(result.getAccessFlags())) {
        throw new NoSuchMethodException(getName() + ".<init> "
                + Arrays.toString(parameterTypes));
    }
    return result;
}
 
Example 18
Source File: Class.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
private Constructor<T> getConstructor0(Class<?>[] parameterTypes,
                                    int which) throws NoSuchMethodException
{
    if (parameterTypes == null) {
        parameterTypes = EmptyArray.CLASS;
    }
    for (Class<?> c : parameterTypes) {
        if (c == null) {
            throw new NoSuchMethodException("parameter type is null");
        }
    }
    Constructor<T> result = getDeclaredConstructorInternal(parameterTypes);
    if (result == null || which == Member.PUBLIC && !Modifier.isPublic(result.getAccessFlags())) {
        throw new NoSuchMethodException("<init> " + Arrays.toString(parameterTypes));
    }
    return result;
}
 
Example 19
Source File: SecurityManager.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Throws a <code>SecurityException</code> if the
 * calling thread is not allowed to access members.
 * <p>
 * The default policy is to allow access to PUBLIC members, as well
 * as access to classes that have the same class loader as the caller.
 * In all other cases, this method calls <code>checkPermission</code>
 * with the <code>RuntimePermission("accessDeclaredMembers")
 * </code> permission.
 * <p>
 * If this method is overridden, then a call to
 * <code>super.checkMemberAccess</code> cannot be made,
 * as the default implementation of <code>checkMemberAccess</code>
 * relies on the code being checked being at a stack depth of
 * 4.
 *
 * @param clazz the class that reflection is to be performed on.
 *
 * @param which type of access, PUBLIC or DECLARED.
 *
 * @exception  SecurityException if the caller does not have
 *             permission to access members.
 * @exception  NullPointerException if the <code>clazz</code> argument is
 *             <code>null</code>.
 *
 * @deprecated This method relies on the caller being at a stack depth
 *             of 4 which is error-prone and cannot be enforced by the runtime.
 *             Users of this method should instead invoke {@link #checkPermission}
 *             directly.
 *             This method is subject to removal in a future version of Java SE.
 *
 * @see java.lang.reflect.Member
 * @since 1.1
 * @see        #checkPermission(java.security.Permission) checkPermission
 */
@Deprecated(since="1.8", forRemoval=true)
@CallerSensitive
public void checkMemberAccess(Class<?> clazz, int which) {
    if (clazz == null) {
        throw new NullPointerException("class can't be null");
    }
    if (which != Member.PUBLIC) {
        Class<?> stack[] = getClassContext();
        /*
         * stack depth of 4 should be the caller of one of the
         * methods in java.lang.Class that invoke checkMember
         * access. The stack should look like:
         *
         * someCaller                        [3]
         * java.lang.Class.someReflectionAPI [2]
         * java.lang.Class.checkMemberAccess [1]
         * SecurityManager.checkMemberAccess [0]
         *
         */
        if ((stack.length<4) ||
            (stack[3].getClassLoader() != clazz.getClassLoader())) {
            checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
        }
    }
}
 
Example 20
Source File: SecurityManager.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
/**
 * Throws a <code>SecurityException</code> if the
 * calling thread is not allowed to access members.
 * <p>
 * The default policy is to allow access to PUBLIC members, as well
 * as access to classes that have the same class loader as the caller.
 * In all other cases, this method calls <code>checkPermission</code>
 * with the <code>RuntimePermission("accessDeclaredMembers")
 * </code> permission.
 * <p>
 * If this method is overridden, then a call to
 * <code>super.checkMemberAccess</code> cannot be made,
 * as the default implementation of <code>checkMemberAccess</code>
 * relies on the code being checked being at a stack depth of
 * 4.
 *
 * @param clazz the class that reflection is to be performed on.
 *
 * @param which type of access, PUBLIC or DECLARED.
 *
 * @exception  SecurityException if the caller does not have
 *             permission to access members.
 * @exception  NullPointerException if the <code>clazz</code> argument is
 *             <code>null</code>.
 * @see java.lang.reflect.Member
 * @since JDK1.1
 * @see        #checkPermission(java.security.Permission) checkPermission
 */
public void checkMemberAccess(Class<?> clazz, int which) {
    if (clazz == null) {
        throw new NullPointerException("class can't be null");
    }
    if (which != Member.PUBLIC) {
        Class stack[] = getClassContext();
        /*
         * stack depth of 4 should be the caller of one of the
         * methods in java.lang.Class that invoke checkMember
         * access. The stack should look like:
         *
         * someCaller                        [3]
         * java.lang.Class.someReflectionAPI [2]
         * java.lang.Class.checkMemberAccess [1]
         * SecurityManager.checkMemberAccess [0]
         *
         */
        if ((stack.length<4) ||
            (stack[3].getClassLoader() != clazz.getClassLoader())) {
            checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
        }
    }
}