joscha / play-authenticate

An authentication plugin for Play Framework 2.x (Java)
http://joscha.github.com/play-authenticate/
Other
807 stars 367 forks source link

Exception with Twitter provider/Oauth1 & memcached. #276

Closed tuanvm closed 8 years ago

tuanvm commented 9 years ago

Hi Joscha,

I used memcached instead of Ehcache, and i've got an exception when trying to login with Twitter provider. It might happen with Oauth1 too. Here are the exception log:

2015-08-20T08:03:20.909420+00:00 app[web.2]: [error] m.plugin - An error has occured while getting the value from memcached. ct=Any
2015-08-20T08:03:20.909428+00:00 app[web.2]:    at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909426+00:00 app[web.2]: java.util.concurrent.ExecutionException: java.io.InvalidClassException: com.feth.play.module.pa.providers.oauth1.OAuth1AuthProvider$SerializableRequestToken; no valid constructor
2015-08-20T08:03:20.909429+00:00 app[web.2]:    at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909432+00:00 app[web.2]:    at net.spy.memcached.transcoders.TranscodeService$Task.get(TranscodeService.java:97) ~[net.spy.spymemcached-2.9.0.jar:2.9.0]
2015-08-20T08:03:20.909438+00:00 app[web.2]:    at play.cache.DefaultCacheApi.get(DefaultCacheApi.java:25) [com.typesafe.play.play-cache_2.11-2.4.0.jar:2.4.0]
2015-08-20T08:03:20.909434+00:00 app[web.2]:    at net.spy.memcached.internal.GetFuture.get(GetFuture.java:63) ~[net.spy.spymemcached-2.9.0.jar:2.9.0]
2015-08-20T08:03:20.909439+00:00 app[web.2]:    at play.cache.Cache.get(Cache.java:23) [com.typesafe.play.play-cache_2.11-2.4.0.jar:2.4.0]
2015-08-20T08:03:20.909445+00:00 app[web.2]:    at com.feth.play.module.pa.providers.oauth1.OAuth1AuthProvider.authenticate(OAuth1AuthProvider.java:119) [com.feth.play-authenticate_2.11-0.7.0-SNAPSHOT.jar:0.7.0-SNAPSHOT]
2015-08-20T08:03:20.909446+00:00 app[web.2]: Caused by: java.io.InvalidClassException: com.feth.play.module.pa.providers.oauth1.OAuth1AuthProvider$SerializableRequestToken; no valid constructor
2015-08-20T08:03:20.909448+00:00 app[web.2]:    at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909441+00:00 app[web.2]:    at com.feth.play.module.pa.PlayAuthenticate.getFromCache(PlayAuthenticate.java:294) [com.feth.play-authenticate_2.11-0.7.0-SNAPSHOT.jar:0.7.0-SNAPSHOT]
2015-08-20T08:03:20.909454+00:00 app[web.2]:    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909443+00:00 app[web.2]:    at com.feth.play.module.pa.PlayAuthenticate.removeFromCache(PlayAuthenticate.java:280) [com.feth.play-authenticate_2.11-0.7.0-SNAPSHOT.jar:0.7.0-SNAPSHOT]
2015-08-20T08:03:20.909436+00:00 app[web.2]:    at com.github.mumoshu.play2.memcached.MemcachedCacheApi.get(MemcachedCacheApi.scala:42) ~[com.github.mumoshu.play2-memcached-play24_2.11-0.7.0.jar:0.7.0]
2015-08-20T08:03:20.909451+00:00 app[web.2]:    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909455+00:00 app[web.2]:    at com.github.mumoshu.play2.memcached.CustomSerializing.deserialize(CustomSerializing.scala:16) ~[com.github.mumoshu.play2-memcached-play24_2.11-0.7.0.jar:0.7.0]
2015-08-20T08:03:20.909458+00:00 app[web.2]:    at net.spy.memcached.transcoders.SerializingTranscoder.decode(SerializingTranscoder.java:88) ~[net.spy.spymemcached-2.9.0.jar:2.9.0]
2015-08-20T08:03:20.909449+00:00 app[web.2]:    at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:768) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909452+00:00 app[web.2]:    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909461+00:00 app[web.2]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_20-'slim']
2015-08-20T08:03:20.909462+00:00 app[web.2]:    at net.spy.memcached.transcoders.TranscodeService$Task.run(TranscodeService.java:110) ~[net.spy.spymemcached-2.9.0.jar:2.9.0]
2015-08-20T08:03:20.909459+00:00 app[web.2]:    at net.spy.memcached.transcoders.TranscodeService$1.call(TranscodeService.java:63) ~[net.spy.spymemcached-2.9.0.jar:2.9.0]

Do you have any ideas to fix it? Thanks.

tuanvm commented 8 years ago

Hello, are you busy Joscha? Sorry if you are busy. @joscha I created a sample app there https://github.com/tuanvm/play-authenticate-memcached-exception It's just an exist example in play-authenticate repos, just change default ehcache to memcached. Other providers as facebook are still working fine, just exception with twitter only. Thank you!

joscha commented 8 years ago

Hi @tuanvm - I just relocated from Europe to Australia, so I haven't had any time to look into issues lately - the one thing that comes to mind: memcached is not distributed, right? So if your application runs on more than one node, it can happen that data saved is on one node and the second request (when the user comes back from the oauth flow) is handled by a different node that does not have the data in store.

tuanvm commented 8 years ago

Hi @joscha , On our current production server, we use a cloud cache, so it's not empty data problem. Even you can run my sample app in single server at localhost, the issue is still remain there. Follow the exception log above

Caused by: java.io.InvalidClassException: com.feth.play.module.pa.providers.oauth1.OAuth1AuthProvider$SerializableRequestToken; no valid constructor

I don't know why it happened? Any idea why i got this exception. Thanks.

joscha commented 8 years ago

Should be fixed in 0.7.1, 0.6.9, 0.5.4 and 0.3.6.