sun.invoke.util.VerifyAccess Java Examples

The following examples show how to use sun.invoke.util.VerifyAccess. 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: InvokerBytecodeGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example #2
Source File: InvokerBytecodeGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example #3
Source File: MethodHandles.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
String accessFailedMessage(Class<?> refc, MemberName m) {
    Class<?> defc = m.getDeclaringClass();
    int mods = m.getModifiers();
    // check the class first:
    boolean classOK = (Modifier.isPublic(defc.getModifiers()) &&
                       (defc == refc ||
                        Modifier.isPublic(refc.getModifiers())));
    if (!classOK && (allowedModes & PACKAGE) != 0) {
        classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), ALL_MODES) &&
                   (defc == refc ||
                    VerifyAccess.isClassAccessible(refc, lookupClass(), ALL_MODES)));
    }
    if (!classOK)
        return "class is not public";
    if (Modifier.isPublic(mods))
        return "access to public member failed";  // (how?)
    if (Modifier.isPrivate(mods))
        return "member is private";
    if (Modifier.isProtected(mods))
        return "member is protected";
    return "member is private to package";
}
 
Example #4
Source File: MethodHandles.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #5
Source File: InvokerBytecodeGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #6
Source File: MethodHandles.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
String accessFailedMessage(Class<?> refc, MemberName m) {
    Class<?> defc = m.getDeclaringClass();
    int mods = m.getModifiers();
    // check the class first:
    boolean classOK = (Modifier.isPublic(defc.getModifiers()) &&
                       (defc == refc ||
                        Modifier.isPublic(refc.getModifiers())));
    if (!classOK && (allowedModes & PACKAGE) != 0) {
        classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), ALL_MODES) &&
                   (defc == refc ||
                    VerifyAccess.isClassAccessible(refc, lookupClass(), ALL_MODES)));
    }
    if (!classOK)
        return "class is not public";
    if (Modifier.isPublic(mods))
        return "access to public member failed";  // (how?)
    if (Modifier.isPrivate(mods))
        return "member is private";
    if (Modifier.isProtected(mods))
        return "member is protected";
    return "member is private to package";
}
 
Example #7
Source File: InvokerBytecodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #8
Source File: MethodHandles.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
String accessFailedMessage(Class<?> refc, Class<?> defc, int mods) {
    // check the class first:
    boolean classOK = (Modifier.isPublic(defc.getModifiers()) &&
            (defc == refc ||
                    Modifier.isPublic(refc.getModifiers())));
    if (!classOK && (allowedModes & PACKAGE) != 0) {
        classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), ALL_MODES) &&
                (defc == refc ||
                        VerifyAccess.isClassAccessible(refc, lookupClass(), ALL_MODES)));
    }
    if (!classOK)
        return "class is not public";
    if (Modifier.isPublic(mods))
        return "access to public member failed";  // (how?)
    if (Modifier.isPrivate(mods))
        return "member is private";
    if (Modifier.isProtected(mods))
        return "member is protected";
    return "member is private to package";
}
 
Example #9
Source File: InvokerBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #10
Source File: InvokerBytecodeGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example #11
Source File: MethodHandles.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #12
Source File: MethodHandles.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #13
Source File: MethodHandles.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
String accessFailedMessage(Class<?> refc, MemberName m) {
    Class<?> defc = m.getDeclaringClass();
    int mods = m.getModifiers();
    // check the class first:
    boolean classOK = (Modifier.isPublic(defc.getModifiers()) &&
                       (defc == refc ||
                        Modifier.isPublic(refc.getModifiers())));
    if (!classOK && (allowedModes & PACKAGE) != 0) {
        classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), ALL_MODES) &&
                   (defc == refc ||
                    VerifyAccess.isClassAccessible(refc, lookupClass(), ALL_MODES)));
    }
    if (!classOK)
        return "class is not public";
    if (Modifier.isPublic(mods))
        return "access to public member failed";  // (how?)
    if (Modifier.isPrivate(mods))
        return "member is private";
    if (Modifier.isProtected(mods))
        return "member is protected";
    return "member is private to package";
}
 
