Jackson Support

Spring Security 为持久化与 Spring Security 相关的类提供 Jackson 支持。使用分布式会话(会话复制、Spring Session 等)处理与 Spring Security 相关的类时,此支持可以提升序列化的性能。

要使用它,请使用 ObjectMapper ( jackson-databind)向 SecurityJackson2Modules.getModules(ClassLoader) 注册:

ObjectMapper mapper = new ObjectMapper();
ClassLoader loader = getClass().getClassLoader();
List<Module> modules = SecurityJackson2Modules.getModules(loader);
mapper.registerModules(modules);

// ... use ObjectMapper as normally ...
SecurityContext context = new SecurityContextImpl();
// ...
String json = mapper.writeValueAsString(context);

以下 Spring Security 模块提供 Jackson 支持:

  • spring-security-core ({security-api-url}org/springframework/security/jackson2/CoreJackson2Module.html[CoreJackson2Module])

  • spring-security-web ({security-api-url}org/springframework/security/web/jackson2/WebJackson2Module.html[WebJackson2Module], {security-api-url}org/springframework/security/web/jackson2/WebServletJackson2Module.html[WebServletJackson2Module], {security-api-url}org/springframework/security/web/server/jackson2/WebServerJackson2Module.html[WebServerJackson2Module])

  • oauth2client ({security-api-url}org/springframework/security/oauth2/client/jackson2/OAuth2ClientJackson2Module.html[OAuth2ClientJackson2Module])

  • spring-security-cas ({security-api-url}org/springframework/security/cas/jackson2/CasJackson2Module.html[CasJackson2Module])