2013-07-31 4 views

답변

5

당신은 이런 식으로 작업을 수행 할 수 있습니다

import org.codehaus.groovy.control.CompilerConfiguration 
import org.codehaus.groovy.control.customizers.SecureASTCustomizer 
import org.codehaus.groovy.control.customizers.SecureASTCustomizer.ExpressionChecker as EC 
import org.codehaus.groovy.ast.expr.AttributeExpression 

def config = new CompilerConfiguration() 
def secure = new SecureASTCustomizer() 
secure.addExpressionCheckers ({ expr -> 
    !(expr instanceof AttributeExpression) 
} as SecureASTCustomizer.ExpressionChecker) 
config.addCompilationCustomizers(secure) 

def shell = new GroovyShell(config) 
shell.evaluate ''' 
class A { int val } 
def a = new A(val:123) 
[email protected] 
''' 
+0

감사합니다! 너 포니의 바위 야! –

0

groovy-sandbox 라이브러리 지원이 차단.

(SecureASTCustomizer 실제로는 전혀 안전하지 않습니다. 샌드 박스를 위해 그것을 사용하지 마십시오.) 작동

관련 문제