Java Code Examples for jdk.nashorn.internal.runtime.Context#isAccessibleClass()

The following examples show how to use jdk.nashorn.internal.runtime.Context#isAccessibleClass() . 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: NashornBeansLinker.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static String findFunctionalInterfaceMethodName(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (final Class<?> iface : clazz.getInterfaces()) {
        // check accessibility up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers())) {
                    return m.getName();
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethodName(clazz.getSuperclass());
}
 
Example 2
Source File: NashornBottomLinker.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Method findFunctionalInterfaceMethod(final Class<?> clazz) {
            if (clazz == null) {
                return null;
            }

            for (Class<?> iface : clazz.getInterfaces()) {
                // check accessiblity up-front
                if (! Context.isAccessibleClass(iface)) {
                    continue;
                }

                // check for @FunctionalInterface
//                if (iface.isAnnotationPresent(FunctionalInterface.class)) {
//                    // return the first abstract method
//                    for (final Method m : iface.getMethods()) {
//                        if (Modifier.isAbstract(m.getModifiers())) {
//                            return m;
//                        }
//                    }
//                }
	            // Not supported in JDK7
            }

            // did not find here, try super class
            return findFunctionalInterfaceMethod(clazz.getSuperclass());
        }
 
Example 3
Source File: ReflectionCheckLinker.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if ("static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {
                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 4
Source File: NashornBeansLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static String findFunctionalInterfaceMethodName(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (final Class<?> iface : clazz.getInterfaces()) {
        // check accessibility up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers()) && !isOverridableObjectMethod(m)) {
                    return m.getName();
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethodName(clazz.getSuperclass());
}
 
Example 5
Source File: NashornBottomLinker.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private Method findFunctionalInterfaceMethod(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (Class<?> iface : clazz.getInterfaces()) {
        // check accessiblity up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers())) {
                    return m;
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethod(clazz.getSuperclass());
}
 
Example 6
Source File: ReflectionCheckLinker.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if ("static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 7
Source File: NashornBottomLinker.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Method findFunctionalInterfaceMethod(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (Class<?> iface : clazz.getInterfaces()) {
        // check accessiblity up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers())) {
                    return m;
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethod(clazz.getSuperclass());
}
 
Example 8
Source File: ReflectionCheckLinker.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if ("static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 9
Source File: NashornBeansLinker.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static String findFunctionalInterfaceMethodName(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (final Class<?> iface : clazz.getInterfaces()) {
        // check accessibility up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers()) && !isOverridableObjectMethod(m)) {
                    return m.getName();
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethodName(clazz.getSuperclass());
}
 
Example 10
Source File: ReflectionCheckLinker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkLinkRequest(final LinkRequest request) {
    final Global global = Context.getGlobal();
    final ClassFilter cf = global.getClassFilter();
    if (cf != null) {
        throw typeError("no.reflection.with.classfilter");
    }

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final Object self = request.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = request.getCallSiteDescriptor();
            if ("static".equals(NashornCallSiteDescriptor.getOperand(desc)) && NashornCallSiteDescriptor.contains(desc, StandardOperation.GET, StandardNamespace.PROPERTY)) {
                if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {
                    // If "GET:PROPERTY:static" passes access checks, allow access.
                    return;
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 11
Source File: NashornBeansLinker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static String findFunctionalInterfaceMethodName(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (final Class<?> iface : clazz.getInterfaces()) {
        // check accessibility up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers()) && !isOverridableObjectMethod(m)) {
                    return m.getName();
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethodName(clazz.getSuperclass());
}
 
Example 12
Source File: NashornBeansLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static String findFunctionalInterfaceMethodName(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (final Class<?> iface : clazz.getInterfaces()) {
        // check accessibility up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers()) && !isOverridableObjectMethod(m)) {
                    return m.getName();
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethodName(clazz.getSuperclass());
}
 
Example 13
Source File: NashornBeansLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static String findFunctionalInterfaceMethodName(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (final Class<?> iface : clazz.getInterfaces()) {
        // check accessibility up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers()) && !isOverridableObjectMethod(m)) {
                    return m.getName();
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethodName(clazz.getSuperclass());
}
 
Example 14
Source File: NashornBeansLinker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static Method findFunctionalInterfaceMethod(final Class<?> clazz) {
    if (clazz == null) {
        return null;
    }

    for (final Class<?> iface : clazz.getInterfaces()) {
        // check accessiblity up-front
        if (! Context.isAccessibleClass(iface)) {
            continue;
        }

        // check for @FunctionalInterface
        if (iface.isAnnotationPresent(FunctionalInterface.class)) {
            // return the first abstract method
            for (final Method m : iface.getMethods()) {
                if (Modifier.isAbstract(m.getModifiers())) {
                    return m;
                }
            }
        }
    }

    // did not find here, try super class
    return findFunctionalInterfaceMethod(clazz.getSuperclass());
}
 
Example 15
Source File: ReflectionCheckLinker.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final Global global = Context.getGlobal();
    final ClassFilter cf = global.getClassFilter();
    if (cf != null) {
        throw typeError("no.reflection.with.classfilter");
    }

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND &&
                    "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 16
Source File: ReflectionCheckLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final Global global = Context.getGlobal();
    final ClassFilter cf = global.getClassFilter();
    if (cf != null) {
        throw typeError("no.reflection.with.classfilter");
    }

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND &&
                    "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 17
Source File: ReflectionCheckLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final Global global = Context.getGlobal();
    final ClassFilter cf = global.getClassFilter();
    if (cf != null) {
        throw typeError("no.reflection.with.classfilter");
    }

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND &&
                    "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 18
Source File: ReflectionCheckLinker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final Global global = Context.getGlobal();
    final ClassFilter cf = global.getClassFilter();
    if (cf != null) {
        throw typeError("no.reflection.with.classfilter");
    }

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND &&
                    "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 19
Source File: ReflectionCheckLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final Global global = Context.getGlobal();
    final ClassFilter cf = global.getClassFilter();
    if (cf != null) {
        throw typeError("no.reflection.with.classfilter");
    }

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND &&
                    "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}
 
Example 20
Source File: ReflectionCheckLinker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkLinkRequest(final LinkRequest origRequest) {
    final Global global = Context.getGlobal();
    final ClassFilter cf = global.getClassFilter();
    if (cf != null) {
        throw typeError("no.reflection.with.classfilter");
    }

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context
        final Object self = requestWithoutContext.getReceiver();
        // allow 'static' access on Class objects representing public classes of non-restricted packages
        if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
            final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor();
            if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) {
                if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND &&
                    "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
                    if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {

                        // If "getProp:static" passes access checks, allow access.
                        return;
                    }
                }
            }
        }
        checkReflectionPermission(sm);
    }
}