jaliss / securesocial

A module that provides OAuth, OAuth2 and OpenID authentication for Play Framework applications
http://www.securesocial.ws
Apache License 2.0
1.19k stars 510 forks source link

Null pointer exception when using signup email #563

Closed zmashiah closed 9 years ago

zmashiah commented 9 years ago

The scenario is easy to reproduce:

  1. Signup to a site using mail validation
  2. Click to complete the registration (and so far so good)
  3. Click AGAIN on the link from the email and you get the exception below

Caused by: java.lang.NullPointerException: null at securesocial.core.java.BaseUserService.findToken(BaseUserService.java:149) ~[securesocial_2.11-master-SNAPSHOT.jar:master-SNAPSHOT] at securesocial.controllers.MailTokenBasedOperations.executeForToken(MailTokenBasedOperations.scala:78) ~[securesocial_2.11-master-SNAPSHOT.jar:master-SNAPSHOT] at securesocial.controllers.BaseRegistration$$anonfun$signUp$1.apply(Registration.scala:138) ~[securesocial_2.11-master-SNAPSHOT.jar:master-SNAPSHOT] at securesocial.controllers.BaseRegistration$$anonfun$signUp$1.apply(Registration.scala:136) ~[securesocial_2.11-master-SNAPSHOT.jar:master-SNAPSHOT]

EnverOsmanov commented 9 years ago

Not reproduced with Scala version.

jaliss commented 9 years ago

I was unable to reproduce this with any of the sample apps. I'll close this but please re-open if still facing the issue.

zmashiah commented 8 years ago

Turns out this is happening in our app as well. It was not clear, but apparently implementations of the abstract method doFindToken(token) must never return null. If the token is not found or removed as was used to complete registration before then I made my method return a Promise.pure of Token to which I set expiration to now:

@Override public Promise doFindToken(String tokenKey) { ... if (tokenNotFound) return expiredToken(); ... }

private Promise expiredToken() { Token token = new Token(); token.setExpirationTime(new DateTime(System.currentTimeMillis())); return Promise.pure(token); }

For the record, the scenario we could reproduce this was: Sign up In your inbox mail, press the complete registration Do complete the registration Go back to email message and press the complete registration again.