comparison src/luan/modules/JavaLuan.java @ 1330:f41919741100

fix security
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 11 Feb 2019 01:38:55 -0700
parents 9fa8b8389578
children 25746915a241
comparison
equal deleted inserted replaced
1329:5a39b006acd1 1330:f41919741100
26 26
27 27
28 public final class JavaLuan { 28 public final class JavaLuan {
29 29
30 public static void java(LuanState luan) throws LuanException { 30 public static void java(LuanState luan) throws LuanException {
31 check(luan); 31 Luan.checkSecurity(luan,"java");
32 luan.javaOk.ok = true; 32 luan.peek().javaOk = true;
33 } 33 }
34 34
35 public static final LuanFunction javaFn; 35 public static final LuanFunction javaFn;
36 static { 36 static {
37 try { 37 try {
40 throw new RuntimeException(e); 40 throw new RuntimeException(e);
41 } 41 }
42 } 42 }
43 43
44 private static void checkJava(LuanState luan) throws LuanException { 44 private static void checkJava(LuanState luan) throws LuanException {
45 if( !luan.javaOk.ok ) 45 if( !luan.peek().javaOk )
46 throw new LuanException("Java isn't allowed"); 46 throw new LuanException("Java isn't allowed");
47 } 47 }
48 48
49 public static Object __index(LuanState luan,Object obj,Object key) throws LuanException { 49 public static Object __index(LuanState luan,Object obj,Object key) throws LuanException {
50 checkJava(luan); 50 checkJava(luan);
470 } 470 }
471 ); 471 );
472 } 472 }
473 */ 473 */
474 474
475 475 private void JavaLuan() {} // never
476
477 // security
478
479 public interface Security {
480 public void check(LuanState luan,String name) throws LuanException;
481 }
482
483 private static String SECURITY_KEY = "Java.Security";
484
485 static void check(LuanState luan) throws LuanException {
486 Security s = (Security)luan.registry().get(SECURITY_KEY);
487 if( s!=null ) {
488 String name = LuanException.currentSource();
489 s.check(luan,name);
490 }
491 }
492
493 public static void setSecurity(LuanState luan,Security s) {
494 luan.registry().put(SECURITY_KEY,s);
495 }
496
497 } 476 }