Skip to content

Instantly share code, notes, and snippets.

@brettbatie
Created August 10, 2015 22:12
Show Gist options
  • Save brettbatie/48443fb111b44c0cedc5 to your computer and use it in GitHub Desktop.
Save brettbatie/48443fb111b44c0cedc5 to your computer and use it in GitHub Desktop.
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface NoAuthRequired {}
public class RequestHandler extends DefaultHttpRequestHandler {
@Override
public Action createAction(Http.Request request, Method actionMethod) {
return new Action.Simple() {
@Override
public F.Promise<Result> call(Http.Context ctx) throws Throwable {
// if the action is annotated with @NoAuthRequired or user is logged in delegate to it
if (actionMethod.isAnnotationPresent(NoAuthRequired.class) || ctx.session().containsKey("loggedIn")) {
return delegate.call(ctx);
}
// otherwise, block access
else {
return F.Promise.pure(forbidden("You're not allowed"));
}
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment