As an example of use, there is a case where the user is logged in as it is after the user registration is completed. In this case, the user does not explicitly enter the ID and password in a form or the like, but logs in programmatically.
To achieve this, in Servlet 3.0 and above, set Spring Security and then [HttpServletRequest # login (Java (TM) EE 7 Specification APIs)](http://docs.oracle.com/javaee/7/api/ Call javax / servlet / http / HttpServletRequest.html # login-java.lang.String-java.lang.String-).
@RequestMapping(...
public void index(HttpServletRequest request) {
try {
request.login("username", "password");
} catch (ServletException e) {}
}
As described in Spring Security Reference --15.2.2 HttpServletRequest.login (String, String) , Due to the cooperation function of Spring Security and Servlet API. The mechanism is that when you call the login method, the login process is performed using the currently valid AuthenticationManager
on the back side.
Recommended Posts