ninjaframework/ninja — pull request #205 by gitblit (2014-08-01 15:35:22+00:00)
Title: Add Http Basic Authentication filter and proper 401 unauthorized support

Ninja would benefit from optional http basic authentication, and here it is. :)

**Step 1:** You need to bind a credentials validator:

```java
public class Module extends AbstractModule {

@Override
protected void configure() {

// bind a UsernamePasswordValidator
bind(UsernamePasswordValidator.class).toInstance(new UsernamePasswordValidator() {

@Override
public boolean validateCredentials(String username, String password) {
return "user".equals(username) && "password".equals(password);
}
});
}
}
```

**Step 2:** Annotate protected resources as desired `@FilterWith(BasicAuthFilter.class)`

```java
@FilterWith(BasicAuthFilter.class)
public class MyProtectedApiController {
}
```

**Note**
I found a discrepancy in *forbidden* message reporting which I have addressed. Hopefully that was correct.