3
I found this post,但它是針對Play 2.0的。如何在Play Framework 1.2中實現HTTP Basic Auth?
有沒有人爲Play 1(我正在使用1.2.4-mbknor-3)做這個工作?
I found this post,但它是針對Play 2.0的。如何在Play Framework 1.2中實現HTTP Basic Auth?
有沒有人爲Play 1(我正在使用1.2.4-mbknor-3)做這個工作?
Http.Request
對象具有從授權標頭填充的user
和password
屬性。你可以這樣做:
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!");
}
}