Created
June 6, 2013 09:21
-
-
Save guillaumebort/5720350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import play.*; | |
import play.mvc.*; | |
import views.html.*; | |
public class Application extends Controller { | |
public static Result index(String name) { | |
return (new Secured(name) { | |
public Result apply() { | |
return ok(index.render("Your new application is ready.")); | |
} | |
}).run(); | |
} | |
/** -- Secured Action, should be packaged elsewhere -- **/ | |
static abstract class Secured extends Action.Simple { | |
private final String connectedUser; | |
public Secured(String connectedUser) { | |
this.connectedUser = connectedUser; | |
} | |
public Result call(Http.Context ctx) throws Throwable { | |
if("Bob".equals(connectedUser)) { | |
return apply(); | |
} else { | |
return forbidden("Please login as an authorized user!"); | |
} | |
} | |
public abstract Result apply(); | |
public Result run() { | |
try { | |
return call(ctx()); | |
} catch(Throwable e) { | |
throw new RuntimeException("Caught in Secured", e); | |
} | |
} | |
} | |
/** -- **/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment