Serialization Issue: Org. Springframework. Dao. Support. Persistenceexceptiontranslationinterceptor

Serialization Issue: Org. Springframework. Dao. Support. Persistenceexceptiontranslationinterceptor

I am getting below exception while serializing authentication Object in JdbcTokenStore.java for oauth2 password flow.

    INFO org.springframework.security.oauth2.provider.endpoint.TokenEndpoint - Handling error: IllegalArgumentException, java.io.NotSerializableException: org.springframework.dao.support.PersistenceExceptionTranslationInterceptor
        - field (class "org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor", name: "advice", type: "class org.springframework.dao.support.PersistenceExceptionTranslationInterceptor")
        - object (class "org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor", org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor@188598ad)
        - element of array (index: 0)
        - array (class "[Lorg.springframework.aop.Advisor;", size: 1)
        - field (class "org.springframework.aop.framework.AdvisedSupport", name: "advisorArray", type: "class [Lorg.springframework.aop.Advisor;")
        - object (class "org.springframework.aop.framework.ProxyFactory", org.springframework.aop.framework.ProxyFactory: 0 interfaces []; 1 advisors [org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor@188598ad]; targetSource [SingletonTargetSource for target object [com.citruspay.um.config.dao.UMConfigProperties@4e8bc1c1]]; proxyTargetClass=true; optimize=false; opaque=false; exposeProxy=false; frozen=false)
        - field (class "org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor", name: "advised", type: "class org.springframework.aop.framework.AdvisedSupport")
        - object (class "org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor", org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor@5be0dce3)
        - field (class "com.citruspay.um.config.dao.UMConfigProperties$$EnhancerBySpringCGLIB$$e4b0fa51", name: "CGLIB$CALLBACK_0", type: "interface org.springframework.cglib.proxy.MethodInterceptor")
        - object (class "com.citruspay.um.config.dao.UMConfigProperties$$EnhancerBySpringCGLIB$$e4b0fa51", com.citruspay.um.config.dao.UMConfigProperties@4e8bc1c1)
        - field (class "com.citruspay.common.security.auth.CPUserDetailsImpl", name: "umConfigProperties", type: "class com.citruspay.um.config.dao.UMConfigProperties")
        - object (class "com.citruspay.common.security.auth.CPUserDetailsImpl", com.citruspay.common.security.auth.CPUserDetailsImpl@5a328ad9)
        - field (class "com.citruspay.common.security.auth.CPUserDetailsImpl$1", name: "this$0", type: "class com.citruspay.common.security.auth.CPUserDetailsImpl")
        - object (class "com.citruspay.common.security.auth.CPUserDetailsImpl$1", com.citruspay.common.security.auth.CPUserDetailsImpl$1@37ddcf60)
        - custom writeObject data (class "java.util.ArrayList")
        - object (class "java.util.ArrayList", [com.citruspay.common.security.auth.CPUserDetailsImpl$1@37ddcf60, com.citruspay.common.security.auth.CPUserDetailsImpl$1@861404d, com.citruspay.common.security.auth.CPUserDetailsImpl$1@7c17f286, com.citruspay.common.security.auth.CPUserDetailsImpl$1@e33e97c])
        - field (class "java.util.Collections$UnmodifiableCollection", name: "c", type: "interface java.util.Collection")
        - object (class "java.util.Collections$UnmodifiableList", [com.citruspay.common.security.auth.CPUserDetailsImpl$1@37ddcf60, com.citruspay.common.security.auth.CPUserDetailsImpl$1@861404d, com.citruspay.common.security.auth.CPUserDetailsImpl$1@7c17f286, com.citruspay.common.security.auth.CPUserDetailsImpl$1@e33e97c])
        - field (class "org.springframework.security.authentication.AbstractAuthenticationToken", name: "authorities", type: "interface java.util.Collection")
        - root object (class "org.springframework.security.oauth2.provider.OAuth2Authentication", org.springframework.security.oauth2.provider.OAuth2Authentication@58609f14: Principal: 23812803521413120; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: com.citruspay.common.security.auth.CPUserDetailsImpl$1@37ddcf60, com.citruspay.common.security.auth.CPUserDetailsImpl$1@861404d, com.citruspay.common.security.auth.CPUserDetailsImpl$1@7c17f286, com.citruspay.common.security.auth.CPUserDetailsImpl$1@e33e97c)

Does anybody knows what does it means? Which class is not serializable and how can I solve it?

P.S. I have tried by extending PersistenceExceptionTranslationInterceptor.java named CustomPersistenceExceptionTranslationInterceptor.java by serializing and configured it instead of PersistenceExceptionTranslationInterceptor, But it didn't work.

3 Answers

Your "authentication Object" should implement Serializable interface and all members of ObjectImpl should be serializable themselves.

2

After trying @Transient or transient for field UMConfigProperties instance, I have figured it out by overriding writeObject(java.io.ObjectOutputStream stream) and readObject(java.io.ObjectInputStream stream). This approach is good when you have less number of variable in to be serialized class. But if there are more number of variables, then I think we should use @Transient annotation or transient keyword. Can anyone explain more about this?

0

Please implement Serializable interface and all members of ObjectImpl should be serializable themselves.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.