playframework 2.0 - Play Framework - Authentication for Assets -
I'm developing an app where I want to limit access to properties. I have created an additional folder
secret /
which holds the data
and the controller media
/ media / secret / * file controller. Media. File (File) Expands Public Class Media Controller {@Profile the public results file (string file) {string path = / home / afu / secret path / filef = new file (Path, file); If (! F.exists ()) {return notound (); } The return is OK (f, true); }
This type of work, the only problem is that there is no etag or cache control to check the assets. Scala implementation () Everything has already been developed here. My question is
- Should I write additional code to implement Etag and CashControl? if so, how? I can not read Scala
- If there is any way to use the property class, how should it work? Returning action @ will not trigger @ so that I can validate whether it is ok or not.
You can use the action structure, see:
(1) New verb
def only unauthenticated [A] (Action: Action [A]) = Action Async (Action Pursuit) {Request = & gt; Request.session.get ("username") match {case something (username) = & gt; User.findByU Name (Username) Match {Case Something (User) = & gt; Action (request) case _ = & gt; Future. Successful (forbidden (views.html.defaultpages.unauthorized.render ()))} Case _ = & gt; Future. Successful redirects (request. Path.path))}}
(2) controller action
def privateAsset (file: string ) = Only authorized {assets} .et (s "/ private", file)}
(3) root
received / private / * file controller. Application: PrivateAsset (File)
Comments
Post a Comment