|
58 | 58 | import com.googlecode.aviator.code.interpreter.InterpretCodeGenerator; |
59 | 59 | import com.googlecode.aviator.exception.CompileExpressionErrorException; |
60 | 60 | import com.googlecode.aviator.exception.ExpressionNotFoundException; |
| 61 | +import com.googlecode.aviator.exception.ExpressionRuntimeException; |
61 | 62 | import com.googlecode.aviator.exception.ExpressionSyntaxErrorException; |
62 | 63 | import com.googlecode.aviator.exception.UnsupportedFeatureException; |
63 | 64 | import com.googlecode.aviator.lexer.ExpressionLexer; |
@@ -1885,4 +1886,37 @@ public StringSegments compileStringSegments(final String lexeme, final String so |
1885 | 1886 | return new StringSegments(Collections.<StringSegment>emptyList(), 0); |
1886 | 1887 | } |
1887 | 1888 | } |
| 1889 | + |
| 1890 | + |
| 1891 | + /** |
| 1892 | + * check if class is in Options.ALLOWED_CLASS_SET |
| 1893 | + * |
| 1894 | + * @param checkIfAllow check or not |
| 1895 | + * @param clazz the class for check |
| 1896 | + * @return the class for check |
| 1897 | + */ |
| 1898 | + public Class<?> checkIfClassIsAllowed(final boolean checkIfAllow, final Class<?> clazz) { |
| 1899 | + if (checkIfAllow) { |
| 1900 | + Set<Class<?>> allowedList = this.getOptionValue(Options.ALLOWED_CLASS_SET).classes; |
| 1901 | + if (allowedList != null) { |
| 1902 | + // Null list means allowing all classes |
| 1903 | + if (!allowedList.contains(clazz)) { |
| 1904 | + throw new ExpressionRuntimeException( |
| 1905 | + "`" + clazz + "` is not in allowed class set, check Options.ALLOWED_CLASS_SET"); |
| 1906 | + } |
| 1907 | + } |
| 1908 | + Set<Class<?>> assignableList = |
| 1909 | + this.getOptionValue(Options.ASSIGNABLE_ALLOWED_CLASS_SET).classes; |
| 1910 | + if (assignableList != null) { |
| 1911 | + for (Class<?> aClass : assignableList) { |
| 1912 | + if (aClass.isAssignableFrom(clazz)) { |
| 1913 | + return clazz; |
| 1914 | + } |
| 1915 | + } |
| 1916 | + throw new ExpressionRuntimeException( |
| 1917 | + "`" + clazz + "` is not in allowed class set, check Options.ALLOWED_CLASS_SET"); |
| 1918 | + } |
| 1919 | + } |
| 1920 | + return clazz; |
| 1921 | + } |
1888 | 1922 | } |
0 commit comments