日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Security + Session Redis——JSON序列化错误[The class xxx and name of xxx is not whitelisted. ]解决方案

發(fā)布時(shí)間:2024/10/5 javascript 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Security + Session Redis——JSON序列化错误[The class xxx and name of xxx is not whitelisted. ]解决方案 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前置

Spring Security + Spring Session + Redis——【SecurityContext】和【AuthenticationToken】JSON反序列化問題解決方案

問題描述

Caused by: java.lang.IllegalArgumentException: The class with com.hailiu.model.Role and name of com.hailiu.model.Role 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
?? ?at org.springframework.security.jackson2.SecurityJackson2Modules$WhitelistTypeIdResolver.typeFromId(SecurityJackson2Modules.java:252) ~[spring-security-core-5.3.5.RELEASE.jar:5.3.5.RELEASE]
?? ?at com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:154) ~[jackson-databind-2.11.3.jar:2.11.3]
?? ?at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:115) ~[jackson-databind-2.11.3.jar:2.11.3]
?? ?at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:99) ~[jackson-databind-2.11.3.jar:2.11.3]
?? ?at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeWithType(BeanDeserializerBase.java:1209) ~[jackson-databind-2.11.3.jar:2.11.3]
?? ?at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:292) ~[jackson-databind-2.11.3.jar:2.11.3]
?? ?... 63 common frames omitted

issues

https://github.com/spring-projects/spring-security/issues/9210

https://github.com/spring-projects/spring-security/issues/9210

問題分析

源代碼

@Overridepublic JavaType typeFromId(DatabindContext context, String id) throws IOException {DeserializationConfig config = (DeserializationConfig) context.getConfig();JavaType result = delegate.typeFromId(context, id);String className = result.getRawClass().getName();if (isWhitelisted(className)) {return result;}boolean isExplicitMixin = config.findMixInClassFor(result.getRawClass()) != null;if (isExplicitMixin) {return result;}JacksonAnnotation jacksonAnnotation = AnnotationUtils.findAnnotation(result.getRawClass(), JacksonAnnotation.class);if (jacksonAnnotation != null) {return result;}throw new IllegalArgumentException("The class with " + id + " and name of " + className + " 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");}

這異常不出現(xiàn)一共三個(gè)情況:

一、白名單的類

但是白名單不能繼承、添加操作

二、有對(duì)應(yīng)的Mixin類

三、有@JacksonAnnotation注解的類

Jackson的相關(guān)注解都有@JacksonAnnotation

解決方案

方法一

編寫一個(gè)Mixin類

參考:Spring Session & RedisでJacksonを使ったシリアライズを試してみる

方法二

在對(duì)應(yīng)類上加 Jackson Annotations的注解

參考文章

Spring Session & RedisでJacksonを使ったシリアライズを試してみる

總結(jié)

以上是生活随笔為你收集整理的Spring Security + Session Redis——JSON序列化错误[The class xxx and name of xxx is not whitelisted. ]解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。