我有一个沙发应用程序,我想通过 Play 控制对它的访问!在每个用户的基础上。我的计划是在端口 xxxx 上托管 couchapp,该端口只能在内部访问,并托管 Play!在 80 端口上。
在 Apache 我会这样做,
ProxyPass /couchapp http://localhost:xxxx
ProxyPassReverse /couchapp http://localhost:xxxx
但是这种方法没有身份验证。我看到了播放!有一些代理功能,但无论如何我都看不到要为此添加用户身份验证,http://www.playframework.com/documentation/2.0/HTTPServer
知道如何将用户身份验证添加到 Play!代理人?代码看起来像这样。
// Routes all request to http://localhost:xxxx/ if authenticated
public static Result useProxy() {
if (!session("authorized").equals("true")) {
String pingURL = "";
return redirect(pingURL); // will call pingCallback after login
}
return ok(); // take the original request to /couchapp/xxxx.asset and proxy it to http://localhost:xxxx/xxxx.asset
}
public static Result pingCallback() {
Form<PingResponse> pingResponseForm = Form.form(PingResponse.class);
PingResponse pingResponse = pingResponseForm.bindFromRequest().get();
if (!pingResponse.isAuthorized()) {
return unauthorized();
} else {
session("authorized", "true");
}
return ok(); // take the original request to /couchapp/xxxx.asset and proxy it to http://localhost:xxxx/xxxx.asset
}
谢谢!