h2/src/main/org/h2/util/Utils.java
/**
     * Load a class, but check if it is allowed to load this class first. To
     * perform access rights checking, the system property h2.allowedClasses
     * needs to be set to a list of class file name prefixes.
     *
     * @param className the name of the class
     * @return the class object
     */
Load a class, but check if it is allowed to load this class first. To
perform access rights checking, the system property h2.allowedClasses
needs to be set to a list of class file name prefixes.

@param className the name of the class
@return the class object
Load a class but check if it is allowed to load this class first . To perform access rights checking the system property h2 . allowedClasses needs to be set to a list of class file name prefixes . @param className the name of the class @return the class object
public static Class<?> loadUserClass(String className) {
        if (allowedClassNames == null) {
            String s = SysProperties.ALLOWED_CLASSES;
            ArrayList<String> prefixes = New.arrayList();
            boolean allowAll = false;
            HashSet<String> classNames = New.hashSet();
            for (String p : StringUtils.arraySplit(s, ',', true)) {
                if (p.equals("*")) {
                    allowAll = true;
                } else if (p.endsWith("*")) {
                    prefixes.add(p.substring(0, p.length() - 1));
                } else {
                    classNames.add(p);
                }
            }
            allowedClassNamePrefixes = new String[prefixes.size()];
            prefixes.toArray(allowedClassNamePrefixes);
            allowAllClasses = allowAll;
            allowedClassNames = classNames;
        }
        if (!allowAllClasses && !allowedClassNames.contains(className)) {
            boolean allowed = false;
            for (String s : allowedClassNamePrefixes) {
                if (className.startsWith(s)) {
                    allowed = true;
                }
            }
            if (!allowed) {
                throw DbException.get(ErrorCode.ACCESS_DENIED_TO_CLASS_1, className);
            }
        }
        for (ClassFactory classFactory : getUserClassFactories()) {
            if (classFactory.match(className)) {
                try {
                    Class<?> userClass = classFactory.loadClass(className);
                    if (!(userClass == null)) {
                        return userClass;
                    }
                } catch (Exception e) {
                    throw DbException.get(ErrorCode.CLASS_NOT_FOUND_1, e, className);
                }
            }
        }
        try {
            return Class.forName(className);
        } catch (ClassNotFoundException e) {
            try {
                return Class.forName(className, true, Thread.currentThread().getContextClassLoader());
            } catch (Exception e2) {
                throw DbException.get(ErrorCode.CLASS_NOT_FOUND_1, e, className);
            }
        } catch (NoClassDefFoundError e) {
            throw DbException.get(ErrorCode.CLASS_NOT_FOUND_1, e, className);
        } catch (Error e) {
            throw DbException.get(ErrorCode.GENERAL_ERROR_1, e, className);
        }
    }
public static Class < ? > loadUserClass ( String className ) { if ( allowedClassNames == null ) { String s = SysProperties . ALLOWED_CLASSES ; ArrayList < String > prefixes = New . arrayList ( ) ; boolean allowAll = false ; HashSet < String > classNames = New . hashSet ( ) ; for ( String p : StringUtils . arraySplit ( s , ',' , true ) ) { if ( p . equals ( "*" ) ) { allowAll = true ; } else if ( p . endsWith ( "*" ) ) { prefixes . add ( p . substring ( 0 , p . length ( ) - 1 ) ) ; } else { classNames . add ( p ) ; } } allowedClassNamePrefixes = new String [ prefixes . size ( ) ] ; prefixes . toArray ( allowedClassNamePrefixes ) ; allowAllClasses = allowAll ; allowedClassNames = classNames ; } if ( ! allowAllClasses && ! allowedClassNames . contains ( className ) ) { boolean allowed = false ; for ( String s : allowedClassNamePrefixes ) { if ( className . startsWith ( s ) ) { allowed = true ; } } if ( ! allowed ) { throw DbException . get ( ErrorCode . ACCESS_DENIED_TO_CLASS_1 , className ) ; } } for ( ClassFactory classFactory : getUserClassFactories ( ) ) { if ( classFactory . match ( className ) ) { try { Class < ? > userClass = classFactory . loadClass ( className ) ; if ( ! ( userClass == null ) ) { return userClass ; } } catch ( Exception e ) { throw DbException . get ( ErrorCode . CLASS_NOT_FOUND_1 , e , className ) ; } } } try { return Class . forName ( className ) ; } catch ( ClassNotFoundException e ) { try { return Class . forName ( className , true , Thread . currentThread ( ) . getContextClassLoader ( ) ) ; } catch ( Exception e2 ) { throw DbException . get ( ErrorCode . CLASS_NOT_FOUND_1 , e , className ) ; } } catch ( NoClassDefFoundError e ) { throw DbException . get ( ErrorCode . CLASS_NOT_FOUND_1 , e , className ) ; } catch ( Error e ) { throw DbException . get ( ErrorCode . GENERAL_ERROR_1 , e , className ) ; } }
Load a class, but check if it is allowed to load this class first.
Load a class but check if it is allowed to load this class first .
// initialize the static fields // Use provided class factory first. // Use local ClassLoader // UnsupportedClassVersionError