我想知道如何在Spring Security處理之前在登錄表單上進行額外驗證。我正在考慮一些LoginController,LoginForm bean,但我不知道如何將它們結合在一起,如何配置它工作。下面是我的「願景」。我已經搜索了一些例子如何在Spring Security中做到這一點,但無法找到。有人可以幫忙嗎?如何在Spring Security登錄表單中額外驗證?
LoginForm的豆:
public class LoginForm {
private String j_username;
private String j_password;
@NotEmpty
private Boolean acceptTerms;
public String getJ_password() {
return j_password;
}
public String getJ_username() {
return j_username;
}
public void setJ_password(String j_password) {
this.j_password = j_password;
}
public void setJ_username(String j_username) {
this.j_username = j_username;
}
public Boolean getAcceptTerms() {
return acceptTerms;
}
public void setAcceptTerms(Boolean accept) {
this.acceptTerms = acceptTerms;
}
}
形式:
<c:url value="/login" var="secureUrl"/>
<form:form id="jf" commandName="loginForm" action="${secureUrl}" method="post">
<form:input path="j_username"/>
<form:input path="j_password"/>
<form:checkbox path="acceptTerms"/>
</form>
的LoginController:
@Controller
class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String logging(@ModelAttribute @Valid LoginForm loginForm) {
...
}
}