steppenwells/guardian-management — pull request #1 by bruntonspall (2012-12-07 13:22:49+00:00)
Title: Authenticate endpoints

This adds basic authentication to specific management endpoints.

It is designed to achieve 2 aims:

1. Passwords between development and production will be different, meaning a script or process that automatically sets switches cannot be accidentally run on the wrong environment.
2. By protecting pages that can cause a change in behaviour, we can open the management ports a little wider without worry that any random person can switch off the website.

Because we want to trigger switches and things from simple scripts, we chose Basic auth as it is well defined and simple to implement. OpenId authentication from Google for example, is impossible to do from curl at the command line.

The code tries to distinguish the responsibilities appropriately.
A page is responsible for saying that it needs to be authenticated for access, it does not care how and whether that actually happens, it's merely a property for whatever renders pages.
The Management Filter is responsible for deciding if a page should be dispatched to, and therefore implements the authentication mechanism in it's own way. However, in order to allow many different ways of validating usernames and passwords, it depends on a user provider to authenticate a username and password.
The user provider should be provided by the app and is the apps responsibility how it authorises a username and password combination. Anything from always returning true, to matching a fixed in code string, to configuration files, to database lookups should be possible this way.

This pull request only updates the servlet-api branch to use authentication. All the hooks are there for play and internal servers to use if they want, but I haven't got a working example to test, so haven't implemented them. Additions to this pull request, or 5 minutes of your time is welcome.

I added some tests for the servlet-api dispatcher, which I think covers most of the changes I did. They could probably be nicer.