基于表单的身份验证如何在 spring 安全性中发挥作用?

How does form based authentication work in spring security?

post 请求被发送到一些 /login url,具有有效的 usernamepassword 参数。

应该怎么回应?一定要包含jsessionidor/and其他信息吗?

安全性如何spring识别当前用户?它使用 jsessionid 过滤还是 "looks" 其他信息(客户 header、cookies 等)?通过“jsessionid过滤”我的意思是(可能是错误的)当用户成功登录时spring安全保存jsessionid到成功验证session 列出其他信息(如角色)并将其保存到 session object 中。是不是这样?

如果有人一步步提供带有身份验证的 raw http requests/responses 就好了,例如 post 请求应该包含什么以及相应的响应包含。此外,对受保护资源的请求需要包含什么(一些 header、cookie、jsession 或其他)?

我会尽力帮助你:

首先: 响应为该路径设置了一个 cookie,在我的例子中,我的应用程序在 localhost:port/CambioClaveDist 中,所以当 Spring 安全验证我的用户时,它会为该路径创建一个新的 JSESSIONID:Set-Cookie:"JSESSIONID=96ABDF25EE278DD69DD1A0400702E416; Path=/CambioClaveDist"

其次:Spring用JSESSIONID标识一个经过身份验证的用户,是的。

第三个: 我有一个 http request/post 例子:
身份验证 post:

POST http://localhost:8080/CambioClaveDist/j_spring_security_check
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://localhost:8080/CambioClaveDist/index.htm?logout=true
Connection: keep-alive

Content-Type: application/x-www-form-urlencoded
Content-Length: 92

_csrf=fbd07004-cc30-4ef6-9bfb-a00ae8f8819f&username=user&password=pass&sSubmit=Enviar

请求保护 url:

GET http://localhost:8080/CambioClaveDist/main/index.htm

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://localhost:8080/CambioClaveDist/index.htm?logout=true
Cookie: JSESSIONID=96ABDF25EE278DD69DD1A0400702E416
Connection: keep-alive