Search in sources :

Example 1 with WhitelistClassBinding

use of org.opensearch.painless.spi.WhitelistClassBinding in project OpenSearch by opensearch-project.

the class PainlessLookupBuilder method buildFromWhitelists.

public static PainlessLookup buildFromWhitelists(List<Whitelist> allowlists) {
    PainlessLookupBuilder painlessLookupBuilder = new PainlessLookupBuilder();
    String origin = "internal error";
    try {
        for (Whitelist allowlist : allowlists) {
            for (WhitelistClass allowlistClass : allowlist.whitelistClasses) {
                origin = allowlistClass.origin;
                painlessLookupBuilder.addPainlessClass(allowlist.classLoader, allowlistClass.javaClassName, allowlistClass.painlessAnnotations.containsKey(NoImportAnnotation.class) == false);
            }
        }
        for (Whitelist allowlist : allowlists) {
            for (WhitelistClass allowlistClass : allowlist.whitelistClasses) {
                String targetCanonicalClassName = allowlistClass.javaClassName.replace('$', '.');
                for (WhitelistConstructor allowlistConstructor : allowlistClass.whitelistConstructors) {
                    origin = allowlistConstructor.origin;
                    painlessLookupBuilder.addPainlessConstructor(targetCanonicalClassName, allowlistConstructor.canonicalTypeNameParameters, allowlistConstructor.painlessAnnotations);
                }
                for (WhitelistMethod allowlistMethod : allowlistClass.whitelistMethods) {
                    origin = allowlistMethod.origin;
                    painlessLookupBuilder.addPainlessMethod(allowlist.classLoader, targetCanonicalClassName, allowlistMethod.augmentedCanonicalClassName, allowlistMethod.methodName, allowlistMethod.returnCanonicalTypeName, allowlistMethod.canonicalTypeNameParameters, allowlistMethod.painlessAnnotations);
                }
                for (WhitelistField allowlistField : allowlistClass.whitelistFields) {
                    origin = allowlistField.origin;
                    painlessLookupBuilder.addPainlessField(targetCanonicalClassName, allowlistField.fieldName, allowlistField.canonicalTypeNameParameter);
                }
            }
            for (WhitelistMethod allowlistStatic : allowlist.whitelistImportedMethods) {
                origin = allowlistStatic.origin;
                painlessLookupBuilder.addImportedPainlessMethod(allowlist.classLoader, allowlistStatic.augmentedCanonicalClassName, allowlistStatic.methodName, allowlistStatic.returnCanonicalTypeName, allowlistStatic.canonicalTypeNameParameters, allowlistStatic.painlessAnnotations);
            }
            for (WhitelistClassBinding allowlistClassBinding : allowlist.whitelistClassBindings) {
                origin = allowlistClassBinding.origin;
                painlessLookupBuilder.addPainlessClassBinding(allowlist.classLoader, allowlistClassBinding.targetJavaClassName, allowlistClassBinding.methodName, allowlistClassBinding.returnCanonicalTypeName, allowlistClassBinding.canonicalTypeNameParameters, allowlistClassBinding.painlessAnnotations);
            }
            for (WhitelistInstanceBinding allowlistInstanceBinding : allowlist.whitelistInstanceBindings) {
                origin = allowlistInstanceBinding.origin;
                painlessLookupBuilder.addPainlessInstanceBinding(allowlistInstanceBinding.targetInstance, allowlistInstanceBinding.methodName, allowlistInstanceBinding.returnCanonicalTypeName, allowlistInstanceBinding.canonicalTypeNameParameters);
            }
        }
    } catch (Exception exception) {
        throw new IllegalArgumentException("error loading allowlist(s) " + origin, exception);
    }
    return painlessLookupBuilder.build();
}
Also used : WhitelistConstructor(org.opensearch.painless.spi.WhitelistConstructor) WhitelistField(org.opensearch.painless.spi.WhitelistField) WhitelistClassBinding(org.opensearch.painless.spi.WhitelistClassBinding) Whitelist(org.opensearch.painless.spi.Whitelist) WhitelistInstanceBinding(org.opensearch.painless.spi.WhitelistInstanceBinding) WhitelistClass(org.opensearch.painless.spi.WhitelistClass) WhitelistMethod(org.opensearch.painless.spi.WhitelistMethod) MalformedURLException(java.net.MalformedURLException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 Whitelist (org.opensearch.painless.spi.Whitelist)1 WhitelistClass (org.opensearch.painless.spi.WhitelistClass)1 WhitelistClassBinding (org.opensearch.painless.spi.WhitelistClassBinding)1 WhitelistConstructor (org.opensearch.painless.spi.WhitelistConstructor)1 WhitelistField (org.opensearch.painless.spi.WhitelistField)1 WhitelistInstanceBinding (org.opensearch.painless.spi.WhitelistInstanceBinding)1 WhitelistMethod (org.opensearch.painless.spi.WhitelistMethod)1