Mercurial Hosting > luan
comparison src/luan/host/WebHandler.java @ 1608:f7e3adae4907
add BasicAuthHandler
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 01 May 2021 19:52:56 -0600 |
parents | fa066aaa068c |
children | 07be5015159d |
comparison
equal
deleted
inserted
replaced
1607:fa066aaa068c | 1608:f7e3adae4907 |
---|---|
15 import goodjava.webserver.handlers.SafeHandler; | 15 import goodjava.webserver.handlers.SafeHandler; |
16 import goodjava.webserver.handlers.LogHandler; | 16 import goodjava.webserver.handlers.LogHandler; |
17 import goodjava.webserver.handlers.FileHandler; | 17 import goodjava.webserver.handlers.FileHandler; |
18 import goodjava.webserver.handlers.DirHandler; | 18 import goodjava.webserver.handlers.DirHandler; |
19 import goodjava.webserver.handlers.HeadersHandler; | 19 import goodjava.webserver.handlers.HeadersHandler; |
20 import goodjava.webserver.handlers.BasicAuthHandler; | |
21 import goodjava.webserver.handlers.RegexHandler; | |
20 import luan.Luan; | 22 import luan.Luan; |
21 import luan.LuanException; | 23 import luan.LuanException; |
22 import luan.LuanTable; | 24 import luan.LuanTable; |
23 import luan.LuanFunction; | 25 import luan.LuanFunction; |
24 import luan.LuanClosure; | 26 import luan.LuanClosure; |
59 } catch(IOException e) { | 61 } catch(IOException e) { |
60 throw new RuntimeException(e); | 62 throw new RuntimeException(e); |
61 } | 63 } |
62 | 64 |
63 Luan luan = new Luan(); | 65 Luan luan = new Luan(); |
64 initLuan(luan,dirStr,domain); | 66 String password; |
67 LuanLogger.startThreadLogging(luan); | |
68 try { | |
69 LuanFunction fn = Luan.loadClasspath(luan,"luan/host/init.luan"); | |
70 fn.call(luan,dirStr,domain); | |
71 LuanTable Io = (LuanTable)luan.require("luan:Io.luan"); | |
72 password = (String)Io.get(luan,"password"); | |
73 if( password==null ) throw new NullPointerException(); | |
74 } catch(LuanException e) { | |
75 throw new LuanRuntimeException(e); | |
76 } finally { | |
77 LuanLogger.endThreadLogging(); | |
78 } | |
79 security(luan,dirStr); | |
65 LuanHandler luanHandler = new LuanHandler(luan,domain); | 80 LuanHandler luanHandler = new LuanHandler(luan,domain); |
66 | 81 |
67 FileHandler fileHandler = new FileHandler(dirStr+"/site/"); | 82 FileHandler fileHandler = new FileHandler(dirStr+"/site/"); |
68 Handler handler = new ListHandler( luanHandler, fileHandler ); | 83 Handler handler = new ListHandler( luanHandler, fileHandler ); |
69 handler = new ContentTypeHandler(handler); | 84 handler = new ContentTypeHandler(handler); |
70 handler = new IndexHandler(handler); | 85 handler = new IndexHandler(handler); |
71 DirHandler dirHandler = new DirHandler(fileHandler); | 86 DirHandler dirHandler = new DirHandler(fileHandler); |
72 Handler notFoundHander = new NotFound(luanHandler); | 87 Handler notFoundHander = new NotFound(luanHandler); |
73 notFoundHander = new ContentTypeHandler(notFoundHander); | 88 notFoundHander = new ContentTypeHandler(notFoundHander); |
74 handler = new ListHandler( handler, dirHandler, notFoundHander ); | 89 handler = new ListHandler( handler, dirHandler, notFoundHander ); |
90 Handler auth = new BasicAuthHandler(handler,"Private","admin",password); | |
91 handler = new RegexHandler("^/private/",auth,handler); | |
75 handler = new HeadersHandler(handler); | 92 handler = new HeadersHandler(handler); |
76 handler = new SafeHandler(handler); | 93 handler = new SafeHandler(handler); |
77 handler = new LogHandler(handler,LogHandler.dirLogger(new File(logDir),days30)); | 94 handler = new LogHandler(handler,LogHandler.dirLogger(new File(logDir),days30)); |
78 | 95 |
79 return new MyHandler(handler,luanHandler); | 96 return new MyHandler(handler,luanHandler); |
98 } | 115 } |
99 | 116 |
100 public static Object callSite(String domain,String fnName,Object... args) throws LuanException { | 117 public static Object callSite(String domain,String fnName,Object... args) throws LuanException { |
101 MyHandler handler = (MyHandler)domainHandler.getHandler(domain); | 118 MyHandler handler = (MyHandler)domainHandler.getHandler(domain); |
102 return handler.luanHandler.call_rpc(fnName,args); | 119 return handler.luanHandler.call_rpc(fnName,args); |
103 } | |
104 | |
105 private static void initLuan(Luan luan,String dir,String domain) { | |
106 LuanLogger.startThreadLogging(luan); | |
107 try { | |
108 LuanFunction fn = Luan.loadClasspath(luan,"luan/host/init.luan"); | |
109 fn.call(luan,dir,domain); | |
110 } catch(LuanException e) { | |
111 throw new LuanRuntimeException(e); | |
112 } finally { | |
113 LuanLogger.endThreadLogging(); | |
114 } | |
115 security(luan,dir); | |
116 } | 120 } |
117 | 121 |
118 public static void removeHandler(String domain) { | 122 public static void removeHandler(String domain) { |
119 domainHandler.removeHandler(domain); | 123 domainHandler.removeHandler(domain); |
120 } | 124 } |