I have static content configured like this:
ContextHandler staticContext = new ContextHandler();
staticContext.setContextPath("/");
staticContext.setResourceBase(".");
staticContext.setClassLoader(Thread.currentThread().getContextClassLoader());
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{"index.html"});
resourceHandler.setResourceBase(webDir);
staticContext.setHandler(resourceHandler);
And now I want to set Basic HTTP Auth for all my static files. How can I do this?
PS. I’m using embedded Jetty withour web.xml
Override
ResourceHandler#handle()with something like:The
Base64.decodeBase64above is from Apache Commons Codec. Of course you can find a library that does Basic Auth for you, but here you can see what happens under the covers. Another approach could be to use a Basic Auth filter and install that into your context.