Mercurial Hosting > luan
view src/goodjava/webserver/handlers/BasicAuthHandler.java @ 1648:224af797b1f9
Mainly small install script improvements
- Consistent usage of `$LUANHOME`, removed reliance on current directory.
- Made Luan build and install fine (on Linux) without requiring launching it via sudo. Only asks to elevate privileges if installation failed.
- Minor spelling mistake fix.
author | Fox |
---|---|
date | Mon, 28 Mar 2022 18:00:12 +0200 |
parents | 557bb90b70d7 |
children |
line wrap: on
line source
package goodjava.webserver.handlers; import goodjava.util.GoodUtils; import goodjava.webserver.Handler; import goodjava.webserver.Request; import goodjava.webserver.Response; import goodjava.webserver.Status; public final class BasicAuthHandler implements Handler { private final Handler handler; private final String realm; private final String match; public BasicAuthHandler(Handler handler,String realm,String username,String password) { this.handler = handler; this.realm = realm; this.match = GoodUtils.base64Encode(username+":"+password); } private Response unauthorized() { Response response = new Response(); response.status = Status.UNAUTHORIZED; response.headers.put("WWW-Authenticate","Basic realm=\""+realm+"\""); return response; } public Response handle(Request request) { String auth = (String)request.headers.get("Authorization"); if( auth==null ) return unauthorized(); String[] a = auth.split(" "); if( a.length!=2 || !a[0].equals("Basic") || !a[1].equals(match) ) return unauthorized(); Response response = handler.handle(request); if( response != null ) response.headers.put("X-Accel-Expires","0"); return response; } }