Package com.tinkerpop.gremlin.groovy

Examples of com.tinkerpop.gremlin.groovy.SecurityCustomizerProvider


    }

    @Test
    public void shouldSecureAll() throws Exception {
        GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
        final SecurityCustomizerProvider provider = new SecurityCustomizerProvider(new DenyAll());
        final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(
                new DefaultImportCustomizerProvider(), provider);
        try {
            scriptEngine.eval("g = new java.awt.Color(255, 255, 255)");
            fail("Should have failed security");
        } catch (ScriptException se) {
            assertEquals(SecurityException.class, se.getCause().getCause().getClass());
        } finally {
            provider.unregisterInterceptors();
        }
    }
View Full Code Here


    }

    @Test
    public void shouldSecureSome() throws Exception {
        GroovyInterceptor.getApplicableInterceptors().forEach(GroovyInterceptor::unregister);
        final SecurityCustomizerProvider provider = new SecurityCustomizerProvider(new AllowSome());
        final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(
                new DefaultImportCustomizerProvider(), provider);
        try {
            scriptEngine.eval("g = 'new java.awt.Color(255, 255, 255)'");
            fail("Should have failed security");
        } catch (ScriptException se) {
            assertEquals(SecurityException.class, se.getCause().getCause().getClass());
        }

        try {
            assertNotNull(g);
            final java.awt.Color c = (java.awt.Color) scriptEngine.eval("c = new java.awt.Color(255, 255, 255)");
            assertEquals(java.awt.Color.class, c.getClass());
        } catch (Exception ex) {
            fail("Should not have tossed an exception");
        } finally {
            provider.unregisterInterceptors();
        }
    }
View Full Code Here

        // gremlin-groovy gets special initialization for custom imports and such.  could implement this more
        // generically with the DependencyManager interface, but going to wait to see how other ScriptEngines
        // develop for TinkerPop3 before committing too deeply here to any specific way of doing this.
        if (language.equals(gremlinGroovyScriptEngineFactory.getLanguageName())) {
            final String clazz = (String) config.getOrDefault("sandbox", "");
            SecurityCustomizerProvider securityCustomizerProvider = null;
            if (!clazz.isEmpty()) {
                try {
                    final Class providerClass = Class.forName(clazz);
                    final GroovyInterceptor interceptor = (GroovyInterceptor) providerClass.newInstance();
                    securityCustomizerProvider = new SecurityCustomizerProvider(interceptor);
                } catch (Exception ex) {
                    logger.warn("Could not instantiate GroovyInterceptor implementation [%s] for the SecurityCustomizerProvider.  It will not be applied.", clazz);
                    securityCustomizerProvider = null;
                }
            }
View Full Code Here

TOP

Related Classes of com.tinkerpop.gremlin.groovy.SecurityCustomizerProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.