Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f1dd7e5
Using Scripting API in platform/core.network
Jan 21, 2019
1894e0c
Continue to specify class filter when using Nashorn engine
Jan 21, 2019
ef302df
Merge branch 'master' into CoreNetworkAndScriptingAPI
Jan 21, 2019
294cb63
Allow exit from the unit test
Jan 22, 2019
f2c5275
ConfigureProxy task to set proxy before downloading Gradle
Jan 25, 2019
6247e88
Merging with recent master
Apr 29, 2019
c9fdbfc
Updating to GraalVM RC16
Apr 29, 2019
a499252
Can't build web.core module in our corporate environment without havi…
Apr 29, 2019
a297bcf
Setting up proxy before building web.core module
Apr 29, 2019
8f60775
Merging with master and running with nashorn emulation
Apr 29, 2019
4592738
icu4j is needed for Graal JS I18N support
Apr 29, 2019
d9ef75c
Make the default value of proxyPort property a number
May 22, 2019
db69ef4
Using released version 19.0.0 of GraalVM libraries
May 22, 2019
fb47be0
Adjusting to API changes in GraalVM SDK, Truffle and Graal.js modules
May 22, 2019
1cb766d
Merge remote-tracking branch 'origin/master' into CoreNetworkAndScrip…
May 22, 2019
d2bb159
Adjusting to GraalVM 19.0.0
May 23, 2019
bfbe61d
Adjusting version to 19.0.0
May 24, 2019
a0ebbb9
Sharing the license between ide/html.parser/external/icu4j-4_4_2-lice…
May 24, 2019
c5365c1
Use 1.7 compilation level even on newer JDKs
May 24, 2019
d0525af
Always set the proxy host property - even to empty string
May 24, 2019
0b04f4d
Avoid configuration of the engines via global properties
May 24, 2019
6468401
Describing the security model of GraalVM languages and crosslinking t…
May 24, 2019
01a351e
Merge remote-tracking branch 'origin/master' into CoreNetworkAndScrip…
May 24, 2019
afc27a4
Keep the hintful comment
May 24, 2019
f47f36c
Secure all script engines by default
May 27, 2019
f21511c
Control access to Java.type via a property
May 28, 2019
c3b95e1
Replacing allowAllAccess property with a builder configuration method
May 28, 2019
5a0a6e7
Test the JavaScript engines in both 'all access' modes
May 28, 2019
7a90c43
ALLOWED_PAC_ENGINES branding API to allow applications to restrict th…
May 28, 2019
ae8dd1a
Only set the gradle.proxy.args if the resolved proxy is not empty
May 29, 2019
30626a3
Attributing non-localizable strings with NOI18N comment
May 29, 2019
abd99c9
Removing redundant null check
May 29, 2019
178b4c6
Tightening up security by removing access to common reflection entryp…
Jun 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions enterprise/web.core/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
-->
<project basedir="." default="build" name="enterprise/web.core">
<import file="../../nbbuild/templates/projectized.xml"/>
<taskdef name="configureproxy" classname="org.netbeans.nbbuild.extlibs.ConfigureProxy" classpath="${nbantext.jar}"/>
<configureproxy connectTo="http://netbeans.apache.org" hostProperty="proxyHost" portProperty="proxyPort"/>
<setproxy proxyhost="${proxyHost}" proxyPort="${proxyPort}"/>
</project>
13 changes: 12 additions & 1 deletion groovy/gradle/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<description>Builds, tests, and runs the project org.netbeans.modules.gradle</description>
<import file="../../nbbuild/templates/projectized.xml"/>

<taskdef name="configureproxy" classname="org.netbeans.nbbuild.extlibs.ConfigureProxy" classpath="${nbantext.jar}"/>

<property name="test-unit-sys-prop.test.data.dir" location="test/data"/>
<property name="tooling" value="netbeans-gradle-tooling"/>
<available property="have.gradle.wrapper" file="${tooling}/gradle/wrapper/gradle-wrapper.jar"/>
Expand All @@ -36,9 +38,18 @@
<copy file="external/gradle-wrapper-4.10.2.jar" tofile="${tooling}/gradle/wrapper/gradle-wrapper.jar"/>
</target>

<target name="build-tooling-lib" depends="-copy-gradle-wrapper,-uptodate-tooling" unless="tooling.uptodate">
<target name="build-tooling-lib" depends="-download.release.files,-copy-gradle-wrapper,-uptodate-tooling" unless="tooling.uptodate">
<configureproxy connectTo="http://netbeans.apache.org" hostProperty="proxyHost" portProperty="proxyPort"/>
<condition property="gradle.proxy.args" value="-Dhttp.proxyHost=${proxyHost} -Dhttp.proxyPort=${proxyPort} -Dhttps.proxyHost=${proxyHost} -Dhttps.proxyPort=${proxyPort}">
<not>
<equals arg1="${proxyHost}" arg2="" />
</not>
</condition>
<property name="gradle.proxy.args" value=""/>

<java fork="true" dir="${tooling}" classpath="${tooling}/gradle/wrapper/gradle-wrapper.jar" classname="org.gradle.wrapper.GradleWrapperMain" failonerror="true">
<sysproperty key="org.gradle.appname" value="Gradle"/>
<arg line="${gradle.proxy.args}"/>
<arg line="clean build -x check"/>
</java>
<copy file="${tooling}/build/libs/${tooling}.jar" todir="build/tooling" overwrite="true"/>
Expand Down
9 changes: 7 additions & 2 deletions ide/libs.graalsdk/arch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@
<usecase id="org.graalvm.polyglot" name="Use Graal SDK directly">
<api category="third" group="java" name="org.graalvm.polyglot" type="export">
This module re-exports <code>org.graalvm.polyglot</code> APIs.
Use them to obtain directly, if you trust the provider of those APIs.
Use them to obtain access to the GraalVM directly, if you only
want to work with them and generic
<a href="@org-netbeans-api-scripting@/org/netbeans/api/scripting/Scripting.html">Scripting</a>
wrapper isn't enough.
</api>
</usecase>
</p>
Expand Down Expand Up @@ -551,7 +554,9 @@
<api name="allowAllAccess" type="export" group="property" category="stable">
By default all the <a href="http://graalvm.org">GraalVM</a> engines
(named <code>GraalVM:something</code>)
run in a very restricted, secure sandbox. That means they cannot
run in a very restricted, secure sandbox. See
<a href="@TOP@/org/netbeans/libs/graalsdk/GraalSDK.html">GraalSDK</a>
for details. That means the languages cannot
access local files, ports, etc. Some languages (like
<a href="https://gihub.com/graalvm/fastr">>FastR</a>
implementation of the <b>R</b> language) need such access. In such
Expand Down
2 changes: 1 addition & 1 deletion ide/libs.graalsdk/external/binaries-list
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
0E1CCE754C9EF8847B473FAB3F848D1FE324F09E org.graalvm.sdk:graal-sdk:1.0.0-rc12
3C22A79D3CCCCFD161F4DD935C30C745F6FFF848 org.graalvm.sdk:graal-sdk:19.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Name: Graal SDK and Truffle API
Description: Graal SDK and Truffle API
License: UPL
Origin: https://github.com/oracle/graal
Version: 1.0
Files: graal-sdk-1.0.0-rc12.jar
Version: 19.0.0
Files: graal-sdk-19.0.0.jar

Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.

Expand Down
465 changes: 445 additions & 20 deletions ide/libs.graalsdk/nbproject/org-netbeans-libs-graalsdk.sig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ide/libs.graalsdk/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ javac.source=1.8
javac.compilerargs=-Xlint -Xlint:-serial
is.autoload=true

release.external/graal-sdk-1.0.0-rc12.jar=modules/ext/graal-sdk-1.0.0-rc12.jar
release.external/graal-sdk-19.0.0.jar=modules/ext/graal-sdk-19.0.0.jar

javadoc.arch=${basedir}/arch.xml
javadoc.apichanges=${basedir}/apichanges.xml
6 changes: 3 additions & 3 deletions ide/libs.graalsdk/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
<specification-version>1.2</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down Expand Up @@ -80,8 +80,8 @@
<package>org.netbeans.libs.graalsdk</package>
</public-packages>
<class-path-extension>
<runtime-relative-path>ext/graal-sdk-1.0.0-rc12.jar</runtime-relative-path>
<binary-origin>external/graal-sdk-1.0.0-rc12.jar</binary-origin>
<runtime-relative-path>ext/graal-sdk-19.0.0.jar</runtime-relative-path>
<binary-origin>external/graal-sdk-19.0.0.jar</binary-origin>
</class-path-extension>
</data>
</configuration>
Expand Down
37 changes: 34 additions & 3 deletions ide/libs.graalsdk/src/org/netbeans/libs/graalsdk/GraalSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,48 @@
*/
package org.netbeans.libs.graalsdk;

import java.util.List;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Context.Builder;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.HostAccess;

