/ / Wie implementiere ich HTTP Basic Auth in Play Framework 1.2? - playframework, playframework-1.x, http-basic-authentication

Wie implementiert man HTTP Basic Auth in Play Framework 1.2? - playframework, playframework-1.x, http-basic-authentication

Ich habe diesen Beitrag gefunden, aber es ist auf Play 2.0 ausgerichtet.

Hat jemand dies für Play 1 getan (ich verwende 1.2.4-mbknor-3)?

Antworten:

6 für die Antwort № 1

Das Http.Request Objekt hat user und password Eigenschaften, die aus dem Authorization-Header ausgefüllt werden. Sie könnten so etwas tun:

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