I want to write a servlet that wraps around a set of resources and needs to protect them with basic HTTP auth; the submitted username/pass will be checked against the backend database before serving the file.
Does anyone have any working examples of this? I tried the sample at http://www.coderanch.com/t/352345/Servlets/java/HTTP-basic-authentication-Web-Applications but it kept returning an IllegalStateException
in the sendError
call.
Here is some code that returns a Credential object (bean object holding login and password).
It works well, even with a password as funky as :&=/?é$£.
Here is a basic unit test for the class, using jMock: