Playframework 如何在Play Framework 1.2中实现HTTP基本身份验证?

Playframework 如何在Play Framework 1.2中实现HTTP基本身份验证?,playframework,playframework-1.x,basic-authentication,Playframework,Playframework 1.x,Basic Authentication,,但它的目标是播放2.0 是否有人在播放1时这样做过(我使用的是1.2.4-mbknor-3)?Http.Request对象具有从授权标头填充的用户和密码属性。你可以这样做: public class Application extends Controller { private static final String WWW_AUTHENTICATE = "WWW-Authenticate"; private static final String REALM = "Basic

,但它的目标是播放2.0


是否有人在播放1时这样做过(我使用的是1.2.4-mbknor-3)?

Http.Request对象具有从授权标头填充的
用户
密码
属性。你可以这样做:

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!");
  }
}