i have the following customized security controller using the secure module for play:
public class Security extends Secure.Security {
static boolean authenticate(String username, String password) {
validation.required(username);
validation.required(password);
if (!validation.hasErrors()) {
BetaUser user = BetaUser.find("username", username).first();
if (user != null && user.password.equals(password)) {
Session.current().put("userid", user.id);
return true;
}
return false;
}
else {
return false;
}
}
static void onAuthenticated() {
Series.userSeries();
}
static void onDisconnected() {
Application.index();
}
static boolean check(String profile) {
if ("admin".equals(profile)) {
return Security.connected().equals("admin");
}
return false;
}
}
In this case the validation mechanism in the authenticate methode works. When i use annotations the password parameter doesn`t get validatet anymore:
static boolean authenticate(@Required String username, @Required String password) {
if (!validation.hasErrors()) {
BetaUser user = BetaUser.find("username", username).first();
if (user != null && user.password.equals(password)) {
Session.current().put("userid", user.id);
return true;
}
return false;
}
else {
return false;
}
}
The strange thing is, that the username validation actually does work (error when username is empty). When only the password is left empty the validation has no errors…
I hope that you can help me.
After I dig around,
Validating HTTP data with play
Ref : http://www.playframework.org/documentation/1.2.4/validation
Before call your implement method, it call authenticate method in Secure class first. So, this it why annotation it not works in your implement method.
Your can see this thread for deep reason why it not works -> parameter validation with net.sf.oval (in play framework)