Skip to content

Instantly share code, notes, and snippets.

@danielberndt
Created February 14, 2012 21:24
Show Gist options
  • Save danielberndt/1830585 to your computer and use it in GitHub Desktop.
Save danielberndt/1830585 to your computer and use it in GitHub Desktop.
Bug with play2.0 action composition
public class Auth extends Controller {
@With(RolesAction.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MinRole {
Role value() default Role.Admin;
}
public static class RolesAction extends Action<MinRole> {
public Result call(Http.Context ctx) throws Throwable {
User user = User.find.ref(1L);// <--- problem arises here
if (user==null || !user.role.greaterEqual(configuration.value())) {
return unauthorized("no access for you!");
}
return delegate.call(ctx);
}
}
@MinRole(Role.Admin)
public static Result adminOnly() {
return ok();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment