Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Serializable to the user data. #178

Merged
merged 1 commit into from
Dec 4, 2018
Merged

Conversation

dfredell
Copy link
Contributor

I was tasked with implementing a custom shiro sessionDAO so we can share user session between our DropWizard web application servers. I was getting java.io.NotSerializableException: com.auth0.json.mgmt.users.User errors so I tried a few different workarounds like using Jackson's ObjectMapper to serialize the data, but that had its own complications (mainly SimplePrincipalCollection.realmPrincipals didn't get serialized.)
With this change I'm now able to serialize my org.apache.shiro.session.mgt.SimpleSession and send it to other webservers to create a HA environment.

Here is the stacktrace I was getting (with -Dsun.io.serialization.extendedDebugInfo=true enabled)


WARN  [2018-11-30 18:36:31,949]: Unable to update session org.apache.shiro.session.mgt.SimpleSession,id=8f1713bc-b59f-49b5-b13d-1234567890 in the database
! java.io.NotSerializableException: com.auth0.json.mgmt.users.User
! - custom writeObject data (class "java.util.HashSet")
! - object (class "java.util.LinkedHashSet", [<PRINCIPAL REDACTED>, <SESSION REDACTED>, {access_token=<PRINCIPAL REDACTED>, id_token=<SESSION REDACTED>, refresh_token=null, sub=auth0|<ID REDACTED>, email_verified=true, updated_at=2018-11-30T18:36:17.534Z, nickname=<EMAIL REDACTED>, name=<EMAIL REDACTED>@certusoft.com, picture=https://s.gravatar.com/avatar/<AVATAR REDACTED>, email=<EMAIL REDACTED>@certusoft.com}, com.auth0.json.mgmt.users.User@49729f39, com.auth0.json.auth.UserInfo@3cd9b149, <EMAIL REDACTED>@certusoft.com, <EMAIL REDACTED>@certusoft.com:<EMAIL REDACTED>@certusoft.com:YES])
! - custom writeObject data (class "java.util.HashMap")
! - object (class "java.util.LinkedHashMap", {<OUR AUTH CLASS>_1=[<PRINCIPAL REDACTED>, <SESSION REDACTED>, {access_token=<PRINCIPAL REDACTED>, id_token=<SESSION REDACTED>, refresh_token=null, sub=auth0|<ID REDACTED>, email_verified=true, updated_at=2018-11-30T18:36:17.534Z, nickname=<EMAIL REDACTED>, name=<EMAIL REDACTED>@certusoft.com, picture=https://s.gravatar.com/avatar/<AVATAR REDACTED>, email=<EMAIL REDACTED>@certusoft.com}, com.auth0.json.mgmt.users.User@49729f39, com.auth0.json.auth.UserInfo@3cd9b149, <EMAIL REDACTED>@certusoft.com, <EMAIL REDACTED>@certusoft.com:<EMAIL REDACTED>@certusoft.com:YES]})
! - field (class "org.apache.shiro.subject.SimplePrincipalCollection", name: "realmPrincipals", type: "interface java.util.Map")
! - custom writeObject data (class "org.apache.shiro.subject.SimplePrincipalCollection")
! - object (class "org.apache.shiro.subject.SimplePrincipalCollection", <PRINCIPAL REDACTED>,<SESSION REDACTED>,{access_token=<PRINCIPAL REDACTED>, id_token=<SESSION REDACTED>, refresh_token=null, sub=auth0|<ID REDACTED>, email_verified=true, updated_at=2018-11-30T18:36:17.534Z, nickname=<EMAIL REDACTED>, name=<EMAIL REDACTED>@certusoft.com, picture=https://s.gravatar.com/avatar/<AVATAR REDACTED>, email=<EMAIL REDACTED>@certusoft.com},com.auth0.json.mgmt.users.User@49729f39,com.auth0.json.auth.UserInfo@3cd9b149,<EMAIL REDACTED>@certusoft.com,<EMAIL REDACTED>@certusoft.com:<EMAIL REDACTED>@certusoft.com:YES)
! - custom writeObject data (class "java.util.HashMap")
! - object (class "java.util.HashMap", {org.apache.shiro.subject.support.DefaultSubjectContext_PRINCIPALS_SESSION_KEY=<PRINCIPAL REDACTED>,<SESSION REDACTED>,{access_token=<PRINCIPAL REDACTED>, id_token=<SESSION REDACTED>, refresh_token=null, sub=auth0|<ID REDACTED>, email_verified=true, updated_at=2018-11-30T18:36:17.534Z, nickname=<EMAIL REDACTED>, name=<EMAIL REDACTED>@certusoft.com, picture=https://s.gravatar.com/avatar/<AVATAR REDACTED>, email=<EMAIL REDACTED>@certusoft.com},com.auth0.json.mgmt.users.User@49729f39,com.auth0.json.auth.UserInfo@3cd9b149,<EMAIL REDACTED>@certusoft.com,<EMAIL REDACTED>@certusoft.com:<EMAIL REDACTED>@certusoft.com:YES})
! - custom writeObject data (class "org.apache.shiro.session.mgt.SimpleSession")
! - root object (class "org.apache.shiro.session.mgt.SimpleSession", org.apache.shiro.session.mgt.SimpleSession,id=8f1713bc-b59f-49b5-b13d-7bd782be7c1e)
! at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1182)
! at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
! at java.util.HashSet.writeObject(HashSet.java:288)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)
! at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
! at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
! at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
! at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
! at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
! at java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
! at java.util.HashMap.writeObject(HashMap.java:1363)
! at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)
! at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
! at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
! at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
! at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
! at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
! at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
! at org.apache.shiro.subject.SimplePrincipalCollection.writeObject(SimplePrincipalCollection.java:274)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)
! at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
! at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
! at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
! at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
! at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
! at java.util.HashMap.internalWriteEntries(HashMap.java:1790)
! at java.util.HashMap.writeObject(HashMap.java:1363)
! at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)
! at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
! at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
! at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
! at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
! at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
! at org.apache.shiro.session.mgt.SimpleSession.writeObject(SimpleSession.java:461)

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dfredell do you think it would be fine to skip adding the serialVersionUID field?

@dfredell
Copy link
Contributor Author

dfredell commented Dec 3, 2018

O ya totally fine. I'll remove them, one sec.

@dfredell
Copy link
Contributor Author

dfredell commented Dec 3, 2018

Should I merge auth0's master into my branch so it passes code coverage?

@lbalmaceda
Copy link
Contributor

Sure, go ahead and rebase 👍

@lbalmaceda lbalmaceda added this to the v1-Next milestone Dec 3, 2018
@lbalmaceda lbalmaceda merged commit 0d9f0cc into auth0:master Dec 4, 2018
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.10.0 Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants