@Check (and its associated method) is never run
I have a Security class that looks like this:
package controllers;
import play.Logger;
public class Security extends Secure.Security {
static boolean authenticate(String username, String password) {
return password.equals("banan");
}
static boolean check(String profile) {
Logger.info("profile: %s", profile);
if ("user".equals(profile)) {
Logger.info("connected: %s", connected());
return connected().equals("user");
}
return false;
}
static void onAuthenticated() {
Logger.info("Login by user %s", connected());
}
static void onCheckFailed() {
Logger.info(开发者_如何学C"Check failed!", "omg");
}
static void onDisconnect() {
Logger.info("Logout by user %s", connected());
}
static void onCheckFailed(String profile) {
Logger.warn("Failed auth for profile %s", profile);
forbidden();
}
}
And a Controller that looks like this:
@Check("user")
@With(Security.class)
public class Person extends Controller {
public static void create() {
List<models.person.Person> persons = models.person.Person.find(
"order by createdAt desc").fetch(10);
render(persons);
}
}
The check method never gets called. Not even the checkAccess (in the Secure class) gets called. Any ideas?
From looking at the code you have posted, the one error I can see (if you compare to the instructions on the secure module page), is that you should use @With(Secure.class)
.
So, change your code from
@Check("user")
@With(Security.class)
public class Person extends Controller {
to
@Check("user")
@With(Secure.class)
public class Person extends Controller {
精彩评论