/**
* Integration of <a href="@org-netbeans-api-scripting@/overview-summary.html">NetBeans Scripting</a>
* API and GraalVM; see the {@link org.netbeans.libs.graalsdk tutorial} for more details.
* <h2>Security</h2>
* <p>
* As a secondary usecase, it is possible to request this module and gain access to
* {@code org.graalvm.polyglot} package directly. Consult {@link Context} and {@link Engine}
* By default all the <a href="http://graalvm.org">GraalVM</a> engines
* (named <code>GraalVM:something</code>)
* run in a very restricted, secure sandbox:
* </p>
* {@codesnippet org.netbeans.libs.graalsdk.impl.GraalContext#SANDBOX}
* <p>
* The languages cannot access local files, ports, etc. They can access <b>public</b>
* fields and <b>public</b> methods of objects passed into their scripts (but not
* those methods exposed by base {@link Object} class). The scripts can access
* elements of Java arrays and {@link List} elements. Methods of a
* {@linkplain FunctionalInterface functional interfaces} are callable by the
* scripts.
* </p>
* <p>
* For some languages such restrictions are too tight. They
* need to gain wider access. This can be done by setting <code>allowAllAccess</code>
* attribute to {@code true}:
* </p>
* {@codesnippet org.netbeans.libs.graalsdk.ScriptingTutorial#allowAllAccess}
* <p>
* Once enabled, the {@link HostAccess#ALL} and {@link Builder#allowAllAccess(boolean) allowAllAccess(true)}
* is then used to construct the engine's environment.
* </p>
* <h2>Polyglot API Access</h2>
* <p>
* As a consequence of packaging the GraalVM APIs, it is possible to request this module and gain access to
* {@link org.graalvm.polyglot} package directly. Consult {@link Context} and {@link Engine}
* classes as a starting points when
* accessing the Graal SDK polyglot API directly.
* accessing the Graal SDK directly. Preferably use only if the
* <a href="@org-netbeans-api-scripting@/overview-summary.html">NetBeans Scripting</a>
* API wrapper isn't good enough.
*/
public final class GraalSDK {
private GraalSDK() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,48 @@
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.SimpleBindings;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.HostAccess;
import org.graalvm.polyglot.PolyglotAccess;
import org.openide.util.io.ReaderInputStream;

final class GraalContext implements ScriptContext {
private final static String ALLOW_ALL_ACCESS = "allowAllAccess"; // NOI18N
private Context ctx;
private final WriterOutputStream writer = new WriterOutputStream(new OutputStreamWriter(System.out));
private final WriterOutputStream errorWriter = new WriterOutputStream(new OutputStreamWriter(System.err));
private Reader reader;
private final Bindings globals;
private SimpleBindings bindings;
private boolean allowAllAccess;

// BEGIN: org.netbeans.libs.graalsdk.impl.GraalContext#SANDBOX
private static final HostAccess SANDBOX = HostAccess.newBuilder().
allowPublicAccess(true).
allowArrayAccess(true).
allowListAccess(true).
allowAllImplementations(true).
denyAccess(Class.class).
denyAccess(Method.class).
denyAccess(Field.class).
denyAccess(Proxy.class).
denyAccess(Object.class, false).
build();
// END: org.netbeans.libs.graalsdk.impl.GraalContext#SANDBOX

GraalContext(Bindings globals) {
this.globals = globals;
}

synchronized final Context ctx() {
if (ctx == null) {
final Context.Builder b = Context.newBuilder();
Expand All @@ -51,15 +76,18 @@ synchronized final Context ctx() {
throw raise(RuntimeException.class, ex);
}
}
if (allowAllAccess) {
b.allowPolyglotAccess(PolyglotAccess.ALL);
if (Boolean.TRUE.equals(getAttribute(ALLOW_ALL_ACCESS, ScriptContext.GLOBAL_SCOPE))) {
b.allowHostAccess(HostAccess.ALL);
b.allowAllAccess(true);
} else {
b.allowHostAccess(SANDBOX);
}
ctx = b.build();
}
return ctx;
}


@Override
public void setBindings(Bindings bindings, int scope) {
throw new UnsupportedOperationException();
Expand All @@ -85,7 +113,7 @@ private void assertGlobalScope(int scope) throws IllegalArgumentException {
@Override
public void setAttribute(String name, Object value, int scope) {
assertGlobalScope(scope);
if ("allowAllAccess".equals(name)) { // NOI18N
if (ALLOW_ALL_ACCESS.equals(name)) {
if (this.ctx == null) {
this.allowAllAccess = Boolean.TRUE.equals(value);
return;
Expand All @@ -98,10 +126,12 @@ public void setAttribute(String name, Object value, int scope) {
@Override
public Object getAttribute(String name, int scope) {
assertGlobalScope(scope);
if ("allowAllAccess".equals(name)) { // NOI18N
return this.allowAllAccess;
if (ALLOW_ALL_ACCESS.equals(name)) {
if (this.allowAllAccess) {
return true;
}
}
return null;
return globals == null ? null : globals.get(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<String> getMimeTypes() {

@Override
public List<String> getNames() {
return Arrays.asList(language.getName());
return Arrays.asList(language.getName(), getEngineName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.script.Bindings;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Language;
import org.netbeans.spi.scripting.EngineProvider;
Expand All @@ -36,19 +38,24 @@ public GraalEnginesProvider() {

@Override
public List<ScriptEngineFactory> factories() {
return factories(null);
}

@Override
public List<ScriptEngineFactory> factories(ScriptEngineManager m) {
List<ScriptEngineFactory> arr = new ArrayList<>();
try {
if (disable == null) {
enumerateLanguages(arr);
enumerateLanguages(arr, m == null ? null : m.getBindings());
}
} catch (IllegalStateException | LinkageError err) {
disable = err;
}
return arr;
}

private void enumerateLanguages(List<ScriptEngineFactory> arr) {
final GraalContext ctx = new GraalContext();
private void enumerateLanguages(List<ScriptEngineFactory> arr, Bindings globals) {
final GraalContext ctx = new GraalContext(globals);
try (Engine engine = Engine.newBuilder().build()) {
for (Map.Entry<String, Language> entry : engine.getLanguages().entrySet()) {
arr.add(new GraalEngineFactory(ctx, entry.getKey(), entry.getValue()));
Expand Down
Loading