Groovy 샌드 박스에서 작업하고 [email protected]
연산자를 차단하고 싶습니다. SecureASTCustomizer
을 사용 중이며 승인을 삭제 한 SecureASTCustomizer.ExpressionChecker
사용자 정의를 작성했습니다.블록. @ 연산자는 어떻게 사용합니까?
내 문제는 : @
연산자를 감지 할 수있는 방법을 찾을 수 없습니다.
Groovy 샌드 박스에서 작업하고 [email protected]
연산자를 차단하고 싶습니다. SecureASTCustomizer
을 사용 중이며 승인을 삭제 한 SecureASTCustomizer.ExpressionChecker
사용자 정의를 작성했습니다.블록. @ 연산자는 어떻게 사용합니까?
내 문제는 : @
연산자를 감지 할 수있는 방법을 찾을 수 없습니다.
당신은 이런 식으로 작업을 수행 할 수 있습니다
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]
'''
groovy-sandbox 라이브러리 지원이 차단.
(SecureASTCustomizer
실제로는 전혀 안전하지 않습니다. 샌드 박스를 위해 그것을 사용하지 마십시오.) 작동
감사합니다! 너 포니의 바위 야! –