Configure Security Context in a Spring Boot with MongoDB Extension…
I get the following WARN and do not figure out how to configure the Security Context
2022-02-06 14:36:37.485 WARN 23153 --- [ main] o.a.e.e.AbstractEventStorageEngine : The default XStreamSerializer is used for events, whereas it is strongly recommended to configure the security context of the XStream instance.
org.axonframework.common.AxonConfigurationException: A default XStreamSerializer is used for events, without specifying the security context
...
...
2022-02-06 14:36:37.486 WARN 23153 --- [ main] o.a.e.e.AbstractEventStorageEngine : The default XStreamSerializer is used for snapshots, whereas it is strongly recommended to configure the security context of the XStream instance.
org.axonframework.common.AxonConfigurationException: A default XStreamSerializer is used for snapshots, without specifying the security context
at org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine$Builder.validate(AbstractEventStorageEngine.java:369) ~[axon-eventsourcing-4.5.8.jar:4.5.8]
Hello and welcome to the Axon community @c3smonkey !
It is a known issue. My recommendation is to secure the XStream instead of switching to Jackson. You can do so by configuring the classes it has access to. Here is an adapted example from a demo app I have. First, create a SecureXStreamSerializer:
public class SecureXStreamSerializer {
private static XStreamSerializer _instance;
public static XStreamSerializer get() {
if (_instance == null) {
_instance = secureXStreamSerializer();
}
return _instance;
}
private static XStreamSerializer secureXStreamSerializer() {
XStream xStream = new XStream();
xStream.setClassLoader(SecureXStreamSerializer.class.getClassLoader());
xStream.allowTypesByWildcard(new String[]{
"org.axonframework.**",
"THE.PACKAGE.OF.YOUR.APPLICATION.**",
"OTHER.PACKAGES.HAVING.SERIALIZABLE.CLASSES.**",
...
});
return XStreamSerializer.builder().xStream(xStream).build();
}
}