我有一個couchapp,我想通過Play來控制訪問權限!在每個用戶的基礎上。我的計劃是在端口xxxx上託管couchapp,該端口只能在內部訪問,並託管Play!在端口80Play Framework - 使用會話身份驗證的代理請求
在Apache中我會做這樣的,
ProxyPass /couchapp http://localhost:xxxx
ProxyPassReverse /couchapp http://localhost:xxxx
但有這種方法不需要認證。我看到Play!有一些代理功能,但我不知道如何添加用戶身份驗證到此,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
}
謝謝!
我更新了問題。我想玩!檢查會話以查看用戶是否已登錄。然後,將用戶引導至couchapp,或要求用戶登錄。 – sissonb