I found this post, but it is aimed at Play 2.0.
Has anyone done this for Play 1 (I'm using 1.2.4-mbknor-3)?
The Http.Request object has user and password properties populated from the Authorization header. You could do something like this:
public class Application extends Controller {
private static final String WWW_AUTHENTICATE = "WWW-Authenticate";
private static final String REALM = "Basic realm=\"Your Realm Here\"";
@Before
static void authenticate() {
if (!("username".equals(request.user) && "password".equals(request.password))) {
response.setHeader(WWW_AUTHENTICATE, REALM);
error(401, "Unauthorized");
}
}
public static void index() {
renderText("Welcome!");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With