Example #14
Source File: MethodHandles.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
String accessFailedMessage(Class<?> refc, MemberName m) {
    Class<?> defc = m.getDeclaringClass();
    int mods = m.getModifiers();
    // check the class first:
    boolean classOK = (Modifier.isPublic(defc.getModifiers()) &&
                       (defc == refc ||
                        Modifier.isPublic(refc.getModifiers())));
    if (!classOK && (allowedModes & PACKAGE) != 0) {
        classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), ALL_MODES) &&
                   (defc == refc ||
                    VerifyAccess.isClassAccessible(refc, lookupClass(), ALL_MODES)));
    }
    if (!classOK)
        return "class is not public";
    if (Modifier.isPublic(mods))
        return "access to public member failed";  // (how?)
    if (Modifier.isPrivate(mods))
        return "member is private";
    if (Modifier.isProtected(mods))
        return "member is protected";
    return "member is private to package";
}
 
Example #15
Source File: InvokerBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #16
Source File: InvokerBytecodeGenerator.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example #17
Source File: MethodHandles.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a lookup on the specified new lookup class.
 * The resulting object will report the specified
 * class as its own {@link #lookupClass lookupClass}.
 * <p>
 * However, the resulting {@code Lookup} object is guaranteed
 * to have no more access capabilities than the original.
 * In particular, access capabilities can be lost as follows:<ul>
 * <li>If the new lookup class differs from the old one,
 * protected members will not be accessible by virtue of inheritance.
 * (Protected members may continue to be accessible because of package sharing.)
 * <li>If the new lookup class is in a different package
 * than the old one, protected and default (package) members will not be accessible.
 * <li>If the new lookup class is not within the same package member
 * as the old one, private members will not be accessible.
 * <li>If the new lookup class is not accessible to the old lookup class,
 * then no members, not even public members, will be accessible.
 * (In all other cases, public members will continue to be accessible.)
 * </ul>
 *
 * @param requestedLookupClass the desired lookup class for the new lookup object
 * @return a lookup object which reports the desired lookup class
 * @throws NullPointerException if the argument is null
 */
public Lookup in(Class<?> requestedLookupClass) {
    requestedLookupClass.getClass();  // null check
    if (allowedModes == TRUSTED)  // IMPL_LOOKUP can make any lookup at all
        return new Lookup(requestedLookupClass, ALL_MODES);
    if (requestedLookupClass == this.lookupClass)
        return this;  // keep same capabilities
    int newModes = (allowedModes & (ALL_MODES & ~PROTECTED));
    if ((newModes & PACKAGE) != 0
        && !VerifyAccess.isSamePackage(this.lookupClass, requestedLookupClass)) {
        newModes &= ~(PACKAGE|PRIVATE);
    }
    // Allow nestmate lookups to be created without special privilege:
    if ((newModes & PRIVATE) != 0
        && !VerifyAccess.isSamePackageMember(this.lookupClass, requestedLookupClass)) {
        newModes &= ~PRIVATE;
    }
    if ((newModes & PUBLIC) != 0
        && !VerifyAccess.isClassAccessible(requestedLookupClass, this.lookupClass, allowedModes)) {
        // The requested class it not accessible from the lookup class.
        // No permissions.
        newModes = 0;
    }
    checkUnprivilegedlookupClass(requestedLookupClass, newModes);
    return new Lookup(requestedLookupClass, newModes);
}
 
Example #18
Source File: MethodHandles.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #19
Source File: InvokerBytecodeGenerator.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #20
Source File: MethodHandles.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a lookup on the specified new lookup class.
 * The resulting object will report the specified
 * class as its own {@link #lookupClass lookupClass}.
 * <p>
 * However, the resulting {@code Lookup} object is guaranteed
 * to have no more access capabilities than the original.
 * In particular, access capabilities can be lost as follows:<ul>
 * <li>If the new lookup class differs from the old one,
 * protected members will not be accessible by virtue of inheritance.
 * (Protected members may continue to be accessible because of package sharing.)
 * <li>If the new lookup class is in a different package
 * than the old one, protected and default (package) members will not be accessible.
 * <li>If the new lookup class is not within the same package member
 * as the old one, private members will not be accessible.
 * <li>If the new lookup class is not accessible to the old lookup class,
 * then no members, not even public members, will be accessible.
 * (In all other cases, public members will continue to be accessible.)
 * </ul>
 *
 * @param requestedLookupClass the desired lookup class for the new lookup object
 * @return a lookup object which reports the desired lookup class
 * @throws NullPointerException if the argument is null
 */
public Lookup in(Class<?> requestedLookupClass) {
    requestedLookupClass.getClass();  // null check
    if (allowedModes == TRUSTED)  // IMPL_LOOKUP can make any lookup at all
        return new Lookup(requestedLookupClass, ALL_MODES);
    if (requestedLookupClass == this.lookupClass)
        return this;  // keep same capabilities
    int newModes = (allowedModes & (ALL_MODES & ~PROTECTED));
    if ((newModes & PACKAGE) != 0
        && !VerifyAccess.isSamePackage(this.lookupClass, requestedLookupClass)) {
        newModes &= ~(PACKAGE|PRIVATE);
    }
    // Allow nestmate lookups to be created without special privilege:
    if ((newModes & PRIVATE) != 0
        && !VerifyAccess.isSamePackageMember(this.lookupClass, requestedLookupClass)) {
        newModes &= ~PRIVATE;
    }
    if ((newModes & PUBLIC) != 0
        && !VerifyAccess.isClassAccessible(requestedLookupClass, this.lookupClass, allowedModes)) {
        // The requested class it not accessible from the lookup class.
        // No permissions.
        newModes = 0;
    }
    checkUnprivilegedlookupClass(requestedLookupClass, newModes);
    return new Lookup(requestedLookupClass, newModes);
}
 
Example #21
Source File: InvokerBytecodeGenerator.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #22
Source File: InvokerBytecodeGenerator.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example #23
Source File: InvokerBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #24
Source File: InvokerBytecodeGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example #25
Source File: InvokerBytecodeGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #26
Source File: MethodHandles.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #27
Source File: InvokerBytecodeGenerator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyNameable(Class<?> cls) {
    if (cls == Object.class)
        return true;
    while (cls.isArray())
        cls = cls.getComponentType();
    if (cls.isPrimitive())
        return true;  // int[].class, for example
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    // could use VerifyAccess.isClassAccessible but the following is a safe approximation
    if (cls.getClassLoader() != Object.class.getClassLoader())
        return false;
    if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;
    if (!Modifier.isPublic(cls.getModifiers()))
        return false;
    for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
        if (VerifyAccess.isSamePackage(pkgcls, cls))
            return true;
    }
    return false;
}
 
Example #28
Source File: MethodHandles.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #29
Source File: InvokerBytecodeGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static boolean isStaticallyInvocable(MemberName member) {
    if (member == null)  return false;
    if (member.isConstructor())  return false;
    Class<?> cls = member.getDeclaringClass();
    if (cls.isArray() || cls.isPrimitive())
        return false;  // FIXME
    if (cls.isAnonymousClass() || cls.isLocalClass())
        return false;  // inner class of some sort
    if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
        return false;  // not on BCP
    if (ReflectUtil.isVMAnonymousClass(cls)) // FIXME: switch to supported API once it is added
        return false;
    MethodType mtype = member.getMethodOrFieldType();
    if (!isStaticallyNameable(mtype.returnType()))
        return false;
    for (Class<?> ptype : mtype.parameterArray())
        if (!isStaticallyNameable(ptype))
            return false;
    if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
        return true;   // in java.lang.invoke package
    if (member.isPublic() && isStaticallyNameable(cls))
        return true;
    return false;
}
 
Example #30
Source File: MethodHandles.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}