Java Code Examples for sun.invoke.util.VerifyAccess#isClassAccessible()

The following examples show how to use sun.invoke.util.VerifyAccess#isClassAccessible() . 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: MethodHandles.java    From jdk1.8-source-analysis with Apache License 2.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 2
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 3
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 4
Source File: MethodHandles.java    From openjdk-jdk8u 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 5
Source File: MethodHandles.java    From JDKSourceCode1.8 with MIT License 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 6
Source File: MethodHandles.java    From openjdk-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 7
Source File: MethodHandles.java    From hottub 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 8
Source File: MethodHandles.java    From jdk8u-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 9
Source File: MethodHandles.java    From jdk-1.7-annotated 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 10
Source File: MethodHandles.java    From jdk8u-jdk 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 11
Source File: MethodHandles.java    From openjdk-8-source 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 12
Source File: MethodHandles.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 13
Source File: MethodHandles.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 14
Source File: MethodHandles.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 15
Source File: MethodHandles.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 16
Source File: MethodHandles.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 17
Source File: MethodHandles.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 18
Source File: MethodHandles.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 19
Source File: MethodHandles.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}
 
Example 20
Source File: MethodHandles.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void checkSymbolicClass(Class<?> refc) throws IllegalAccessException {
    refc.getClass();  // NPE
    Class<?> caller = lookupClassOrNull();
    if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes))
        throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this);
}