我在我的应用程序中使用Spring 3和Spring Security。现在,我正在使用Web表单登录。我正在创建一个需要用户身份验证的Web服务,但我不知道如何启用它。这些是Spring安全性的设置:
<form-login login-page="/home.htm" default-target-url="/home/index.htm"
always-use-default-target="true" authentication-failure-url="/home.htm?authfailed=true" />
<logout invalidate-session="true" logout-success-url="/home.htm"
logout-url="/j_spring_security_logout" />
这是将接收用户电子邮件和密码并对用户进行身份验证的Web服务方法:
@RequestMapping(value = "authenticate", method = RequestMethod.POST)
public @ResponseBody
Student authenticate(
@RequestParam(value = "username", required = true) String username,
@RequestParam(value = "password", required = true) String password) {
//Authenticate user
//Do other stuff
}
如何使用上述方法对用户进行身份验证。在身份验证之后,对API的后续调用会有该用户的会话吗?