Spring 会话休息和 AuthenticationManager

Spring Session Rest and AuthenticationManager

来自 Spring 会话休息示例:http://docs.spring.io/spring-session/docs/current/reference/html5/guides/rest.html

我已经在 Cloud Foundry 上部署了示例,它可以正常工作。 我想知道会话如何使用 Spring Security AuthenticationManager 来验证第二个请求中的 x-auth-token。 我检查了 Spring 会话中的代码,但没有找到任何详细信息。

据我了解,身份验证管理器将通过 x-auth-token 在 SessionRepository 中查找会话。

谁能告诉我 Spring Session Rest 中的身份验证是如何工作的?

实际上,就 Spring 安全性而言,与不使用 Spring Session(即使用 Servlet 容器的内部 session 存储和 JSESSIONID cookie)。

Spring Session 使用 org.springframework.session.web.http.SessionRepositoryFilter 将 Servlet 容器的 HttpSession 实现替换为 Spring Session 支持的自定义实现。此过滤器还提供 HttpSessionStrategy(基于 cookie,或者像您的示例中那样,基于 HTTP 请求 header)将您提供的信息(同样,通过 cookie 或 header)关联到session 存储在 SessionRepository 执行你的选择。之后,这完全取决于您的应用程序如何使用 session.

请注意,Spring 安全性的 AuthenticationManager 仅处理对提供的 Authentication 令牌的身份验证请求。它没有任何 session 或任何其他 web/Servlet API 相关知识。