mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-29 16:22:12 +00:00
find -name "*.adoc" | xargs -I{file} awk -v file={file} '/\[\[/ { gsub("\[|\]", ""); id=$0; gsub("./docs/modules/ROOT/pages/", "", file); gsub("\[|\]", ""); id=$0;getline;text=$0; sub("^=+ ","", text); print file > "build/ids/"id".id"; print text > "build/ids/"id".text" }' {file} find docs/modules -name "*.adoc"|while read adoc_file_to_replace; do echo "Replacing $adoc_file_to_replace" for id_file in build/ids/*.id; do id=$(basename $id_file | sed 's/\.id$//') xref_page=$(cat $id_file) if [[ "$adoc_file_to_replace" -ef "./docs/modules/ROOT/pages/$xref_page" ]] then echo " - Skipping same page refid $id " else sed -i -E "s%<<$id(|,([^,>]+))>>%xref:${xref_page}#${id}[\2]%g" $adoc_file_to_replace fi done done
48 lines
1.6 KiB
Plaintext
48 lines
1.6 KiB
Plaintext
[[jackson]]
|
|
= Jackson Support
|
|
|
|
Spring Security provides Jackson support for persisting Spring Security related classes.
|
|
This can improve the performance of serializing Spring Security related classes when working with distributed sessions (i.e. session replication, Spring Session, etc).
|
|
|
|
To use it, register the `SecurityJackson2Modules.getModules(ClassLoader)` with `ObjectMapper` (https://github.com/FasterXML/jackson-databind[jackson-databind]):
|
|
|
|
====
|
|
.Java
|
|
[source,java,role="primary"]
|
|
----
|
|
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);
|
|
----
|
|
|
|
.Kotlin
|
|
[source,kotlin,role="secondary"]
|
|
----
|
|
val mapper = ObjectMapper()
|
|
val loader = javaClass.classLoader
|
|
val modules: MutableList<Module> = SecurityJackson2Modules.getModules(loader)
|
|
mapper.registerModules(modules)
|
|
|
|
// ... use ObjectMapper as normally ...
|
|
val context: SecurityContext = SecurityContextImpl()
|
|
// ...
|
|
val json: String = mapper.writeValueAsString(context)
|
|
----
|
|
====
|
|
|
|
[NOTE]
|
|
====
|
|
The following Spring Security modules provide Jackson support:
|
|
|
|
- spring-security-core (`CoreJackson2Module`)
|
|
- spring-security-web (`WebJackson2Module`, `WebServletJackson2Module`, `WebServerJackson2Module`)
|
|
- xref:servlet/oauth2/oauth2-client.adoc#oauth2client[ spring-security-oauth2-client] (`OAuth2ClientJackson2Module`)
|
|
- spring-security-cas (`CasJackson2Module`)
|
|
====
|