org.mozilla.javascript.SecurityController Java Examples

The following examples show how to use org.mozilla.javascript.SecurityController. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
 
Example #2
Source File: BirtEngine.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Inits the birt config.
 */
public static synchronized void initBirtConfig() {
	loadEngineProps();
	/**
	 * Needed by Mozilla Javascript lib when Tomcat is started
	 * with a security manager.
	 */
	SecurityController.initGlobal(new PolicySecurityController());
}
 
Example #3
Source File: Main.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private static Script loadCompiledScript(Context cx, String path,
                                         byte[] data, Object securityDomain)
        throws FileNotFoundException
{
    if (data == null) {
        throw new FileNotFoundException(path);
    }
    // XXX: For now extract class name of compiled Script from path
    // instead of parsing class bytes
    int nameStart = path.lastIndexOf('/');
    if (nameStart < 0) {
        nameStart = 0;
    } else {
        ++nameStart;
    }
    int nameEnd = path.lastIndexOf('.');
    if (nameEnd < nameStart) {
        // '.' does not exist in path (nameEnd < 0)
        // or it comes before nameStart
        nameEnd = path.length();
    }
    String name = path.substring(nameStart, nameEnd);
    try {
        GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
        Class<?> clazz = loader.defineClass(name, data);
        loader.linkClass(clazz);
        if (!Script.class.isAssignableFrom(clazz)) {
            throw Context.reportRuntimeError("msg.must.implement.Script");
        }
        return (Script) clazz.newInstance();
    } catch (IllegalAccessException iaex) {
        Context.reportError(iaex.toString());
        throw new RuntimeException(iaex);
    } catch (InstantiationException inex) {
        Context.reportError(inex.toString());
        throw new RuntimeException(inex);
    }
}
 
Example #4
Source File: JavascriptEngineFactory.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static void initMyFactory( )
{
	ContextFactory.initGlobal( new MyFactory( ) );
	if ( System.getSecurityManager( ) != null )
	{
		SecurityController.initGlobal( ScriptUtil
				.createSecurityController( ) );
	}
}
 
Example #5
Source File: RhinoAndroidHelper.java    From rhino-android with Apache License 2.0 4 votes vote down vote up
/**
 * call this instead of {@link Context#enter()}
 *
 * @return a context prepared for android
 */
public Context enterContext() {
    if (!SecurityController.hasGlobal())
        SecurityController.initGlobal(new NoSecurityController());
    return getContextFactory().enterContext();
}
 
Example #6
Source File: ScriptUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static SecurityController createSecurityController( )
{
	return new PolicySecurityController( );
}