You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are able to serialize/deserialize the class Saml2Authentication and SimpleSaml2AuthenticatedPrincipal using an object mapper.
Current Behavior
We cannot whitelist SimpleSaml2AuthenticatedPrincipal as it is package private and the deserialization crashes.
Context
We are using spring-session-data-mongo to store the HttpSession in a mongo collection.
This approach uses a object mapper to convert it to JSON/BSON.
We can whitelist and fix the Saml2Authentication storage with the following kotlin snippets:
objectMapper.addMixIn(Saml2Authentication::class.java, Saml2AuthenticationMixin::class.java)
...
/** * Used to whitelist [Saml2Authentication] for [SecurityJackson2Modules].*/classSaml2AuthenticationMixin @JsonCreator constructor(
@JsonProperty("principal") principal:AuthenticatedPrincipal,
@JsonProperty("saml2Response") saml2Response:String,
@JsonProperty("authorities") authorities:Collection<GrantedAuthority>
) : Saml2Authentication(principal, saml2Response, authorities) // Nothing special
But I cannot add the following mixin as the class is package private:
/** * Used to whitelist [SimpleSaml2AuthenticatedPrincipal] for [SecurityJackson2Modules].*/classSimpleSaml2AuthenticatedPrincipalMixin// Nothing special
This is the exception we get without being able to whitelist the class:
com.fasterxml.jackson.databind.JsonMappingException: The class with
org.springframework.security.saml2.provider.service.authentication.SimpleSaml2AuthenticatedPrincipal and name of
org.springframework.security.saml2.provider.service.authentication.SimpleSaml2AuthenticatedPrincipal is not whitelisted. If you
believe this class is safe to deserialize, please provide an explicit mapping using Jackson annotations or by providing a Mixin. If
the serialization is only done by a trusted source, you can also enable default typing. See https://github.com/spring-projects
/spring-security/issues/4370 for details (through reference chain:
org.springframework.session.data.mongo.MongoSession["attrs"]->
java.util.HashMap["SPRING_SECURITY_CONTEXT"]->
org.springframework.security.core.context.SecurityContextImpl["authentication"]->
org.springframework.security.saml2.provider.service.authentication.Saml2Authentication["principal"])
We have a workaround by using plain Java serialization using the Serializable interface and the Spring boot utils SerializationUtils.serialize() and SerializationUtils.deserialize().
E.g.:
/** * Used to whitelist [Saml2Authentication] for [SecurityJackson2Modules].*/
@JsonDeserialize(using =SAMLAuthDeserializer::class)
@JsonSerialize(using =SAMLAuthSerializer::class)
classSaml2AuthenticationMixin
This approach works but is not ideal.
The text was updated successfully, but these errors were encountered:
@JoakimLofgren I think it was package-private while the name was under consideration.
Would you be able to submit a PR to change the class to be named DefaultSaml2AuthenticatedPrincipal (to match DefaultOAuth2AuthenticatedPrincipal) and make the class public?
Rename it to DefaultSaml2AuthenticatedPrincipal to be more in line with
the respective class in the OAuth2 module.
Also make the class public to be able to whitelist the SAML2 auth classes
in Jackson object mappers for deserialization in e.g. Spring Session MongoDB.
Closesspring-projectsgh-8852
Rename it to DefaultSaml2AuthenticatedPrincipal to be more in line with
the respective class in the OAuth2 module.
Also make the class public to be able to whitelist the SAML2 auth classes
in Jackson object mappers for deserialization in e.g. Spring Session MongoDB.
Closesgh-8852
Expected Behavior
We are able to serialize/deserialize the class
Saml2Authentication
andSimpleSaml2AuthenticatedPrincipal
using an object mapper.Current Behavior
We cannot whitelist
SimpleSaml2AuthenticatedPrincipal
as it is package private and the deserialization crashes.Context
We are using
spring-session-data-mongo
to store theHttpSession
in a mongo collection.This approach uses a object mapper to convert it to JSON/BSON.
We can whitelist and fix the Saml2Authentication storage with the following kotlin snippets:
But I cannot add the following mixin as the class is package private:
This is the exception we get without being able to whitelist the class:
We have a workaround by using plain Java serialization using the
Serializable
interface and the Spring boot utilsSerializationUtils.serialize()
andSerializationUtils.deserialize()
.E.g.:
This approach works but is not ideal.
The text was updated successfully, but these errors were encountered: